You are on page 1of 19

Alex Maier

How-To-Guide for generating a Web Service Client with the SAP NetWeaver Application Server
Java EE 5 Edition

How to Generate a Web Service Client with


SAP NetWeaver Application Server Java EE 5
Edition
Applies to:
SAP NetWeaver Application Server Java EE 5 Edition
https://www.sdn.sap.com/irj/sdn/downloads?rid=/library/uuid/da699d27-0b010010-99b0-f11458f31ef2
Access to the ES Workplace mySAP ERP ECC 600
https://www.sdn.sap.com/irj/sdn/developerareas/esa/esworkplace

Summary
This document enables you to generate Web Service Clients for consuming Web
Services from the ES Workplace using the SAP NetWeaver Developer Studio.
For ease of use, this guide is divided into four parts: part one describes creating
the required project, part two deals with choosing and importing a WSDL file, part
three involves generating the Web Service Client, and part four tests the Web
Service Client with a JavaServer Page. The time requirement for this how-to
guide is about 25 minutes.
Author: Boris Mueller Company: SAP AGCreated on: 16 January 2007

Author Bio
Boris Mueller is computer science student and works at present as a trainee at
SAP in the Market Development Engineering Team in Walldorf.
Boris has several years experience as maintenance supervisor of electrical
engineering and telecommunications in a management position.

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY |


bpx.sap.com 2007 SAP AG 1

Table of Contents
Applies
to: .............................................................................................................................
........... 1
Summary...................................................................................................................
....................... 1 Author
Bio ............................................................................................................................
............ 1 Table of
Contents ..................................................................................................................
.......... 2 Part 1: Creating a
Project ................................................................................................................ 3
Create a Dynamic Web Project
2.5.............................................................................................. 3
Use ..........................................................................................................................
................. 3
Procedure ................................................................................................................
................. 3
Create an Enterprise Application 5
Project .................................................................................. 3
Use ..........................................................................................................................
................. 3
Procedure ................................................................................................................
................. 3
Part 2: Choosing and Importing a WSDL
File.................................................................................. 3 Choose a WSDL
file..................................................................................................................... 3
Use ..........................................................................................................................
................. 3
Procedure ................................................................................................................
................. 4 Import a WSDL
File .........................................................................................................................
4
Use ..........................................................................................................................

................. 4
Procedure ................................................................................................................
................. 5 Part 3: Generating a Web Service
Client......................................................................................... 5
Use ..........................................................................................................................
................. 5
Procedure ................................................................................................................
................. 5 Part 4: Testing the Web Service
Client............................................................................................ 7 Creating a
JavaServer Page
(JSP).............................................................................................. 7
Use ..........................................................................................................................
................. 7
Procedure ................................................................................................................
................. 7 Creating source
code ................................................................................................................... 7
Use ..........................................................................................................................
................. 7
Procedure ................................................................................................................
................. 7 Deploy the JavaServer
Page ..................................................................................................... 10
Use ..........................................................................................................................
............... 10
Procedure ................................................................................................................
............... 10 Complete source code for the
JSP ............................................................................................ 11 Related
Content.....................................................................................................................
........ 13
Copyright..................................................................................................................
...................... 14
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY |
bpx.sap.com 2007 SAP AG 2
How-To-Guide for generating a Web Service Client with the SAP NetWeaver Application Server
Java EE 5 Edition

Before you create web components, you need to create a Dynamic Web Project
2.5. The purpose of this project type is to organize and collect the web
components of a Java EE 5 application. All class files, resources and deployment
descriptors that are to be packed in the same web archive (WAR) should be
created in the same Dynamic Web Project 2.5. To create the project, complete
the following steps:

Procedure
1. Choose File New Project.2. In the pop-up window, choose Web
DynamicWeb Project 2.5.3. Enter the project name: WsClient.4. Choose Finish to
create a new Dynamic Web Project.
Create an Enterprise Application 5 Project
Use
To create enterprise applications in SAP NetWeaver Developer Studio, you use
Enterprise Application Projects 5. The goal of this project type is to assemble all
Web, EJB, connector and other components (modules) of the application. The
application components represented by their corresponding projects - for
example, the EJB components of an application are represented by the
corresponding EJB 3.0 Project. An Enterprise Application Project 5 also allows
you to add bundled libraries to the application. To create the project, complete the
following steps:
Procedure
1. Choose File New Project.2. In the pop-up window, choose J2EE
Enterprise Application 5 Project. 3. Choose Next.4. Enter the project name:
EarProject5. Choose Finish to create a new Enterprise Application 5 Project..

