14
1 Distributed Programming in Java Web Services (3) 2/41 Tracing SOAP Messages Enable trace messages by enabling the electric.logging property or using Log.startLogging Run the client with SOAP logging enabled 3/41 Logging Generated when the source of a Java interface cannot be found SOURCE Generated by any remote SOAP requests or SOAP responses SOAP Generated when an exception for oneway msg occurs ONEWAY Generated when a map file is read MAPPING Generated when a JMS warning occurs JMS Generated by any SOAP-related HTTP traffic HTTP Generated when a SOAPException constructed EXCEPTION Generated when internal GLUE exception occurs ERROR A general comment COMMENT Generated when line in a command file executed COMMAND MEANING CATEGORY

Distributed Programming in Javapeople.scs.carleton.ca/.../documents/04-Web-Services-3.pdf · 2007. 11. 21. · Services in Axis • Automatic Deployment • Using a Web Services Deployment

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Distributed Programming in Javapeople.scs.carleton.ca/.../documents/04-Web-Services-3.pdf · 2007. 11. 21. · Services in Axis • Automatic Deployment • Using a Web Services Deployment

1

DistributedProgramming in Java

Web Services (3)

2/41

Tracing SOAP Messages

•Enable trace messages by enabling theelectric.logging property or using Log.startLogging

•Run the client with SOAP logging enabled

3/41

Logging

Generated when the source of a Java interfacecannot be found

SOURCE

Generated by any remote SOAP requests orSOAP responses

SOAP

Generated when an exception for oneway msgoccurs

ONEWAY

Generated when a map file is readMAPPING

Generated when a JMS warning occursJMS

Generated by any SOAP-related HTTP trafficHTTP

Generated when a SOAPException constructedEXCEPTION

Generated when internal GLUE exception occursERROR

A general commentCOMMENT

Generated when line in a command file executedCOMMAND

MEANINGCATEGORY

Page 2: Distributed Programming in Javapeople.scs.carleton.ca/.../documents/04-Web-Services-3.pdf · 2007. 11. 21. · Services in Axis • Automatic Deployment • Using a Web Services Deployment

2

4/41

