Java Reference
In-Depth Information
return "Processed work for: " + msg;
}
}
Other than the new annotation, there's nothing noteworthy about this web service. You then
need to write the actual handler implementation classes. You can have as few as one if you
like, and I'll do that here. This will be a simple class that spits out the messages to the system
output stream. I've kept it simple on purpose so that it doesn't get in the way. You would im-
plement anything you would normally want to do in a servlet filter, for example.
The last step is to create your myHandlers.xmlfile (as shown in Example 7-14 ) . Put it in the
WEB-INF/classesdirectory of your WAR.
Example7-14.myHandlers.xml
<?xml version="1.0" encoding="UTF-8"?>
<handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
<handler-chain>
<handler>
<handler-class>com.soacookbook.LogHandler</handler-class>
<handler-class>com.soacookbook.LateNotifyHandler</handler-class>
</handler>
</handler-chain>
</handler-chains>
The handlers are dynamically loaded based on the implementations specified, and they are ex-
ecuted for both inbound and outbound messages. Handlers are executed in the order listed.
Testing the service produces the following output, which illustrates the order in which the
runtime invokes the handler interface methods:
LH: handleMessage
LH: logToOut
Inbound message:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header/>
<S:Body><ns2:doWork xmlns:ns2="http://soacookbook.com/">
<msg>SOME IMPORTANT JOB</msg></ns2:doWork></S:Body>
</S:Envelope>
doing work
LH: handleMessage
LH: logToOut
Outbound message:
LH: close
Search WWH ::




Custom Search