1 g52iws: xml messaging (briefly) chris greenhalgh 2007-11-30

17
1 G52IWS: XML Messaging (briefly) Chris Greenhalgh 2007-11-30

Upload: lewis-riley

Post on 18-Jan-2018

220 views

Category:

Documents


0 download

DESCRIPTION

3 Message-based communication Send an XML document, not parameters No necessary response –But a later message may be a response :-) “Developing Java Web Services”, figure 3.4

TRANSCRIPT

Page 1: 1 G52IWS: XML Messaging (briefly) Chris Greenhalgh 2007-11-30

1

G52IWS: XML Messaging (briefly)

Chris Greenhalgh2007-11-30

Page 2: 1 G52IWS: XML Messaging (briefly) Chris Greenhalgh 2007-11-30

2

Contents

• Introduction to message-based communication

• SOAP with Attachment API for Java• Provider-less messaging• Messaging with a JAXM provider

See “Developing Java Web Services”, Chapter 9

Page 3: 1 G52IWS: XML Messaging (briefly) Chris Greenhalgh 2007-11-30

3

Message-based communication

• Send an XML document, not parameters• No necessary response

– But a later message may be a response :-)

“Developing Java Web Services”, figure 3.4

Page 4: 1 G52IWS: XML Messaging (briefly) Chris Greenhalgh 2007-11-30

4

SOAP with Attachment API for Java

• Defined by Java Community Process JSR-67• Allows explicit construction and unpacking of

SOAP messages using Java• See example client in src/sample/client/SaajClient.java

• Can be used – to implement SOAP clients and servers directly over

HTTP (as in example)– With JAXM to support indirect and asynchronous

communication (see later)

Page 5: 1 G52IWS: XML Messaging (briefly) Chris Greenhalgh 2007-11-30

5

Recap: SOAP Message structure

“Developing Java Web Services”, figure 4.1

Page 6: 1 G52IWS: XML Messaging (briefly) Chris Greenhalgh 2007-11-30

6

SOAP: main classes & interfaces

• javax.xml.soap.SOAPMessageFactory – Source of new SOAPMessages

• javax.xml.soap.SOAPMessage – An entire SOAP message, including attachments (not

XML)• javax.xml.soap.SOAPPart,

javax.xml.soap.AttachmentPart.  – SOAP and Attachment Part(s) of a SOAPMessage– SOAP Part has SOAPEnvelope & MIMEHeaders

• javax.xml.soap.SOAPEnvelope – Contains SOAPHeader &SOAPBody

Page 7: 1 G52IWS: XML Messaging (briefly) Chris Greenhalgh 2007-11-30

7

• javax.xml.soap.SOAPHeader & javax.xml.soap.SOAPHeaderElement

• javax.xml.soap.SOAPBody & javax.xml.soap.SOAPBodyElement – The body and body elements

• javax.xml.soap.SOAPElement – (Interface) Any SOAP-related XML element in a

SOAP message• javax.xml.soap.Node

– Any XML element in a SOAP message (compare XML Document Object Model)

• javax.xml.soap.SOAPFault – Representation of a SOAP Fault

Page 8: 1 G52IWS: XML Messaging (briefly) Chris Greenhalgh 2007-11-30

8

Using SAAJ with HTTP: client

• javax.xml.soap.SOAPConnection.    – obtained from SOAPConnectionFactory – Supports request/response over HTTP– E.g. from sample client:SOAPMessage rp = conn.call(msg, urlval);

Page 9: 1 G52IWS: XML Messaging (briefly) Chris Greenhalgh 2007-11-30

9

Using SAAJ/JAXM with no JAXM Provider: server

• Extend javax.xml.messaging.JAXMServlet and implement javax.xml.messaging.ReqRespListener – E.g.

public class ReqRespServlet extends JAXMServlet implements ReqRespListener { public SOAPMessage onMessage(SOAPMessage msg) { //Implement your business logic here return respMsg; }}

Page 10: 1 G52IWS: XML Messaging (briefly) Chris Greenhalgh 2007-11-30

10

• Servlet runs in container which handles HTTP

• JAXMServlet handles – converting the POSTed SOAP message

(MIME-encoded) into a javax.xml.soap.SOAPMessage

– calling onMessage()– Converting the returned SOAPMessage into

the HTTP response

Page 11: 1 G52IWS: XML Messaging (briefly) Chris Greenhalgh 2007-11-30

11

Main JAXM classes & interfaces• javax.xml.messaging.OneWayListener

– Interface for receiving a SOAPMessagepublic void onMessage(SOAPMessage msg);

• javax.xml.messaging.ReqRespListener – Interface for receiving a SOAPMessage and replying

public SOAPMessage onMessage(SOAPMessage msg); • javax.xml.messaging.JAXMServlet

– Utility servlet for doing JAXM HTTP-based message receivers• javax.xml.messaging.ProviderConnection

– Interface for communicating with JAXM “Provider” (see later)• javax.xml.messaging.Endpoint

– Endpoint (client or service) identifier; URI

Page 12: 1 G52IWS: XML Messaging (briefly) Chris Greenhalgh 2007-11-30

12

Recap: Message-Oriented Middleware (MOM)

Application A

Persistence

Adapter API Application BMOMinfrastructureAdapter API

After “Developing Java Web Services” figure 1.6

Messages sent & received

(& transactions contexts)

Page 13: 1 G52IWS: XML Messaging (briefly) Chris Greenhalgh 2007-11-30

13

JAXM-based application architecture

“Developing Java Web Services”, figure 9.1

Page 14: 1 G52IWS: XML Messaging (briefly) Chris Greenhalgh 2007-11-30

14

JAXM-based application architecture details

ProviderConntection: allows message sendingand registering of receivers

Logical distributedJAXM provider

OneWayListener orReqRespListener interfaceto receive message(s).Identified by an Endpoint (URI)

Message bean orJAXMServlet

Local API/client

for provider

Page 15: 1 G52IWS: XML Messaging (briefly) Chris Greenhalgh 2007-11-30

15

Simple JAXM provider realisation

Local API/client

for provider

ProviderInfrastructure

Including persistence

ProviderConnectionw. Endpoint

Messagesbetweenclient andprovider

Messagesto/from

external services

Page 16: 1 G52IWS: XML Messaging (briefly) Chris Greenhalgh 2007-11-30

16

JAXM Provider• C.f. MOM infrastructure• Handles message transmission and routing

– Including message reliability (through retransmission)• Uses “Profiles” to specify the underlying

messaging protocol– E.g. SOAP-RP (SOAP Routing Protocol) or ebXML

• Handles synchronous vs asynchronous interactions– E.g. mapping asynchronous client request to

synchronous server handling

Page 17: 1 G52IWS: XML Messaging (briefly) Chris Greenhalgh 2007-11-30

17

Conclusion

• SAAJ allows direct construction/consumption of SOAP messages– No mapping to programming language types

or paradigms (such as RPC)• JAXM supports messaging-style use of

SOAP, in particular asynchronous interactions– E.g. extended business processes