Java Reference
In-Depth Information
@Test
public void testHandler(){
HelloWSService service = new HelloWSService();
//Set handler resolver into service.
service.setHandlerResolver(new HelloHandlerResolver());
// Get the Hello stub
Hello hello = service.getHelloWSPort();
//Invoke the business method
String result = hello.sayHello(name);
assertEquals("Hello, " + name + "!", result);
//Now go check your log file to see if handler worked.
}
}
The client here is just a standard invocation of a proxy following a call to wsimport in your
Ant script. That generates the service and port classes for you based on the WSDL. Before you
invoke the getXXXPort method, make sure to set the handler resolver instance on the service.
This test performs the usual assertion check to make sure that what you got back in the re-
sponse matches what you expected to get. But the real test lies in checking to make sure that
the filesystem has the files the handler writes. If you open the contents of the file written by
the handler on the response, it contains the entire SOAP envelope, as follows:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:sayHello xmlns:ns2="http://ch03.soacookbook.com/">
<arg0>Eben</arg0>
</ns2:sayHello>
</S:Body></S:Envelope>
This is the entire request SOAP envelope written to outMsg.xmlin the /tmpdirectory. The
response message will get written to the file inMsg.xmland has the following contents:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header/><S:Body>
<ns2:sayHelloResponse xmlns:ns2="http://ch03.soacookbook.com/">
<return>Hello, Eben!</return>
</ns2:sayHelloResponse>
</S:Body></S:Envelope>
Search WWH ::




Custom Search