Unformatted text preview:

Chapter 29: Introduction to Web Services and SOAP29.1 Introduction29.2 Simple Object Access Protocol (SOAP)Fig. 29.1 Class SimpleService. Line 4 Lines 6-1229.2 Simple Object Access Protocol (SOAP) (cont.)Slide 6Fig. 29.4 Client making a SOAP request (part 1). Lines 10-11 Line 13 Line 17 Lines 27-28 Lines 31-33Fig. 29.4 Client making a SOAP request (part 2). Lines 40-44 Line 48 Lines 51-57 Lines 60-63Fig. 29.4 Client making a SOAP request (part 3).29.3 SOAP Weather ServiceFig. 29.5 SOAP implementation of class Weather-Service (part 1). Line 11Fig. 29.5 SOAP implementation of class Weather-Service (part 2). Lines 66-71Fig. 29.5 SOAP implementation of class Weather-Service (part 3). Lines 95-100Fig. 29.6 SOAP implementation of class Weather-ServiceClient (part 1). Lines 31-32Fig. 29.6 SOAP implementation of class Weather-ServiceClient (part 2). Lines 35-37 Line 46 Lines 49-55 Lines 58-65Fig. 29.6 SOAP implementation of class Weather-ServiceClient (part 3). Line 95Fig. 29.6 SOAP implementation of class Weather-ServiceClient (part 4).29.3 SOAP Weather Service (cont.)Slide 19Slide 20 2002 Prentice Hall. All rights reserved.Chapter 29: Introduction to Web Services and SOAPOutline29.1 Introduction29.2 Simple Object Access Protocol (SOAP)29.3 SOAP Weather Service 2002 Prentice Hall. All rights reserved.29.1 Introduction•SOAP–Simple Object Access Protocol–Promote interoperability•Communication among different software systems.–Provides XML communication in many Web services•Web Services–Exposes public interfaces usable by Web applications 2002 Prentice Hall. All rights reserved.29.2 Simple Object Access Protocol (SOAP)•SOAP–HTTP-XML-based protocol–Enables application to communicate over Internet–Uses XML documents called messages•SOAP message contains an envelope–Describes message’s content and intended recipient–Ability to make a Remote Procedure Call (RPC)•Request to another machine to run a task 2002 Prentice Hall.All rights reserved.OutlineFig. 29.1 Class SimpleService.Line 4Lines 6-121 // Fig. 29.1: SimpleService.java2 // Implementation for the requested method on the server3 4 public class SimpleService {5 6 public String getWelcome( String message ) throws Exception7 {8 String text = 9 "Welcome to SOAP!\nHere is your message: " + message;10 11 return text; // response12 }13 }Class SimpleService resides on a serverMethod returns a String when invoked; this method is made available to remote clients 2002 Prentice Hall. All rights reserved.29.2 Simple Object Access Protocol (SOAP) (cont.)Fig. 29.2 SOAP package administration tool. 2002 Prentice Hall. All rights reserved.29.2 Simple Object Access Protocol (SOAP) (cont.)Fig. 29.3 Description of deployed service. 2002 Prentice Hall.All rights reserved.OutlineFig. 29.4 Client making a SOAP request (part 1).Lines 10-11Line 13Line 17Lines 27-28Lines 31-331 // Fig. 29.4 : GetMessage.java2 // Program that makes a SOAP RPC3 4 // import Java packages5 import java.io.*;6 import java.net.*;7 import java.util.*;8 9 // import third-party packages10 import org.apache.soap.*;11 import org.apache.soap.rpc.*;12 13 public class GetMessage {14 15 // main method16 public static void main( String args[] ) {17 String encodingStyleURI = Constants.NS_URI_SOAP_ENC;18 String message;19 20 if ( args.length != 0 )21 message = args[ 0 ];22 else23 message = "Thanks!";24 25 // attempt SOAP remote procedure call26 try { 27 URL url = new URL( 28 "http://localhost:8080/soap/servlet/rpcrouter" );29 30 // build call31 Call remoteMethod = new Call();32 remoteMethod.setTargetObjectURI( 33 "urn:xml-simple-message" );34 Client for the RPCSOAP-implementation APIsSpecify encoding style used for SOAP messageSpecify URL of server to which the client sends the SOAP messageInstantiate Call object and set its URI 2002 Prentice Hall.All rights reserved.OutlineFig. 29.4 Client making a SOAP request (part 2).Lines 40-44Line 48Lines 51-57Lines 60-6335 // set name of remote method to be invoked36 remoteMethod.setMethodName( "getWelcome" );37 remoteMethod.setEncodingStyleURI( encodingStyleURI );38 39 // set parameters for remote method40 Vector parameters = new Vector();41 42 parameters.addElement( new Parameter( "message", 43 String.class, message, null ) );44 remoteMethod.setParams( parameters );45 Response response;46 47 // invoke remote method48 response = remoteMethod.invoke( url, "" );49 50 // get response51 if ( response.generatedFault() ) {52 Fault fault = response.getFault();53 54 System.err.println( "CALL FAILED:\nFault Code = "55 + fault.getFaultCode()+ "\nFault String = " 56 + fault.getFaultString() );57 }58 59 else {60 Parameter result = response.getReturnValue();61 62 // display result of call63 System.out.println( result.getValue() );64 }65 }66 Build parameters used to invoke method getWelcome of class SimpleServiceInvoke method getWelcome and store returned value in Response objectDisplay message if error occurredDisplay remote method’s returned value if no problems occurred 2002 Prentice Hall.All rights reserved.OutlineFig. 29.4 Client making a SOAP request (part 3).67 // catch malformed URL exception68 catch ( MalformedURLException malformedURLException ) {69 malformedURLException.printStackTrace();70 System.exit( 1 );71 }72 73 // catch SOAPException74 catch ( SOAPException soapException ) {75 System.err.println( "Error message: " +76 soapException.getMessage() );77 System.exit( 1 );78 }79 }80 }java GetMessage Welcome to SOAP!Here is your message: Thanks! java GetMessage "my message”Welcome to SOAP!Here is your message: my message 2002 Prentice Hall. All rights reserved.29.3 SOAP Weather Service•SOAP Weather Service–Web service–Modification of RMI-based Weather Service (Chapter 13)–Use SOAP RPC instead of Java RMI•Send information from server to client 2002 Prentice Hall.All rights


View Full Document

UCF COP 4610L - Lecture Notes

Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?