Professional Documents
Culture Documents
How-To-Guide for generating a Web Service Client with the SAP NetWeaver Application Server
Java EE 5 Edition
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.
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..
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.
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.
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.
<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> <%}%>
System.setProperty("http.proxyHost",
"<my_http_proxy.mycorp.com>"); System.setProperty("proxyPort",
"my_proxy_port"); System.setProperty("http.proxyPort",
"my_http_proxy_port");
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("");
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
</tr>
</table>
<% }
<%@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
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