Blogs

Oliver Stiefbold

Java EE 5 and SOA@SAP, Part 3 - ES Workplace and Java EE 5 Web Client
Oliver Stiefbold SAP Employee 
Business Card
Posted on Apr. 18, 2007 08:21 AM in Service-Oriented Architecture, Java Programming, SAP NetWeaver Platform, SAP xApps, Community Day

Subscribe.Subscribe
Print. Print
Permalink Permalink
Share

The tutorial is developed with SAP NetWeaver 7.1. To retrace this blog you need to install the SAP NetWeaver Application Server, Java EE 5 Edition and you need access to the ES Workplace.

 

Part 1:

For pictured but different descritption see the following article.

1. Navigate to SDN ES Workplace homepage http://erp.esworkplace.sap.com/socoview.

2. Click the link Enterprise Service Index.

3. In the browser window insert the name of the Enterprise Service: Find Customer by Address into the field Search and click Search in Enterprise Service Index.

4. In the browser window you get the result of the search. Click the link Find Customer by Address.
5. Now you can get detailed information about the Enterprise Service.
6. To open the WSDL file click the link on Related Web Service Definition.
7. Logon with your user.

8 Copy the link http://erp.esworkplace.sap.com/sap/bc/srt/xip/sap/ECC_CUSTOMER002QR?sap-client=800&wsdl=1.1 to your clipboard. Otionally you may save the WSDL locally in your file system. Eclipse based NetWeaver Developer Studio NWDS can handle both ways.

Part 2: Test the WSDL

1. Open theES Workplace http://erp.esworkplace.sap.com/ in your Browser and click on Web Service Navigator.

2. Enter the WSDL, click next and logon with your credentials.

3. Click on "Test" in the navigation pane.

4. You see the Request Test Page for the wsdl:portType name="CustomerSimpleByNameAndAddressQueryResponse_In"

5. Enter e.g. "Julia" into xsd:element name="FirstLineName" and click "Send" button.

6. You will receive a Response list of customers. Look carefully at the nested structure of the Web Service reuest and response. We will need it for programming in the next part.

image

 

Part 3: Creating a java proxy in WEB 2.5 Project

Use

This procedure enables you to generate a standalone Web Service proxy for consuming a Web Service using the Web Service Client wizard.

Creating a Web 2.5 project

Procedure

1. Choose File --> New --> Project.

2. In the pop-up window choose Web --> Web 2.5 Project and click Next.
3. Enter the project name: ECCCustomerWEB and choose add to ECCCustomerEAR.
4. Choose Finish.

As a Result a new Web Project (for Java EE 5) is created.

5. Create a new Web Service Client. Choose File --> New --> Other --> Web Service Client.