Part 2: Choosing and Importing a WSDL File


Choose a WSDL file
Use
The Web Service Client Wizard needs a WSDL file to access the Web service. In
the following example, we will use the Find Customer by Address Web service,
which you can find on the ES Workplace. The name of this Web service in the
mySAP ERP ECC 600 backend system is ECC_CUSTOMER002QR. To find and
save this WSDL file, complete the following steps:
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY |
bpx.sap.com 2007 SAP AG 3
How-To-Guide for generating a Web Service Client with the SAP NetWeaver Application Server
Java EE 5 Edition

Part 1: Creating a Project


Create a Dynamic Web Project 2.5

Use

Procedure
1. Open the ES Workplace: http://erp.esworkplace.sap.com/socoview 2. Click the
link Enterprise Service Index.
3. In the Search field of the resulting page, insert the name of the Enterprise
Service: Find Customer by Address. Click Search.
4. In the browser window, the results of your search will appear. Click the link
Find Customer by Address, which will give you more information about the
Enterprise Service.
5. To open the WSDL file, click on the Related Web Service Definition link.
6. You will have to log on before accessing the WSDL file. Once you have logged
in and have access to the WSDL file as XML, choose File Save As...in the
browser window. Make sure that you change the file extension from XML to
WSDL before saving the file locally.

Import a WSDL File


Use
The Web Service Client Wizard will assist you in creating a new Web Service
Client from a WSDL file. First, you have to import a WSDL file into your Dynamic
Web Project. To do so, complete the following steps:
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY |
bpx.sap.com 2007 SAP AG 4
How-To-Guide for generating a Web Service Client with the SAP NetWeaver Application Server
Java EE 5 Edition

Procedure
1. Choose File Import.
2. In the pop-up window, choose General File System and click Next.
3. Click Browse on the next page of the wizard to select the path which contains
the WSDL file.
4. In the window on the right, select the checkbox for the WSDL file.
5. Specify the WsClient project as the import destination.
6. When you have finished specifying your import options, click Finish.

Part 3: Generating a Web Service Client


Use
With the generated projects and the WSDL file, you can generate a Web Service

Client. To generate a Web Service Client, complete the following steps:


Procedure
1. Select the WSDL file from the WsClient project.
2. Right-click on the file name. In the pop-up menu, choose Web Services
Generate Client. A wizard for creating a Web Service Client will start.
3. Choose the Client EAR project from Configuration.
4. In the pop-up window, change the name of the Client EAR project from
WsClientEAR to EarProject and click OK.
5. Move the slider to the Start client position.
6. Check the settings under Configuration. The settings should be:
- Server: SAP Server
- Web service runtime: SAP Netweaver
- Client project: WsClient
- Client EAR project: EarProject 7. Once you are sure the settings are
correct, choose Next.8. Choose the folder source in the WsClient project as the
output folder and choose Finish. 9. Enter the user and password information for
the engine and click OK. SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS
PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 5
How-To-Guide for generating a Web Service Client with the SAP NetWeaver Application Server
Java EE 5 Edition

How-To-Guide for generating a Web Service Client with the SAP NetWeaver Application Server
Java EE 5 Edition

10. If the deployment was successful, the following dialog will appear. Choose OK
again.
11. The Deploy View Console will appear. In this Console, you can see the entire
deployment process. The wizard has created two classes and two files: Java
classes in the source folder, class files in the build folder, a WAR file, and an EAR
file. The EAR file is deployed.

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY |


bpx.sap.com 2007 SAP AG 6

In the current preview version of SAP NetWeaver Application Server Java EE 5


