
To create a JavaServer Page (JSP) 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 webContent, which contains the created JSP file. Double-click the file to open a UI containing two tabs - Preview and Source - on the right. Open the Source tab.
Implement the JSP file:
InitialContextctx = new InitialContext();
To get the default logical port, use:
CreditLimitCheckViDocument port = (CreditLimitCheckViDocument) obj.getLogicalPort(Cr editLimitCheckViDocument.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"));
<%@page import="javax.naming.InitialContext" %> <%@page import="javax.rmi.PortableRemoteObject" %> <%@page import="com.sap.demo.proxy.CreditLimitCheckViDocument" %> <%@page import="com.sap.demo.proxy.CreditLimitCheck" %> <%@page import="com.sap.demo.proxy.types.CreditLimitCheckResponse" %> <%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 JSP 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 JSP 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 a slash (/), it must be replaced with a tilde (~).
<ProxyName> is the fully-qualified proxy name, that is, proxy package name and proxy application name.
Open web.xml, choose Mapping → Servlet Mappings followed by Add. In the displayed dialog box, select your JSP 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 JSP under http://<host>:<port>/<contextRoot>