You can create a web service from ADF Business Components by publishing the application module as a service session bean. This is a good technique to use if the web service needs to interact with other EJB session beans as part of its implementation. Another way of creating a web service from ADF Business Components is generating a web service class for the application module, and creating the web service from it.
You can configure ADF Business Components application modules to deploy as EJB session beans. For more information, see Packaging ADF Business Components as an EJB Session Bean. By default, these are stateful session beans, and to create web services from them they have to be changed into stateless session beans.
The steps below illustrate turning a stateful ADF Business Components based session bean into a stateless session bean.
To change the bean to a stateless session bean:
<AppModuleName>
Server.java
.
createApplicationModule()
call
from the ejbCreate()
, leaving an method that
looks like:
public void ejbCreate() throws java.rmi.RemoteException, javax.ejb.CreateException
{
// To make stateless, comment this line out
// createApplicationModule("mypkg.MypkgModule");
}
createApplicationModule("mypkg.MyModule")
line
from above, and put it first, just inside the try
.
catch
block to handle the
javax.ejb.CreateException
, making sure that you use the
fully qualified form.
finally
block that contains a call to
removeApplicationModule()
someExposedMethod()
above
would end up looking like this:
// NOTE: Need to add imports for javax.ejb.CreateException and java.rmi.RemoteException
public String someExposedMethod(int x) throws java.rmi.RemoteException
{
try
{
// (Step 1) Add this line -- Create the application module
createApplicationModule("mypkg.MypkgModule");
// (Step 2) Add this line -- Connect the appmodule to a datasource using the
// ejb-location name of the datasource from the data-sources.xml file
getApplicationModule().getTransaction().connectToDataSource(null,"jdbc/OracleDS",false);
return getMypkgModule().someExposedMethod(x);
}
// (Step 3) Add this catch block
catch(javax.ejb.CreateException ex)
{
throw new RemoteException("Create error", ex);
}
catch(oracle.jbo.JboException ex)
{
// Convert JboException to service exception below
// Business methods shouldn't throw RuntimeException
ex.printStackTrace();
throw ex;
}
// (Step 4) Add this finally block to remove the appmodule
finally {
// Add this line -- Remove the application module
removeApplicationModule();
}
}
Stateless
.
Copyright © 1997, 2004, Oracle. All rights reserved.