
To create a servlet that calls the deployable proxy, proceed as follows:
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. Choose OK.
Open your Web project and then open the source section. You will find the servlet that was created under the package you defined in step 3. Double-click the file to open the source screen.
Implement the servlet:
InitialContext ctx = new InitialContext();
To get the logical port, use:
CreditLimitCheckViDocument port = (CreditLimitCheckViDocument) obj.getLogicalPort(CreditLimitCheckViDocument.class);
Alternatively, you can specify which logical port to get by passing the name as a parameter:
CreditLimitCheckViDocument port = (CreditLimitCheckViDocument) obj.getLogicalPort("DEFAULTPort_Document", CreditLimitCheckViDocument.class);
CreditLimitCheckResponse result = new CreditLimitCheckResponse();
result = port.creditLimitCheck(request.getParameter("idNumber"));
package com.sap.demo.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.sap.demo.proxy.CreditLimitCheck;
import com.sap.demo.proxy.CreditLimitCheckViDocument;
import com.sap.demo.proxy.types.CreditLimitCheckResponse;
public class CreditLimitCheckServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
InitialContext ctx = new InitialContext();
CreditLimitCheck obj = (CreditLimitCheck) ctx.lookup("java:comp/env/CreditLimitCheckProxy");
CreditLimitCheckViDocument port = (CreditLimitCheckViDocument) obj.getLogicalPort("DEFAULTPort_Document", CreditLimitCheckViDocument.class);
CreditLimitCheckResponse result = new CreditLimitCheckResponse();
result = port.creditLimitCheck(request.getParameter("idNumber"));
if (result.getScore() == null) {
result.setScore(" ");
}
if (result.getCreditLimit() == null) {
result.setCreditLimit(" ");
}
if (result.getLimitCurrency() == null) {
result.setLimitCurrency(" ");
}
if (result.getValidTo() == null) {
result.setValidTo(" ");
}
}You have to define a reference from your servlet to the J2EE Engine interface or service components. This way, components of your Web application can look up server components and use their functions. Alternatively, you have to create a reference from the servlet to the proxy.
Open the web-j2ee-engine.xml file and choose References. Then, select the JNDI mapping folder and choose Add to add a new server component reference. Enter the required data:
/wsclients/proxies/<ProviderName>/<ApplicationName>/<ProxyName>
<ApplicationName> is the name of the proxy application generated during the 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 the proxy application name.
Open web.xml, choose Mapping → Servlet Mappings followed by Add. In the dialog box that is displayed, select your servlet and choose OK. Enter "/" in the URL Pattern field.
Select the Web project and choose Build Web Archive from the context menu.
Choose File → New → Project → J2EE → EnterpriseApplication Project. Enter the required data and choose Next. In the dialog box that is displayed, select the Web project to create a reference to it and choose Finish.
After step 6, you have defined the reference that is to be bound to your Web 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 created EAR project and choose General → References → Add → Create New.
Enter the corresponding data:
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.
You can test the servlet under http://<host > :<port> /<contextRoot> .