Java Reference
In-Depth Information
Handlers are very useful within SOA, as they provide an easy and standard means of em-
ploying many of the decorations that some of the SOAP specifications make available. For
example, you could use a handler to add a security block to an outbound message, or take ad-
vantage of WS-ReliableMessaging. You might wish to log outbound messages or even save
them to disk so that you could resend them in the event of a network failure. It could be useful
to add a unique ID to your message header.
NOTE
In fact, adding a unique ID to your message headers is probably a good idea. This does two things: it
ensures that you have a useful reference key for extending the work of operating on a message across
a grid or other distributed workflow; and it can also help prevent message replay attacks. A message
replay attack happens when a malicious user records a message in transit and resends it. The only
way to avoid replay is to ensure message uniqueness using an ID or timestamp. You can then register
that the message with a given ID has been handled, and it shouldn't be processed any further.
Another use for handlers, as indicated in the JAX-WS specification, is to ensure that messages
conform with one or more WS-I profiles.
The javax.xml.ws.handler.Handler<C extends MessageContext> interface defines
three methods, each of which makes use of a context. The context used as the handler type
parameter allows developers to pass properties between the multiple handlers processing the
same message:
boolean handleMessage(C context)
The primary method handler developers are interested in, as it gets invoked for normal
processing of messages, inbound or outbound. Return true if you want to continue pro-
cessing, or false to stop further processing.
boolean handleFault(C context)
The method that determines what to do when a SOAP fault is thrown during message pro-
cessing. Return true if you want to continue processing, or false to stop further processing.
boolean close(MessageContext context)
The method used to perform any clean-up work necessary at the end of processing. It is
invoked by the runtime immediately prior to dispatch.
In order to specify programmatically that your handler should be attached to a proxy instance,
use a javax.xml.ws.handler.HandlerResolver . This interface allows the developer to
control the handler chain that is set on a service proxy or dispatch object.
Search WWH ::




Custom Search