Entering content frame

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

Procedure

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

...

       1.      Create a Web Module project. Choose File ® New ® Project ® J2EE.

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

Note

For convenience, in this example the doPost() method is deselected.

This graphic is explained in the accompanying text

       3.      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

       4.      Implement the servlet

It must look up the deployable proxy from the JNDI context and, as a result, display the result of the call or the message from the exception.

This graphic is explained in the accompanying text

package samplews.client.servlet;

import java.io.IOException;

 

import javax.naming.*;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

 

import samplews.proxy.*;

 

public class SampleWSClientServlet extends HttpServlet {

   protected void doGet(

      HttpServletRequest request,

      HttpServletResponse response)

      throws ServletException, IOException {

         try{

            InitialContext ic = new InitialContext();

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

         SampleWSViDocument vi = sampleWS.getLogicalPort();

         response.getWriter().write(vi.myBusinessMethod());

         }catch (Exception e){

            response.getWriter().write(e.toString());

         }

   }

 

}

       5.      Add JNDI mappings

Open the web-j2ee-engine.xml file and choose References. Then select the jndi mapping folder and choose Add. Enter the required data:

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

                            b.      Server Component Name – service or application

                            c.      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

       6.      Add the servlet to the URL Pattern

Open web.xml, choose Mapping ® Servlet Mappings and choose Add. Select your servlet and choose OK. In the tab on the right-hand side, enter “/” in the URL Pattern field.

This graphic is explained in the accompanying text

 

       7.      Create a reference to the deployable proxy application.

So that your client application can access the proxy classes, you need to provide an application reference. In this example, SampleWSClient_EAR application needs to reference the sap.com/SampleWSProxy_PRX proxy application.

To do this, open the application-j2ee-engine.xml editor of the EAR project. Choose General ® References ® Add ® Create New.

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

       8.      Add the WEB project to the application. Select the EAR project and choose Add Modules in the context menu.

This graphic is explained in the accompanying text

       9.      Edit the Context Root value of the WAR project to get the correct location to invoke the servlet. Choose application.xml ® Modules ® Context Root and enter a new value.

This graphic is explained in the accompanying text

   10.      Build and deploy the application.

You can test it under http://<host>:<port>/SampleWSClient/servlet.

 

See also:

Creating a Client Bean

Creating a Client JavaServer Page

Leaving content frame