Tracing using In-code Loggingpublic class ExchangeClient { public static void main(String args[]) throws Exception { // bind to web service from WSDL at the specified URL String url = "http://localhost:8004/soap/exchange.wsdl"; IExchange exchange = (IExchange) Registry.bind(url,IExchange.class);

// Start Logging SOAP messages (using text from table) Log.startLogging("SOAP");

// invoke the web service via its proxy double rate = exchange.getRate("canada", "usa"); System.out.println("canada/usa exchange rate = " + rate); }

}

5/41

Anatomy of a SOAP Request

6/41

HTTP Request

LOG.HTTP: outbound request to tcp://192.168.15.104:8004

POST /soap/exchange HTTP/1.1Host: 192.168.15.104:8004Content-Type: text/xml; charset=UTF-8User-Agent: GLUE/2.1Connection: Keep-AliveSOAPAction: "getRate"Content-Length: 534

< material deleted >

Page 3: Distributed Programming in Javapeople.scs.carleton.ca/.../documents/04-Web-Services-3.pdf · 2007. 11. 21. · Services in Axis • Automatic Deployment • Using a Web Services Deployment

3

7/41

SOAP Message Model

Header: optional, 1 or more header entriesBody: 0 or more body entries0 or more non-standard elements

8/41

SOAP Request

LOG.SOAP: request to http://192.168.15.104:8004/soap/exchange

<?xml version='1.0' encoding='UTF-8'?> <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'soap:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'> <soap:Body> <n:getRate xmlns:n='http://tempuri.org/exchange.Exchange'> <country1 xsi:type='xsd:string'>canada</country1> <country2 xsi:type='xsd:string'>usa</country2> </n:getRate> </soap:Body> </soap:Envelope>

9/41

Anatomy of a SOAP Response

Page 4: Distributed Programming in Javapeople.scs.carleton.ca/.../documents/04-Web-Services-3.pdf · 2007. 11. 21. · Services in Axis • Automatic Deployment • Using a Web Services Deployment

4

10/41

HTTP Response

LOG.HTTP:

<?xml version='1.0' encoding='UTF-8'?><soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'soap:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'><soap:Body><n:getRateResponsexmlns:n='http://tempuri.org/exchange.Exchange'><Resultxsi:type='xsd:double'>1.0638297872340425</Result></n:getRateResponse></soap:Body></soap:Envelope>

11/41

SOAP Response

LOG.SOAP: response from http://192.168.15.104:8004/soap/exchange

<?xml version='1.0' encoding='UTF-8'?> <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'soap:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'> <soap:Body> <n:getRateResponsexmlns:n='http://tempuri.org/exchange.Exchange'> <Result xsi:type='xsd:double'>1.0638297872340425</Result> </n:getRateResponse> </soap:Body> </soap:Envelope>

12/41

Envelope-Message

http://192.168.15.104:8004/soap/exchange

Page 5: Distributed Programming in Javapeople.scs.carleton.ca/.../documents/04-Web-Services-3.pdf · 2007. 11. 21. · Services in Axis • Automatic Deployment • Using a Web Services Deployment

5

13/41

WSDL

•Web Service Description Language

•Neutral format for services to advertisethemselves on the network

• In future, can choose between competingproviders of same service (price, etc.)

•GLUE generates WSDL file automatically

14/41

WSDLhttp://localhost:8004/soap/exchange.wsdl

15/41

WSDL Messages

Request

Response

Page 6: Distributed Programming in Javapeople.scs.carleton.ca/.../documents/04-Web-Services-3.pdf · 2007. 11. 21. · Services in Axis • Automatic Deployment • Using a Web Services Deployment

6

16/41

WSDL Port Type•Defines operations offered by a service

17/41

WSDL Binding

•How messages will be handled

18/41

WSDL Service Definition

•How to access the service (defines port,binding, and service URL)

Page 7: Distributed Programming in Javapeople.scs.carleton.ca/.../documents/04-Web-Services-3.pdf · 2007. 11. 21. · Services in Axis • Automatic Deployment • Using a Web Services Deployment

7

19/41

Web Service DesignConsiderations

• Transport Protocol• HTTP -- firewall friendly, unreliable. Tends to beused synchronously for request/response.

• Asynchronous/Synchronous Messaging• Synchronous: connection remains open untilresponse sent. Servers have to maintain multipleconcurrent messages -- complex. Server has todo error handling•WS-ReliableMessaging designed to addressreliable delivery and message processing

20/41

Web Service DesignConsiderations

• Encoding style:• Encoded: primitive (standard) mapping of objectsand parameters to XML.• Literal: external specification provided for “wire”representation.• Style is mostly “encoded”

• Binding style:• RPC: Receiver must interpret message as aprocedure call (rules are SOAP-specified)• Document: XML document is delivered

• Summary: most Web Services uses SOAP encodingwith synchronous, RPC binding; i.e., looks just likeRMI, CORBA requests.

21/41

Apache Axis

•Open source web service framework

•Client programming model of Axis providescomponents for client to invoke a serviceendpoint and receive the response message

•Server programming model based on a listenerfor each transport protocol, a set of messagehandlers, and service handlers

•Let us have a closer look at its architecture

Page 8: Distributed Programming in Javapeople.scs.carleton.ca/.../documents/04-Web-Services-3.pdf · 2007. 11. 21. · Services in Axis • Automatic Deployment • Using a Web Services Deployment

8

22/41

Axis Engine Architecture

HTTP, JMS, etc. SOAP, XML-RPC

java:RPC

http://ws.apache.org/axis/java/architecture-guide.htmlhttp://www.enterpriseintegrationpatterns.com/ComposedMessagingWS.html

23/41

Axis Architecture

• Framework made up of handlers:• Invoked in order depending on configuration•Whether client or server accessing framework

• Handlers grouped in chains: request and response

• 3 chains:• Transport• Global• Service

• Reference http://xml.apache.org/axis

24/41

Service Activator

Activator handles all messaging details and invokes the service like any client. Service can be POJO.

Page 9: Distributed Programming in Javapeople.scs.carleton.ca/.../documents/04-Web-Services-3.pdf · 2007. 11. 21. · Services in Axis • Automatic Deployment • Using a Web Services Deployment

9

25/41

Techniques for Deploying WebServices in Axis

•Automatic Deployment

•Using a Web Services DeploymentDescriptor (WSDD)

•Generate proxies from an existing WSDLdocument

26/41

Automatic Deployment

•Write business logic as Java Web Service file(*.jws)• Deploy SOURCE file into webapps directory of Axis

server• File name forms part of endpoint that axis server

exposes as a Web Service:

•WSDL is automatically generated, as is the location• Can also generate client stub classes (like GLUE)• Cannot set deployment parameters though

27/41

Creating a Service

• Implement the service in a web serviceagnostic manner (as a regular class)

Page 10: Distributed Programming in Javapeople.scs.carleton.ca/.../documents/04-Web-Services-3.pdf · 2007. 11. 21. · Services in Axis • Automatic Deployment • Using a Web Services Deployment

10

28/41

Deploying the Service

• In Axis you use a Web Service DeploymentDescriptor (WSDD) to tell Axis how to routerequests to the correct target class

•SmallCompanyImpl.wsdd

29/41

Starting the Axis Server

•Two options for running Axis:•as a servlet from within a servlet engine (eg

Tomcat): code in webapps/axis•as a standalone server (for testing and simple

applications only)

• Invoking the standalone server

30/41

Deploying the Service

•Make the service available to clients bydeploying it using the AdminClient

• If deploying to the standalone Axis server,also supply the port number

•Now we are ready to invoke the service

Page 11: Distributed Programming in Javapeople.scs.carleton.ca/.../documents/04-Web-Services-3.pdf · 2007. 11. 21. · Services in Axis • Automatic Deployment • Using a Web Services Deployment

11

31/41

Create the Client

•Again two options:•Dynamic web service client: create a Call

object for each method at runtime•Static web service client: generate a proxy

from a WSDL description

•First we will use the dynamic option•Most interesting from the perspective of

understanding low level operation

32/41

Client

33/41

Appendix

•This appendix collects information you mayfind useful setting up Apache Axis

•Apache Axis “requires” Tomcat (or otherservlet container)

Page 12: Distributed Programming in Javapeople.scs.carleton.ca/.../documents/04-Web-Services-3.pdf · 2007. 11. 21. · Services in Axis • Automatic Deployment • Using a Web Services Deployment

12

34/41

Tomcat

•http://tomcat.apache.org•Servlet container, provides reference

implementation for Java Servlet andJavaServer pages technologies.

•Good release is 5.5.25

•Download and install

•Create start_tomcat, stop_tomcat shellscripts ==>

35/41

Tomcat Scripts

•Startup script:

•Shutdown script:

36/41

Configuring Tomcat Port

•Edit server.xml in $CATALINA_HOME/conf

•Change 8080 to required value

Page 13: Distributed Programming in Javapeople.scs.carleton.ca/.../documents/04-Web-Services-3.pdf · 2007. 11. 21. · Services in Axis • Automatic Deployment • Using a Web Services Deployment

13

37/41

Axis Installation

•Download Apache Axis from website•http://ws.apache.org/axis/•Latest stable v1 release is axis-1_4.zip•Also have axis 2, supports SOAP 2, REST, …• Install in a directory and put the jar files in the

axis/lib directory into your classpath•Can also install in Eclipse by adding all jar files to

the Eclipse project•Should also set default output directory to putcompiled classes into webapps/axis

38/41

Setting up Axis in Tomcat

•Axis as a servlet• Install axis subdir.

from dist’n intotomcat webappsdirectory•Set up classpath as

shown in appendix•Services classes in

WEB-INF/classes

39/41

Axis is Running!• After configuration, type http://localhost:8080/axis

Page 14: Distributed Programming in Javapeople.scs.carleton.ca/.../documents/04-Web-Services-3.pdf · 2007. 11. 21. · Services in Axis • Automatic Deployment • Using a Web Services Deployment

14

40/41

Setting up the Classpath

41/41

Axis User Guide

http://ws.apache.org/axis/java/user-guide.html