Entering content frame

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

Procedure

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

...

       1.      Create EJB Module and Enterprise Application projects. Choose File ® New ® Project ® J2EE.

       2.      Select the name of the EJB project and choose New  ® EJB. Enter the required information and choose Finish.

       3.      Select the bean and enter the methods it uses on the Methods tab page.

This graphic is explained in the accompanying text

       4.      Add the Web service client API.

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

This graphic is explained in the accompanying text

 

This graphic is explained in the accompanying text

       5.      Add the implementation of the bean method(s)

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.

Note

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

 

This graphic is explained in the accompanying text

public String testSampleWS() {

       try{

         InitialContext ic = new InitialContext();

         SampleWS sampleWS = (SampleWS)ic.lookup("java:comp/env/SampleWSProxy");

         SampleWSViDocument vi = sampleWS.getLogicalPort();

         return vi.myBusinessMethod();

       } catch (Exception e){

         return e.toString();

       }

       6.      Add JNDI mappings

                            a.      In the J2EE Development perspective, open ejb-j2ee-engine.xml ® Enterprise Beans ® session beans ® jndi mapping

                            b.      To add a new JNDI mapping, choose Add and enter the required data.

                                                  i.       Application local JNDI name – this is the name under which the proxy is looked up in the application (in our example this is “SampleWSProxy”).

                                                ii.       Server Component type – service or interface

                                               iii.       Server Component JNDI name – the name of the JNDI context by which the proxy is bound. The following convention is used:

/wsclients/proxies/<provider name>/<ApplicationName>/<ProxyName>

If the application name contains “/”, it must be replaced by “~”.

In our example the JNDI context is:

/wsclients/proxies/sap.com/SampleWSProxy_PRX/samplews.proxy.SampleWSProxy

This graphic is explained in the accompanying text

       7.      You can expose the bean as a Web service if you want to test it.

In the EJB module project, select the name of the bean and choose New ® Web Service in the context menu.

This graphic is explained in the accompanying text

       8.      Add an application reference

So that your client application can access the proxy classes that are included by the Web Service API during runtime, you need to provide an application reference. In the Enterprise Application project, choose application-j2ee-engine.xml ® Add ® Create Newand enter the corresponding data.

                            a.      Reference Target – this is the proxy project name. In this example it is: SampleWSProxy_PRX.

                            b.      Reference Type – hard means that your application will not be started if the proxy application 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 application is started.

                            c.      Reference Target Type – select application

                            d.      Provider Name – enter sap.com

This graphic is explained in the accompanying text

       9.      Build and deploy the EAR

You can test the application under http://<host:port>/SampleWSClient/bean – open the test page and send a request.

 

See also:

Creating a Client Servlet

Creating a Client JavaServer Page

Leaving content frame