O'Reilly logo

Java SOA Cookbook by Eben Hewitt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a Service Provider with an XML View

Problem

You want to create a service implementation that works directly with the SOAP XML in the requests and responses, rather than the object view.

Solution

Have your service implement the javax.xml.ws.Provider<T> interface.

Discussion

JAX-WS-based web services are typically implemented using annotations, which allow the developer to get up and running quickly. Such endpoint implementations are very easy to work with and save developers the trouble of having to deal with a lot of plumbing. They offer an object-level view of messages and port types as described in the WSDL, allowing developers to work comfortably with abstractions over the XML contents of the messages passed back and forth in service invocations.

But there are times when you want to have a raw XML view of the requests and responses coming through your service. That’s where Provider<T> comes in.

Provider<T> is part of JAX-WS, but it lets you work with the SAAJ API, and it offers an alternative to working with annotated SEIs. It is the server-side analog to Dispatch<T>, providing an XML message-level view of requests. The interface defines a single method for you to implement:

T invoke(T request) 

Every time a new message is received, the invoke method is called.

Vendor implementations of JAX-WS are required to support at least three values for the type parameter on the provider:

  • javax.xml.transform.Source

  • javax.activation.DataSource

  • javax.xml.soap.SOAPMessage

A Source acts as a container ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required