6. In the popup wizard enter the WSDL-URL and choose "Deploy Client" in the slider on the left (however you may choose whatever you like, it has no influence in this project type.

7. Choose "SAP NetWeaver" as Web Service Runtime instead of "Apache Axis". Otherwise you will not be able to "SAP Global datatypes", You will need them for the rather complex business data types.

8. Choose finish, a Java Proxy is generated.

9. This Java Proxy has a known bug. Programm the service implementation manually:

package com.sap.xi.appl.se.global;

/**
* Service implementation of {CustomerSimpleByNameAndAddressQueryResponse_InService} (generated by SAP WSDL to Java generator).
*/
@javax.xml.ws.WebServiceClient(name = "CustomerSimpleByNameAndAddressQueryResponse_InService", targetNamespace = "http://sap.com/xi/APPL/SE/Global", wsdlLocation = "file:/C:/SAP/IDE/ct0315/workspace/Customer/wsdl/CustomerSimpleByNameAndAddressQuery/wsdlroot.wsdl")
public class CustomerSimpleByNameAndAddressQueryResponseInService extends javax.xml.ws.Service {

private final static java.net.URL CUSTOMERSIMPLEBYNAMEANDADDRESSQUERYRESPONSEINSERVICE_WSDL_LOCATION;
static {
java.net.URL url = null;
try {
java.net.URL tmpUrl = Thread.currentThread().getContextClassLoader().getResource("wsdl/sap/bc/srt/xip/sap/ECC_CUSTOMER002QR/wsdlroot.wsdl");
url = new java.net.URL(tmpUrl.getProtocol(), tmpUrl.getHost(), tmpUrl.getPort(), tmpUrl.getFile());
} catch (java.net.MalformedURLException e) {
e.printStackTrace();
}
CUSTOMERSIMPLEBYNAMEANDADDRESSQUERYRESPONSEINSERVICE_WSDL_LOCATION = url;
}
/**
* Default service constructor.
*/

 

Part 4: Creating a Web Service Client Web Application

Creating a new JSP

Use

To invoke the standalone proxy you need a new JSP page.

Procedure

1. Choose File --> New --> JSP .

2. In the popup-window enter the class name: index.
3. Click Finish.

Creating source code

Use

To invoke the standalone proxy you have to create instances, insert authentication and set the values for the request. The complete source code of the class is also available at the end of this chapter.

Coding (Tested with SAP NW 7.1)

<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.io.PrintWriter"%>
<%@page import="java.util.*"%>
<%@page import="javax.xml.ws.*"%>

<%@page import="com.sap.xi.appl.se.global.CustomerSimpleByNameAndAddressQueryMessage_SyncType.CustomerSimpleSelectionByNameAndAddressAnonymous"%>
<%@page import="com.sap.xi.appl.se.global.CustomerSimpleByNameAndAddressResponseMessage_SyncType.CustomerAnonymous"%>
<%@page import="com.sap.xi.appl.se.global.CustomerSimpleByNameAndAddressQueryResponseInService"%>
<%@page import="com.sap.xi.appl.se.global.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test ECCCustomer002QR Web Service</title>
</head>
<body>
<h1>Webservice returns :</h1>
<%

try {

// create service: CustomerSimpleByNameAndAddressQueryResponse_In
CustomerSimpleByNameAndAddressQueryResponseInService service = new CustomerSimpleByNameAndAddressQueryResponseInService();
// create SOAP binding
CustomerSimpleByNameAndAddressQueryResponseIn binding = service
.getCustomerSimpleByNameAndAddressQueryResponse_InSoapBinding();
// JAX-WS - set username and password in Binding Provider
((BindingProvider) binding).getRequestContext().put(
BindingProvider.USERNAME_PROPERTY, "user");
((BindingProvider) binding).getRequestContext().put(
BindingProvider.PASSWORD_PROPERTY, "password");
// create parameters (test.types.CustomerSimpleByNameAndAddressQueryMessageSync)
CustomerSimpleByNameAndAddressQueryMessage_SyncType parameters = new CustomerSimpleByNameAndAddressQueryMessage_SyncType();
//CustomerSimpleSelectionByNameAndAddress (test.types.CustomerSimpleSelectionByNameAndAddress)
CustomerSimpleSelectionByNameAndAddressAnonymous selection = new CustomerSimpleSelectionByNameAndAddressAnonymous();
// set selection in paramters
parameters.setCustomerSimpleSelectionByNameAndAddress(selection);
// CustomerName (test.types.OrganisationName)
OrganisationNameType customerName = new OrganisationNameType();
customerName.setFirstLineName("Julia");
// set customername in selection
selection.setCustomerName(customerName);

// call the service
System.out.println("Calling web service.....");
// response (test.types.CustomerSimpleByNameAndAddressResponseMessageSync)
CustomerSimpleByNameAndAddressResponseMessage_SyncType wsresponse = binding
.customerSimpleByNameAndAddressQueryResponseIn(parameters);

out.write("Webservice call succeeded.");

// create some output
List<CustomerAnonymous> customers = wsresponse.getCustomer();
for (CustomerAnonymous customer : customers) {
%>
<%=customer.getBasicData().getCommon()
.getName().getFirstLineName()%>
<%
}

} catch (Exception e) {
e.printStackTrace(new PrintWriter(out));
}

%>
</body>
</html>

 

 

JSP Page Result

Webservice returns :

Webservice call succeeded.

Julia Chase Julia Ewing ...

Oliver Stiefbold   has been with SAP since 1998 and has worked in Development in ERP Automotive and consulting in e-Commerce. Since 2001, he's been the product manager for the Portal Development Kit.


Comment on this article
Comment on this weblog