Presentation is loading. Please wait.

Presentation is loading. Please wait.

Technische universität dortmund Service Computing Service Computing Prof. Dr. Ramin Yahyapour IT & Medien Centrum 24. November 2009.

Similar presentations


Presentation on theme: "Technische universität dortmund Service Computing Service Computing Prof. Dr. Ramin Yahyapour IT & Medien Centrum 24. November 2009."— Presentation transcript:

1 technische universität dortmund Service Computing Service Computing Prof. Dr. Ramin Yahyapour IT & Medien Centrum 24. November 2009

2 technische universität dortmund SOAP Example Request <SOAP-ENV:Envelope xmlns:SOAP-ENV="SoapEnvelopeURI" SOAP-ENV:encodingStyle="SoapEncodingURI"> SUNW Winter 2009/10 2

3 technische universität dortmund Winter 2009/10 3 Sample SOAP Request POST /Supplier HTTP/1.1 Host: www.somesupplier.com Content-Type: text/xml; charset="utf-8" Content-Length: nnnn SOAPAction: "Some-URI" 557010 1050420459 AMF Night Hawk Pearl M2 Bowling Ball 100 130.95 2000-06-19 10:09:56 header body Envelope

4 technische universität dortmund SOAP Response Format Winter 2009/10 4 HTTP/1.1 200 OK Content-Type: text/xml; charset="utf-8" Content-Length: nnnn <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP- ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> 561381 header body Envelope

5 technische universität dortmund WSDL components Winter 2009/10 5

6 technische universität dortmund Step 1: Write Java Application Winter 2009/10 6 public class StockQuoteService { DocumentBuilder xdb = XMLParserUtils.getXMLDocBuilder(); public float getQuote (String symbol) throws Exception { URL url = new URL ("http://www.xmltoday.com/examples/stockquote/getxmlquote.vep?s="+symbol); InputStream is = url.openStream (); Document d = xdb.parse(is); Element e = d.getDocumentElement (); NodeList nl = e.getElementsByTagName ("price"); e = (Element) nl.item (0); String quoteStr = e.getAttribute ("value"); try { return Float.valueOf (quoteStr).floatValue (); } catch (NumberFormatException e1) { // mebbe its an int? try { return Integer.valueOf (quoteStr).intValue () * 1.0F; } catch (NumberFormatException e2) { return -1.0F; }

7 technische universität dortmund Generate WSDL (sqs.wsdl) Winter 2009/10 7 Stock Quote Service

8 technische universität dortmund Generate WSDL (sqs-interface.wsdl) 8 message portType

9 technische universität dortmund Generate WSDL (sqs-interface.wsdl) Winter 2009/10 9 Binding (SOAP)

10 technische universität dortmund UDDI and WSDL Winter 2009/10 10

11 technische universität dortmund Building a Web Service public class StockQuoteService { if ( symbol.equals("XXX") ) return( (float) 55.25 ); URL url = new URL( "http://www.xmltoday.com/examples/" + "stockquote/getxmlquote.vep?s="+symbol ); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse( url.toExternalForm() ); Element elem = doc.getDocumentElement(); NodeList list = elem.getElementsByTagName( "stock_quote"); if ( list != null && list.getLength() != 0 ) { elem = (Element) list.item(0); list = elem.getElementsByTagName( "price" ); elem = (Element) list.item(0); String quoteStr = elem.getAttribute("value"); try { return Float.valueOf(quoteStr).floatValue(); } catch (NumberFormatException e1) {//Exception handling} }

12 technische universität dortmund WSDL Definition Stock Quote Service Winter 2009/10 12

13 technische universität dortmund Service Endpoint Interface package helloservice; import java.rmi.Remote; import java.rmi.RemoteException; public interface HelloIF extends Remote { public String sayHello(String s) throws RemoteException; } Winter 2009/10 13 File: HelloIF.java

14 technische universität dortmund Service Endpoint Implementation package helloservice; public class HelloImpl implements HelloIF { public String message ="Hello"; public String sayHello(String s) { return message + s; } Winter 2009/10 14 File: HelloImpl.java

15 technische universität dortmund Static Web Service Client package staticstub; import javax.xml.rpc.Stub; public class HelloClient { private String endpointAddress; public static void main(String[] args) { System.out.println("Endpoint address = " + args[0]); try { Stub stub = createProxy(); stub._setProperty (javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY, args[0]); HelloIF hello = (HelloIF)stub; System.out.println(hello.sayHello("Duke!")); } catch (Exception ex) { ex.printStackTrace(); } private static Stub createProxy() { // Note: MyHelloService_Impl is implementation-specific. return (Stub) (new MyHelloService_Impl().getHelloIFPort()); } 15 File: HelloClient.java

16 technische universität dortmund J2EE Application Client package appclient; import javax.xml.rpc.Stub; import javax.naming.*; public class HelloClient { private String endpointAddress; public static void main(String[] args) { System.out.println("Endpoint address = " + args[0]); try { Context ic = new InitialContext(); MyHelloService myHelloService = (MyHelloService) ic.lookup("java:comp/env/service/MyJAXRPCHello"); appclient.HelloIF helloPort = myHelloService.getHelloIFPort(); ((Stub)helloPort)._setProperty (Stub.ENDPOINT_ADDRESS_PROPERTY,args[0]); System.out.println(helloPort.sayHello("Jake!")); System.exit(0); } catch (Exception ex) { ex.printStackTrace(); System.exit(1); } 16 File: HelloClient.java


Download ppt "Technische universität dortmund Service Computing Service Computing Prof. Dr. Ramin Yahyapour IT & Medien Centrum 24. November 2009."

Similar presentations


Ads by Google