Edition, the testing feature has not yet been implemented. Therefore, we must do
the testing using a JavaServer Page (JSP).
The JSP technology enables you to generate dynamic web content, such as
HTML, DHTML, XHTML, and XML files, to include in a Web application. We will
use a JSP to test the Web Service Client.
Most types of JSP files can be created using the JSP File wizard. To create a
basic JSP file using the wizard, complete the following steps:
Procedure
1. Select the WebContent folder in the WsClient project.
2. From the WsClient context menu, choose New Other.
3. In the pop-up window, choose Web JSP and click Next.
4. On the next page of the wizard, enter the file name of the JSP: index.
5. Click Finish to create a Java Server Page File.
Creating source code
Use
To invoke the Web service, you have to specify the proxy settings,
authentifications, and values of the request and response. The process is
described below, and the complete source code of the JSP is available at the end
of this chapter.
Procedure
1. Insert the imports.
2. Insert the title of the page3. Handle errors and exceptions with a try/catch
statement into the body-tag
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY |
bpx.sap.com 2007 SAP AG 7
How-To-Guide for generating a Web Service Client with the SAP NetWeaver Application Server
Java EE 5 Edition

Part 4: Testing the Web Service Client

Creating a JavaServer Page (JSP)


Use

<%@page import = "java.io.PrintWriter"%>


<%@page import = "com.sap.xi.appl.se.global.*"%>
<%@page import = "java.util.*"%>

<title>Test WS Client</title>
<h1>Webservice returns :</h1>
<%

How-To-Guide for generating a Web Service Client with the SAP NetWeaver Application Server
Java EE 5 Edition

try{} catch(Exception e) {
%><pre><%e.printStackTrace(newPrintWriter(out)); %>
</pre> <%}%>

3. Insert the proxy settings when they are necessary


4. Create instances
System.setProperty("proxyHost", "<my_proxy.mycorp.com>");

System.setProperty("http.proxyHost",
"<my_http_proxy.mycorp.com>"); System.setProperty("proxyPort",
"my_proxy_port"); System.setProperty("http.proxyPort",
"my_http_proxy_port");

// connection to the web service


CustomerSimpleByNameAndAddressQueryResponseInService service
= new
CustomerSimpleByNameAndAddressQueryResponseInService();
// get method for web service port
CustomerSimpleByNameAndAddressQueryResponseIn query =
service.getCustomerSimpleByNameAndAddressQueryResponse_InSoa
pBinding();
// create request
CustomerSimpleByNameAndAddressQueryMessageSync message = new
CustomerSimpleByNameAndAddressQueryMessageSync();
// in memory representation of querydata
CustomerSimpleByNameAndAddressQueryMessageSync.
CustomerSimpleSelectionByNameAndAddress querydata = new
CustomerSimpleByNameAndAddressQueryMessageSync.
CustomerSimpleSelectionByNameAndAddress();
OrganisationName oname = new OrganisationName();
4. Insert authentication and specify your username and password from the ES
Workplace.
5. Set values for the request.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY |
bpx.sap.com 2007 SAP AG 8

javax.xml.ws.BindingProvider bp =
(javax.xml.ws.BindingProvider) query; Map<String, Object>
context = bp.getRequestContext();
context.put("javax.xml.ws.security.auth.username",
"myUser");
context.put("javax.xml.ws.security.auth.password",
"myPassword");
oname.setFirstLineName("Julia");
oname.setSecondLineName("");
oname.setThirdLineName("");

6. Display the response.


How-To-Guide for generating a Web Service Client with the SAP NetWeaver Application Server
Java EE 5 Edition

oname.setFourthLineName("");
querydata.setCustomerName(oname);
querydata.setCustomerAddressCountryCode("DE");
querydata.setCustomerAddressCityName("");
querydata.setCustomerAddressDistrictName("");
querydata.setCustomerAddressStreetPostalCode("");
querydata.setCustomerAddressStreetName("");
querydata.setCustomerKeyWordsText("");
querydata.setCustomerAdditionalKeyWordsText("");
message.setCustomerSimpleSelectionByNameAndAddress(querydata
);

