AddNumbersHandlerService service = new AddNumbersHandlerService();
AddNumbersHandlerPortType proxy = service.getAddNumbersHandlerPort();
BindingProvider p = (BindingProvider)proxy;
p.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, axisEndpoint);
SOAPFaultException expectedException = null;
Throwable t = null;
try {
proxy.addNumbersHandler(-1000, Integer.MIN_VALUE);
} catch (Throwable e) {
// An exception is expected
t = e;
}
// Make sure the proper exception is thrown
if (t == null) {
fail("Expected AddNumbersHandlerFault_Exception to be thrown");
}
if (t instanceof SOAPFaultException) {
expectedException = (SOAPFaultException) t;
} else {
fail("Expected SOAPFaultException to be thrown, " +
"but the exception is: " + t);
}
// also confirm that @PreDestroy method is called. Since it only makes sense to call it on the managed
// (server) side and just before the handler instance goes out of scope, we are creating a file in the
// @PreDestroy method, and will check for its existance here. If the file does not exist, it means
// @PreDestroy method was never called. The file is set to .deleteOnExit(), so no need to delete it.
File file = new File("AddNumbersProtocolHandler.preDestroy.txt");
assertTrue("File AddNumbersProtocolHandler.preDestroy.txt does not exist, meaning the @PreDestroy method was not called.", file.exists());
String log = readLogFile();
String expected_calls =
"AddNumbersLogicalHandler2 POST_CONSTRUCT\n"
+ "AddNumbersProtocolHandler2 GET_HEADERS\n"
+ "AddNumbersProtocolHandler GET_HEADERS\n"
+ "AddNumbersProtocolHandler HANDLE_MESSAGE_INBOUND\n"
+ "AddNumbersProtocolHandler2 HANDLE_MESSAGE_INBOUND\n"
+ "AddNumbersLogicalHandler2 HANDLE_MESSAGE_INBOUND\n"
+ "AddNumbersLogicalHandler HANDLE_MESSAGE_INBOUND\n"
+ "AddNumbersLogicalHandler HANDLE_FAULT_OUTBOUND\n"
+ "AddNumbersLogicalHandler2 HANDLE_FAULT_OUTBOUND\n"
+ "AddNumbersProtocolHandler2 HANDLE_FAULT_OUTBOUND\n"
+ "AddNumbersProtocolHandler HANDLE_FAULT_OUTBOUND\n"
+ "AddNumbersLogicalHandler CLOSE\n"
+ "AddNumbersLogicalHandler2 CLOSE\n"
+ "AddNumbersProtocolHandler2 CLOSE\n"
+ "AddNumbersProtocolHandler CLOSE\n"
+ "AddNumbersProtocolHandler PRE_DESTROY\n";
assertTrue("Expected : " + expected_calls + " but received " + log, expected_calls.equals(log));
// The outbound service handler adds the stack trace to the
// message. Make sure the stack trace contains the AddNumbersHandlerPortTypeImpl
TestLogger.logger.debug("Expected Exception is " +
expectedException.getMessage());
SOAPFault fault = expectedException.getFault();
assertTrue("A stack trace was not present in the returned exception's message:" +
fault.getFaultString(),
fault.getFaultString().indexOf("AddNumbersHandlerPortTypeImpl") > 0);