Java Reference
In-Depth Information
•
void close(MessageContext context)
is called at the conclusion
of a MEP just before the JAX-WS runtime dispatches a message, fault or ex-
ception.Thismethodletsahandlercleanupanyresourcesusedforprocessing
request-only or request-response message exchanges.
•
boolean handleFault(C context)
isinvokedforfaultmessagepro-
cessing. This method returns true when the handler wants to continue hand-
ling fault messages; otherwise, it returns false. It may throw
javax.xml.ws.ProtocolException
(asubclassof
WebServiceEx-
ception
) or
RuntimeException
to cause the JAX-WS runtime to cease
the handler's fault processing and dispatch the fault.
•
boolean handleMessage(C context)
isinvokedfornormalprocess-
ing of inbound and outbound messages. This method returns true when the
handler wants to continue handling such messages; otherwise, it returns false.
Itmaythrow
ProtocolException
or
RuntimeException
tocausethe
JAX-WSruntimetoceasethehandler'snormalmessageprocessingandgener-
ate a fault.
Each method is called with a
MessageContext
or subinterface argument that
stores a map of properties for handlers to use to communicate with each other and
for other purposes. For example,
MessageCon-
text.MESSAGE_OUTBOUND_PROPERTY
storesa
Boolean
objectthatidentifiesa
message'sdirection.Duringarequest(fromclienttowebservice),thisproperty'svalue
is
Boolean.TRUE
fromaclienthandler'sperspectiveand
Boolean.FALSE
froma
web service handler's perspective.
JAX-WS supports logical and protocol handlers. A
logical handler
is independent
of the message protocol (it only has access to the message payload) and is associated
with the
javax.xml.ws.handler.LogicalMessageContext
and
javax.xml.ws.handler.LogicalHandler<C extends LogicalMes-
sageContext>
interfaces. In contrast, a
protocol handler
is tied to a specific pro-
tocol; JAX-WS supports SOAP protocol handlers with the
javax.xml.ws.handler.soap.SOAPMessageContext
and
javax.xml.ws.handler.soap.SOAPHandler
interfaces.
TologtheflowofSOAPmessages,weneedtoworkwith
SOAPMessageContext
plements
SOAPHandler<SOAPMessageContext>
tologtheflowofSOAPmes-
sages by outputting them to the standard output device.
Listing 11-19.
Logging SOAP messages to standard output