CustomerSimpleByNameAndAddressResponseMessageSync responce =
query.customerSimpleByNameAndAddressQueryResponseIn(message)
;
List<CustomerSimpleByNameAndAddressResponseMessageSync.Custo
mer> li = responce.getCustomer();
for
(CustomerSimpleByNameAndAddressResponseMessageSync.Customer
c : li) { %>

<td><

<p>Customer:</p>
<table>
<tr>
<td>Key</td>
<td>Value</td>
</tr>
<tr>
<td>CustomerID</td>
<td><%=c.getID().getValue()%></td>
</tr>
<tr>
<td>FirstLineName</td>

%=c.getBasicData().getCommon().getName().getFirstLineName()
%></td> </tr>
<tr>
<td>BlockedIndicator</td>
<td><%=c.getBasicData().getCommon().isBlockedIndicator()
%></td> </tr>
<tr>
<td>NaturalPersonIndicator</td>
<td><
%=c.getBasicData().getCommon().isNaturalPersonIndicator()
%></td>
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY |
bpx.sap.com 2007 SAP AG 9

Deploy the JavaServer Page


Use
Before use, the JSP needs to be deployed as follows.
Procedure
1. Select the EarProject and click the right mouse button.
2. From the context menu, choose Run As Run on Server.
3. In the pop-up window, choose your server and click Finish.
4. Enter the user and password for the engine and choose OK.
5. If the deployment was successful, a dialog will appear. Choose OK to deploy
the JSP on the engine.
6. Choose OK to deploy the JSP on the engine. The result of the response will be
displayed in your web browser.
To start the JSP, enter the following address in your web browser:
http://<computer>:<port>/<context_path>
In this example, the address is: http://localhost:50000/WsClient
How-To-Guide for generating a Web Service Client with the SAP NetWeaver Application Server
Java EE 5 Edition

</tr>
</table>
<% }

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG


BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 10

Complete source code for the JSP


Here is the complete source code for the JSP. You can copy it and paste it into
the JSP file. Before deploying it, you will have to change the settings for
username yourUser and password yourPassword in the source code.
<%@ page language="java" contentType="text/html;
charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN">
<%@page import="java.io.PrintWriter"%>
<%@page import="com.sap.xi.appl.se.global.*"%>

<%@page import="java.util.*"%>
<html><head><meta http-equiv="Content-Type"
content="text/html; charset=UTF-8"> <title>Test WS
Client</title></head><body><h1>Webservice returns :</h1><%try
{// System.setProperty("proxyHost",
"<my_proxy.mycorp.com>");//
System.setProperty("http.proxyHost",
"<my_http_proxy.mycorp.com>"); // if
// System.setProperty("proxyPort", "my_proxy_port");
settings
// System.setProperty("http.proxyPort",
"my_http_proxy_port");
necessary
CustomerSimpleByNameAndAddressQueryResponseInService service
= newCustomerSimpleByNameAndAddressQueryResponseInService();
CustomerSimpleByNameAndAddressQueryResponseIn query =
service.getCustomerSimpleByNameAndAddressQueryResponse_InSoa
pBinding();
CustomerSimpleByNameAndAddressQueryMessageSync message = new
CustomerSimpleByNameAndAddressQueryMessageSync();
// only
//// are
CustomerSimpleByNameAndAddressQueryMessageSync.CustomerSimpl
eSelectionByNameAndA ddress querydata = new
CustomerSimpleByNameAndAddressQueryMessageSync.CustomerSimpl
eSelectionByNameAndA ddress();
OrganisationName oname = newOrganisationName();
javax.xml.ws.BindingProvider bp =
(javax.xml.ws.BindingProvider) query; Map<String, Object>
context = bp.getRequestContext();
context.put("javax.xml.ws.security.auth.username",
"yourUser");
context.put("javax.xml.ws.security.auth.password",
"yourPassword"); oname.setFirstLineName("Julia");
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY |
bpx.sap.com 2007 SAP AG 11
How-To-Guide for generating a Web Service Client with the SAP NetWeaver Application Server

Java EE 5 Edition

