Скачать презентацию
Идет загрузка презентации. Пожалуйста, подождите
Презентация была опубликована 10 лет назад пользователемЖанна Таловерова
1 © 2006 IBM Corporation Made available under the EPL v WebSphere Services Technical Conference world class skill building and technical enablement May 1-5, 2006 Las Vegas, NV Developing Web Services with Eclipse Web Tools Session Number: D22 Arthur Ryman,
2 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 2 Objectives You will learn how to use Eclipse WTP to develop Web services You will learn about top-down and bottom-up service creation, client access, interoperability testing, discovery, and publication After this tutorial you should be able to develop Web services using WTP and products such as AST and RAD that are based on it Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both. Other company, product, or service names may be trademarks or service marks of others.
3 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 3 About this tutorial You will use WTP to develop Web services in a sequence of iterations The example used is League Planet, a fictitious Web site for amateur sports leagues For more information, see Chapter 10 of the forthcoming book, Java Web Application Development Using Eclipse For the most benefit, you should follow along You are expected to be comfortable using Eclipse and programming in Java Some prior knowledge of Web services would be useful
4 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 4 Code Examples This tutorial is based on a complete working Web application called League Planet All source code is provided in the examples directory The directory structure is: / / e.g. webservices/iteration1/IceHockeyService/schedule.xmlwebservices/iteration1/IceHockeyService/schedule.xml To make the application work, you must create some projects and generate some code
5 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 5 Introduction Web services have emerged as the standard technology for integrating heterogeneous systems across the Internet and intranet e.g. services implemented on J2EE TM application servers and clients implemented on.NET desktops or PHP Web servers The key technologies are: Extensible Markup Language: XML – for messages XML Schema Description: XSD – for message description Web Service Description Language: WSDL – for service description Universal Description, Discovery, and Integration: UDDI – for service registries Web Service Interoperability: WS-I – for interoperability
6 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 6 Overview of Iterations 1. Developing Web Services Top-Down 2. Developing Web Services Bottom-Up 3. Generating Web Service Client Proxies 4. Testing Web Services for Interoperability 5. Using Web Services in Web Applications 6. Discovering and Publishing Web Services
7 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 7 Iteration 1 – Developing Web Services Top-Down
8 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 8 Iteration 1 - Developing Web Services Top-Down Top-Down development means designing the Web service interface first and then developing the implementation code This approach yields the best interoperability because the underlying implementation details do not bleed through into the interface This approach is required if the messages use existing industry or corporate XML document formats You need to learn XSD and WSDL design skills Luckily, WTP has two great editors that make this task easier
9 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 9 Iteration 1 Overview 1. Use the XSD editor to describe the League Planet schedule format 2. Use the WSDL editor to describe a Web service for querying schedules 3. Use the Web service wizard to generate a Java skeleton for the service and deploy it to the Axis SOAP engine running on Tomcat 4. Fill in the implementation of the skeleton by accessing the League Planet business tier 5. Use the Web service explorer to test the Web service
10 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 10 Create a new Dynamic Web Project named IceHockeyService to contain the Web service.
11 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 11 Describing schedule.xml League Planet has an XML format for schedules Import IceHockeyService/schedule.xml for an example instance documentIceHockeyService/schedule.xml Your goal is to describe this format using XSD
12 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 12 Create a new XML Schema file named schedule.xsd in IceHockeyService.
13 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 13 schedule.xsd In general, there are many equivalent ways to describe a given format using XSD For Web services, its a good practice to describe formats in a way that works well with XML data binding toolkits such as JAX- RPC Define complexTypes for the content model of each element The XSD editor lets you edit in the source tab, the graphical tab, the outline view, and the property view Try creating schedule.xsd Import IceHockeyService/schedule.xsd before proceedingIceHockeyService/schedule.xsd
14 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 14 View schedule.xsd in the Graph tab of the XSD editor.
15 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 15 View ScheduleContent of schedule.xsd in the Graph tab of the XSD editor.
16 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 16 View schedule.xsd in the Outline view of XSD editor.
17 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 17 query.wsdl Now that youve described the message format using XSD, you next goal is to describe a Web service for retrieving it For simplicity, the Web service will have a single operation named getSchedule The operation will take as input, the schedule id, and return as output the corresponding schedule document
18 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 18 Create a new WSDL file named query.wsdl in IceHockeyService.
19 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 19 Enter the namespace for the WSDL and have the wizard generate a skeleton document for you using the SOAP binding and document/literal style.
20 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 20 WSDL editor You can edit the document in the graph tab, the source tab, the outline view, and the property view. WSDL describes Web service using a hierachy of constructs: message, portType, binding, and service The editor has a wizard that generates binding content for you Try creating query.wsdl Import IceHockeyService/query.wsdl before proceedingIceHockeyService/query.wsdl
21 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 21 View query.wsdl in the Graph tab of the WSDL editor.
22 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 22 View query.wsdl in the Outline view of the WSDL editor.
23 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 23 Deploying query.wsdl You have now described the Web service Your next goal is to deploy it This step assumes you have previously installed Tomcat and added it to WTP Select query.wsdl and execute the command Web Services > Generate Java bean skeleton This command launches the Web service wizard
24 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 24 Check the boxes to Install and Start the Web service and click Next.
25 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 25 The wizard validates your WSDL. Click Next.
26 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 26 The wizard selects Axis and Tomcat. Click Next.
27 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 27 The wizard lets you select a source folder and change the package name for the generated skeleton. Accept the defaults and click Next.
28 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 28 Click Start server, wait, then click Next.
29 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 29 The wizard lets you publish the WSDL to UDDI. Just click Finish.
30 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 30 What the wizard did. Installed the Axis SOAP engine in your project Generated the Java bean skeleton for you service and lots of Java XML data binding classes in the src folder Copied query.wsdl to WebContent/wsdl/querySOAP.wsdl and set its endpoint to your Web application (also copied schedule.xsd) Created the Axis deployment descriptor WebContent/WEB- INF/server-config.wsdd Created a couple of handy Axis files to deploy and undeploy your Web service in a subfolder of WebContent/WEB-INF Started Tomcat to make your Web service available
31 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 31 The IceHockeyService project after the wizard completed. Select AxisServlet and execute the command Run As > Run on Server.
32 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 32 View the list of deployed Web services.
33 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 33 LeaguePlanetModel Business Tier The Web service is running but it just returns null at this point You next need to fill in the implementation of the Java bean skeleton The Web service needs to access the League Planet business tier If you have not previously done so, create a new J2EE Utility Project named LeaguePlanetModel and import the source code from LeaguePlanentModel/src into itLeaguePlanentModel/src
34 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 34 Select IceHockeyService and open its Properties dialog. Add LeaguePlanetModel as a J2EE Module Dependency.
35 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 35 View the module structure of the server in the Servers view.
36 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 36 Filling in the Java bean skeleton You now have a Web service skeleton and access to the League Planet business tier. Your next goal is to implement the Web service. The generated skeleton class is com.leagueplanet.ws.query.QuerySOAPImpl Import IceHockeyService/src/com/leagueplanet/ws/query/QuerySOAPImpl.java now IceHockeyService/src/com/leagueplanet/ws/query/QuerySOAPImpl.java This modified skeleton simply delegates to a new class com.leagueplanet.Query to avoid confusion with the generated code Create this new class now and try to implement it Import IceHockeyService/src/com/leagueplanet/Query.java before proceedingIceHockeyService/src/com/leagueplanet/Query.java
37 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 37 Testing the Web service At this point the Web service is ready to test You will test it using the Web Service Explorer Select IceHockeyService/WebContent/wsdl/querySOAP.wsdl and execute the command Web Services > Test with Web Service Explorer The Web Service Explorer will start and open a new Web browser in the editor area
38 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 38 View querySOAP.wsdl in the Web Service Explorer. Click the getSchedule link.
39 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 39 View the getSchedule operation. Enter 1 in the scheduleId field and click Go. The schedule is returned in the Status pane.
40 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 40 Double-click the Status pane to maximize it. Click the Source link to view the SOAP message.
41 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 41 View the SOAP message source. Click the Form link to return to the Form display.
42 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 42 Iteration 2 – Developing Web Services Bottom-Up
43 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 43 Iteration 2 – Developing Web Services Bottom-Up Bottom-Up development starts with a Java service class and generates the WSDL from it This approach is more productive for Java developers since XSD and WSDL design skills are not required It is suitable when the Java class uses simple data transfer objects as inputs and outputs of its operations It is dangerous because the resulting XSD may be complex and less interoperable There is risk of implementation bleed through into the service interface and coupling between the client and service
44 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 44 Iteration 2 Overview 1. Develop a Java service class to get details about a game and to update its score 2. Use the Web service wizard to deploy the service 3. Use the WSDL editor to view the generated WSDL
45 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 45 Create the Java service implementation The service implementation will be created in the package com.leagueplanet Import the following Java classes into IceHockeyService/src/com/leagueplanet: GameDetail.java – the data transfer class GameDetail.java GameException.java ScoreException.java Update.java – the service class Update.java The service has two operations: getGame updateScore The service accesses the League Planet business tier
46 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 46 Deploy the service Select Update.java and execute the command Web Services > Create Web service
47 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 47 Check the Install and Start Web service boxes. You could click Finish at this point since the wizard picks sensible defaults. Click Next to step this the pages.
48 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 48 The wizard lets you select a different class. Click Next.
49 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 49 The wizard lets you select a different project. Click Next.
50 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 50 The wizard lets you select the methods to include as operations and the style to use. Click Next.
51 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 51 Confirm that Update was deployed using the AxisServlet.
52 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 52 View the generated Update.wsdl in the WSDL editor.
53 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 53 Iteration 3 – Generating Web Service Client Proxies
54 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 54 Iteration 3 – Generating Web Service Client Proxies Web services can be invoked from programs written in many programming languages, e.g. Java, C#, PHP, JavaScript TM etc. Most languages support dynamic invocation and do not require any code generation A client proxy simplifies Web service invocation by producing a class that resembles the service interface In J2EE, client proxies are specified by JAX-RPC and its follow- on JAX-WS
55 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 55 Iteration 3 Overview 1. Use the Web service wizard to generate a Java client proxy and a JSP test client 2. Test the service using the JSP test client
56 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 56 Select Update.wsdl and execute the command Web Services > Generate Client. The wizard opens. Check the Install, Test, and Monitor boxes and click Next.
57 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 57 The wizard validates the WSDL. Click Next.
58 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 58 The wizard lets you select a different client project. Click Next.
59 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 59 The wizard lets you change the package for the generated client proxy code. Click Next.
60 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 60 The wizard lets you select the operations to include in the generated JSP test client. It also lets you select a different output folder for the JSPs. Click Finish.
61 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 61 What the wizard did Created a new Dynamic Web project named IceHockeyServiceClient Installed Axis in IceHockeyServiceClient Generated Java proxy code including XML data binding classes and exceptions in IceHockeyServiceClient/src/com/leagueplanet Generated JSP test client code in IceHockeyWebContent/sampleUpdateProxy Started an instance of the TCP/IP Monitor and configured the JSP client to use it Opened the JSP test client in a Web browser You are now ready to test the Web service
62 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 62 Click the getGameDetail method. Enter gameId = 1 and click Invoke. View the game details in the Result pane.
63 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 63 Click the updateScore method. Enter input parameters and click Invoke. The operation returns an empty result.
64 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 64 Click the getGameDetails method. Enter gameId =1 and click Invoke. View the updated score in the Result pane to confirm that the updateScore operation works correctly.
65 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 65 Iteration 4 – Testing Web Services for Interoperability
66 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 66 Iteration 4 – Testing Web Services for Interoperability The main value proposition of Web services is interoperability between heterogeneous systems, e.g..NET, PHP, JavaScript WS-I.org was established to define interoperability profiles WTP lets you validate both your WSDL and your Web service implementations for interoperability
67 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 67 Click the getEndpoint method. Click Invoke. View the endpoint address in the Result pane. Note the port number.
68 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 68 Open the Preferences dialog and select the TCP/IP Monitor page. Note the port number of the monitor matches the endpoint.
69 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 69 View the recorded messages in the TCP/IP Monitor view. Click the Validate icon (document with checkmark).
70 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 70 The wizard lets you select a folder to store the message log file. Select IceHockeyServiceClient and click Next.
71 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 71 The wizard lets you validate the message against a WSDL file. Select Update.wsdl and click Next.
72 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 72 The wizard lets you select the WSDL element to use. Select the Update port and click Finish.
73 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 73 The messages are valid. In the event of errors, markers are placed in the generated log file.
74 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 74 Use the Profile Compliance and Validation Preference page to control the level of validation.
75 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 75 Iteration 5 – Using Web Services in Applications
76 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 76 Iteration 5 – Using Web Services in Applications Web services can be used in applications developed with many programming languages and technologies Web services allow alternate user interfaces to be developed Web services allow decoupling of the presentation and business tiers within an enterprise Java applications can use JAX-RPC or JAX-WS to access both Java and non-Java Web services
77 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 77 Iteration 5 Overview 1. Develop a user interface in IceHockeyServiceClient based on JSPs and servlets 2. Access the Update Web service from the servlet using the Java client proxy
78 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 78 Create a new servlet in IceHockeyServiceClient. Enter package and class names. Click Next.
79 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 79 Enter a description and URL mapping. Click Next.
80 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 80 Check the doGet and doPost boxes. Click Finish.
81 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 81 Develop the user interface The wizard created and configured the UpdateScoreServlet Create two new JSPs: score-form.jsp – to input score, has Submit button score-confirmation.jsp – to confirm score update, has Edit button Code the servlet as follows: doGet takes a gameId query parameter, calls the service to get the game detail, puts the game detail in the session, and forwards to score-form.jsp doPost takes gameId, visitorScore, and homeScore query parameters, calls the service to update the score, gets the new game detail, and forwards to score-confirmation.jsp
82 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 82 Import the UI code Just kidding! That was way too much code to write. Import the following code into IceHockeyService: /src/com/leagueplanet/ui/UpdateScoreServlet.java /WebContent/score-form.js /WebContent/score-confirmation.js /WebContent/schedule.css /WebContent/validator.css /WebContent/score-validator.js Note the JAX-RPC usage pattern in the servlet
83 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 83 Select the updateScore servlet and execute the command Run As > Run on Server. A GameException is thrown because you didnt provide a gameId query parameter.
84 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 84 Append ?gameId=1 to the URL and try again. Now the score form is displayed. Enter a new score and click Submit.
85 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 85 The score confirmation page is displayed. Click Edit to update the score again.
86 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 86 Iteration 6 – Discovering and Publishing Web Services
87 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 87 Iteration 6 – Discovering and Publishing Web Services You can look for available Web services in UDDI registries You can also publish Web services in UDDI registries UDDI provides a SOAP Web service for dynamic discovery You can also look for and publish Web services using the simpler WSIL document format In the future, Web crawlers might harvest WSIL documents and automatically populate UDDI registries so you can take advantage of the powerful UDDI inquiry support
88 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 88 Iteration 6 Overview 1. Explore a UDDI registry 2. Explore a WSIL document 3. Create a WSIL document
89 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 89 Launch the Web Service Explorer. Select the XMethods UDDI Registry and click Go.
90 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 90 View the registry details. Click the Find link.
91 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 91 Enter a name for the query. Search for Services. Enter a partial service name to search for and click Go.
92 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 92 View the query results. Click the service links to explore the services.
93 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 93 View the webservicex.com service. Click the Add to WSDL Page icon (with plus sign).
94 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 94 View the WSDL details. Click the StockQuoteSOAP link.
95 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 95 View the WSDL binding details. Click the GetQuote link.
96 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 96 View the operation details. Click the Add link and enter a stock symbol. Click Go.
97 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 97 View the result of the operation in the Status pane.
98 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 98 WSIL As you can see from this exercise, UDDI is very complex WSIL is a simpler way to publish information about Web services WSIL can refer to WSDL, UDDI, and other WSIL documents WSIL was jointly developed by IBM and Microsoft Microsoft still uses the precursor, DISCO There is not a lot of WSIL deployed XMethods supports it and several other technologies
99 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 99 Surf to Click the Access link.
100 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 10 0 View the many access methods supported by XMethods. Copy the WS-Inspection link.
101 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 10 1 Open the WSIL page of the Web Service Explorer (page with globe icon). Paste in the XMethods WSIL URL, select WSDL Services, and click Go.
102 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 10 2 View the list of WSDL services registered at XMethods.
103 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 10 3 Create an new inspection.wsil file in IceHockeyService/WebContent
104 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 10 4 Edit inspection.wsil Select IceHockeyService/WebContent/wsdl/querySOAP.wsdl and execute the command Web Services > Generate WSIL to create querySOAP.wsil Repeat for Update.wsdl Merge the contents of these into inspection.wsil and add abstracts Import IceHockeyService/WebContent/inspection.wsil before proceedingIceHockeyService/WebContent/inspection.wsil
105 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 10 5 Enter in WSIL page, select WSDL Services and click Go.
106 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 10 6 View the available WSDL services. Click the QuerySOAP.wsdl link.
107 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 10 7 View the QuerySOAP.wsdl details.
108 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 10 8 Web Services Summary In this tutorial you have covered all the major functional areas of Web service development that are available in WTP Tools covered included the Web Service Wizard, Web Service Explorer, XSD Editor, WSDL Editor, TCP/IP Monitor, and WS-I Test Tools Technologies covered include XSD, WSDL, SOAP, UDDI, WSIL, JAX-RPC, and Axis For further details consult the WTP Help and Web site
109 2006 WebSphere Services Technical Conference © 2006 IBM Corporation 10 9 Questions Please complete your session evaluation Thank you
Еще похожие презентации в нашем архиве:
© 2024 MyShared Inc.
All rights reserved.