Show TOC Start of Content Area

Procedure documentation Creating a Client Bean  Locate the document in its SAP Library structure

Procedure

To create a session bean that calls a deployable proxy, proceed as follows:

...

       1.      In the EJB Explorer tab in the Web Services perspective, choose File New Project J2EE EJB Module Project.

       2.      In the dialog window that appears, enter the name of the EJB project and choose Finish

       3.      Select the name of the EJB project on the left and choose New  EJB from the context menu. Enter the required information, select generate default interfaces, and choose Next Next.

This graphic is explained in the accompanying text

The generated default classes and interfaces are added to ejbModule and ejb-jar.xml of the EJB project.

       4.      Add business methods for the EJB.

In the dialog box that appeared, select Business Methods and choose Add. Enter data for the method such as name, return types, and parameters. When you are ready, choose Finish.

       5.      Add a Web service client API.

Select the name of the project and choose Add Web Service Client API Library from the context menu. This enables you to use the client API of the deployable proxy.

This graphic is explained in the accompanying text

       6.      Implement the session bean

The implementation must contain methods for: a proxy lookup from the JNDI context, getting the default Logical Port, and invoking the Web service method(s). The result is returned as a result of the method or as an exception.

You have to implement the proxy lookup from the naming system and get the logical port in the ejbCreate() method of the bean. You also have to invoke the Web service methods in the business method of the EJB.

Note

When you enter the JNDI name, bear in mind that the java:comp/env/ prefix is always appended to the JNDI name.

Syntax

  /**

   * Create Method.

   */

 public void ejbCreate() throws CreateException {

    try {

      InitialContext ctx = new InitialContext();

      CreditLimitCheck obj = (CreditLimitCheck) ctx.lookup("java:comp/env/CreditLimitCheckProxy");

      CreditLimitCheckViDocument port = (CreditLimitCheckViDocument) obj.getLogicalPort("DEFAULTPort_Document", CreditLimitCheckViDocument.class);

      this.port = port;

    } catch (Exception e) {

      throw new CreateException(e.toString());

    }

  /**

   * Business Method.

   */

  public CreditLimitStruct creditLimitCheck(String idNumber) throws Exception {

    CreditLimitCheckResponse response = port.creditLimitCheck(idNumber);

    CreditLimitStruct result = new CreditLimitStruct();

    result.creditLimit = response.getCreditLimit();

    result.limitCurrency = response.getLimitCurrency();

    result.score = response.getScore();

    result.status = response.getStatus();

    result.validTo = response.getValidTo();

    return result;

  }

       7.      Add JNDI mappings

You have to define a reference from your session bean to the J2EE Engine interface or service components. This way, components of your application can look up server components and use their functions. Alternatively, you have to create a reference from the EJB to the proxy.

In the J2EE Development perspective, open ejb-j2ee-engine.xml Enterprise Beans session beans jndi mapping. To add a new JNDI mapping, choose Add and enter the required data.

                            a.      Application local JNDI name – This is the name that you use in the JSP code to look up the server component. It is relative to the java:comp/env context.

                            b.      Server component type – Choose the type of the reference. The types can be service or interface depending on the component type that is referenced.

                            c.      Server Component JNDI name – Enter the name with which this component is bound to the J2EE Engine Naming System. The following convention is used:

/wsclients/proxies/<ProviderName>/<ApplicationName>/<ProxyName>

<ApplicationName> is the name of the proxy application generated during build of the Enterprise Archive file of the Deployable Proxy Project. The application automatically gets the same name as specified for the proxy project. If the application name contains  slash (/), it must be replaced with a tilde (~).

<ProxyName> is the fully-qualified proxy name, that is, the proxy package name and proxy application name.

       8.      To invoke the session bean later, you have to create a Web service, servlet, or JSP. The EJB contains the business logic and the WS, servlet, or JSP contains the presentation logic.

To expose the bean as a Web service, see Creating a Web Service for an Enterprise JavaBean.

       9.      Build the EJB.

Select the EJB project and choose Build Project from the context menu.

   10.      Create an Enterprise Application Project from which the EJB can be generated in the form of an EAR file and deployed.

Choose File New Project J2EE Enterprise Application Project. Enter the required data and choose Next. In the dialog box that is displayed, select the EJB project to create a reference to it and choose Finish.

   11.      Add an application reference

After step 7, you have defined the reference that is to be bound to your application’s naming environment. However, to be able to load classes of the referenced proxy interface, you must also set a reference at classloader level. That is, you must set a reference to the corresponding server component in the application-j2ee-engine.xml descriptor in your Enterprise Application Project. To do this, open the application-j2ee-engine.xml editor of the EAR project you created and choose General References Add Create New.

                            a.      Reference target – this is the component to which you want to create a reference.

                            b.      Reference type – hard means that your application will not be started if the component is not started. Weak means that it will be started whether the proxy application is deployed or not, but it will not be useable until the proxy is started.

                            c.      Reference target type – this is the type of the component to which you are creating a reference.

                            d.      Provider name – enter sap.com

This graphic is explained in the accompanying text

   12.      Build and deploy the EAR

Select the EAR project and choose Build Application Archive from the context menu. Then select the generated EAR file and choose Deploy on J2EE Engine from the context menu.

 

Because the EJB is exposed as a Web service, you can test it under http://<host:port>/<WebService_Name>/<Configuration_Name>.

The Configuration_Name is specified during creation of the Web service.

 

End of Content Area