querydata.setCustomerAddressCountryCode("DE");
querydata.setCustomerAddressCityName("");
querydata.setCustomerAddressDistrictName("");
querydata.setCustomerAddressStreetPostalCode("");
querydata.setCustomerAddressStreetName("");
querydata.setCustomerKeyWordsText("");
querydata.setCustomerAdditionalKeyWordsText("");
message.setCustomerSimpleSelectionByNameAndAddress(querydata
);
CustomerSimpleByNameAndAddressResponseMessageSync responce =
query.customerSimpleByNameAndAddressQueryResponseIn(message)
;
List<CustomerSimpleByNameAndAddressResponseMessageSync.Custo
mer> li = responce.getCustomer();
for
(CustomerSimpleByNameAndAddressResponseMessageSync.Customer
c : li) { %>
<p>Customer:</p><table><tr> <td>Key</td> <td>Value</td>
</tr><tr> <td>CustomerID</td> <td><%=c.getID().getValue()
%></td> </tr>
<tr> <td>FirstLineName</td> <td><
%=c.getBasicData().getCommon().getName().getFirstLineName()
%></ td>
</tr><tr> <td>BlockedIndicator</td> <td><
%=c.getBasicData().getCommon().isBlockedIndicator()%></td>
</tr><tr> <td>NaturalPersonIndicator</td>
<td><
%=c.getBasicData().getCommon().isNaturalPersonIndicator()
%></td> </tr>
</table>
<% }
} catch(Exception e) { %>

<pre><%e.printStackTrace(newPrintWriter(out)); %>
SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG
BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 12
How-To-Guide for generating a Web Service Client with the SAP NetWeaver Application Server
Java EE 5 Edition

oname.setSecondLineName("");
oname.setThirdLineName("");
oname.setFourthLineName("");
querydata.setCustomerName(oname);

</pre>
<%
}
%>
</body>
</html>

Related Content

Platform Ecosystem

ES Workplace homepage on SDN

Enterprise SOA homepage on SDN


How-To-Guide for generating a Web Service Client with the SAP NetWeaver Application Server
Java EE 5 Edition

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG


BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 13

No part of this publication may be reproduced or transmitted in any form or for any purpose
without the express permission of SAP AG. The information contained herein may be changed
without prior notice.
Some software products marketed by SAP AG and its distributors contain proprietary software
components of other software vendors. Microsoft, Windows, Outlook, and PowerPoint are
registered trademarks of Microsoft Corporation.
IBM, DB2, DB2 Universal Database, OS/2, Parallel Sysplex, MVS/ESA, AIX, S/390, AS/400,

OS/390, OS/400, iSeries, pSeries, xSeries, zSeries, z/OS, AFP, Intelligent Miner, WebSphere,
Netfinity, Tivoli, Informix, i5/OS, POWER, POWER5, OpenPower and PowerPC are trademarks
or registered trademarks of IBM Corporation.
Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered
trademarks of Adobe Systems Incorporated in the United States and/or other countries.
Oracle is a registered trademark of Oracle Corporation.UNIX, X/Open, OSF/1, and Motif are
registered trademarks of the Open Group.
Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are
trademarks or registered trademarks of Citrix Systems, Inc.
HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C, World Wide
Web Consortium, Massachusetts Institute of Technology.
Java is a registered trademark of Sun Microsystems, Inc.
JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for
technology invented and implemented by Netscape.
MaxDB is a trademark of MySQL AB, Sweden.
SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, and other SAP products and
services mentioned herein as well as their respective logos are trademarks or registered
trademarks of SAP AG in Germany and in several other countries all over the world. All other
product and service names mentioned are the trademarks of their respective companies. Data
contained in this document serves informational purposes only. National product specifications
may vary.
These materials are subject to change without notice. These materials are provided by SAP AG
and its affiliated companies ("SAP Group") for informational purposes only, without
representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions
with respect to the materials. The only warranties for SAP Group products and services are
those that are set forth in the express warranty statements accompanying such products and
services, if any. Nothing herein should be construed as constituting an additional warranty.
These materials are provided as is without a warranty of any kind, either express or implied,
including but not limited to, the implied warranties of merchantability, fitness for a particular
purpose, or non-infringement.
SAP shall not be liable for damages of any kind including without limitation direct, special,
indirect, or consequential damages that may result from the use of these materials.
SAP does not warrant the accuracy or completeness of the information, text, graphics, links or
other items contained within these materials. SAP has no control over the information that you
may access through the use of hot links contained in these materials and does not endorse your
use of third party web pages nor provide any warranty whatsoever relating to third party web
pages.
Any software coding and/or code lines/strings (Code) included in this documentation are only
examples and are not intended to be used in a productive system environment. The Code is only
intended better explain and visualize the syntax and phrasing rules of certain coding. SAP does

not warrant the correctness and completeness of the Code given herein, and SAP shall not be
liable for errors or damages caused by the usage of the Code, except if such damages were
caused by SAP intentionally or grossly negligent.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY |
bpx.sap.com 2007 SAP AG 14

You might also like