use of fromwsdl.handler.common.HandlerTracker in project metro-jax-ws by eclipse-ee4j.
the class HandleFaultTester method testClientException2.
/*
* Same as testClientException1 except that a protocol
* exception is thrown from handleFault instead of
* a generic runtime exception.
* ProtocolExceptions are not rewrapped in WebServiceException
*/
public void testClientException2() throws Exception {
TestService testStub = getTestStub(getService());
HandlerTracker tracker = HandlerTracker.getClientInstance();
tracker.clearAll();
for (int i = 0; i < numTotalHandlers; i++) {
tracker.setHandlerAction(CLIENT_PREFIX + i, HA_REGISTER_HANDLE_XYZ);
}
tracker.setHandleFaultAction(CLIENT_PREFIX + 4, HF_THROW_PROTOCOL_EXCEPTION);
tracker.setHandlerAction(CLIENT_PREFIX + 5, HA_THROW_PROTOCOL_EXCEPTION_OUTBOUND);
try {
testStub.testInt(42);
fail("did not receive any exception");
} catch (ProtocolException pe) {
String msg = pe.getMessage();
assertTrue("received exception from wrong handler", msg.startsWith(CLIENT_PREFIX + 4));
assertTrue("did not get proper message in exception: " + msg, msg.indexOf("handleFault") != -1);
} catch (WebServiceException wse) {
fail("did not receive ProtocolException. received: " + wse);
} catch (Exception oops) {
fail("did not receive ProtocolException. received: " + oops);
}
// check called handlers
String[] called = { "0", "1", "3", "4", "5", "4_FAULT" };
int[] closed = { 5, 4, 3, 1, 0 };
List<String> calledHandlers = tracker.getCalledHandlers();
assertEquals("Did not get proper number of called handlers", called.length, calledHandlers.size());
for (int i = 0; i < called.length; i++) {
assertEquals("did not find expected handler", CLIENT_PREFIX + called[i], calledHandlers.get(i));
}
// check closed handlers
List<String> closedHandlers = tracker.getClosedHandlers();
assertEquals("Did not get proper number of closed handlers", closed.length, closedHandlers.size());
for (int i = 0; i < closed.length; i++) {
assertEquals("did not find expected handler", CLIENT_PREFIX + closed[i], closedHandlers.get(i));
}
// check destroyed handlers
List<String> destroyedHandlers = tracker.getDestroyedHandlers();
assertTrue("should be no handlers destroyed", destroyedHandlers.isEmpty());
}
use of fromwsdl.handler.common.HandlerTracker in project metro-jax-ws by eclipse-ee4j.
the class HandleFaultTester method testServerException3.
/*
* Same as testServerException2 except that a logical
* handler throws the first protocol exception, then
* a soap handler throws the second one from the handleFault
* method. See testServerException2 description for more detail.
*/
public void testServerException3() throws Exception {
TestService_Service service = getService();
TestService testStub = getTestStub(service);
ReportService reportStub = getReportStub(service);
HandlerTracker tracker = HandlerTracker.getClientInstance();
reportStub.clearHandlerTracker();
for (int i = 0; i < numTotalServerHandlers; i++) {
reportStub.setInstruction(SERVER_PREFIX + i, HA_REGISTER_HANDLE_XYZ);
}
reportStub.setInstruction(SERVER_PREFIX + 1, HA_THROW_PROTOCOL_EXCEPTION_INBOUND);
reportStub.setInstruction(SERVER_PREFIX + 2, HF_THROW_PROTOCOL_EXCEPTION);
tracker.clearAll();
try {
testStub.testInt(42);
fail("did not receive exception");
} catch (SOAPFaultException sfe) {
// check which exception came back
SOAPFault fault = sfe.getFault();
assertNotNull("did not receive fault in exception", fault);
String handlerMsg = fault.getFaultString();
assertNotNull("null message in exception", handlerMsg);
assertTrue("did not receive the expected exception, received: " + handlerMsg, handlerMsg.startsWith(SERVER_PREFIX + 2));
assertTrue("did not get proper message, got: " + handlerMsg, handlerMsg.indexOf("from handleFault") != -1);
}
// check called handlers on server side
String[] called = { "4", "2", "1", "2_FAULT" };
List<String> calledHandlers = reportStub.getReport(REPORT_CALLED_HANDLERS);
assertEquals("Did not get proper number of called handlers", called.length, calledHandlers.size());
for (int i = 0; i < called.length; i++) {
assertEquals("did not find expected handler", SERVER_PREFIX + called[i], calledHandlers.get(i));
}
}
use of fromwsdl.handler.common.HandlerTracker in project metro-jax-ws by eclipse-ee4j.
the class HandleFaultTester method testServerException4.
/*
* Same as testServerException3 except with different
* handlers throwing the exceptions.
*/
public void testServerException4() throws Exception {
TestService_Service service = getService();
TestService testStub = getTestStub(service);
ReportService reportStub = getReportStub(service);
HandlerTracker tracker = HandlerTracker.getClientInstance();
reportStub.clearHandlerTracker();
for (int i = 0; i < numTotalServerHandlers; i++) {
reportStub.setInstruction(SERVER_PREFIX + i, HA_REGISTER_HANDLE_XYZ);
}
reportStub.setInstruction(SERVER_PREFIX + 0, HA_THROW_PROTOCOL_EXCEPTION_INBOUND);
reportStub.setInstruction(SERVER_PREFIX + 2, HF_THROW_PROTOCOL_EXCEPTION);
tracker.clearAll();
try {
testStub.testInt(42);
fail("did not receive exception");
} catch (SOAPFaultException sfe) {
// check which exception came back
SOAPFault fault = sfe.getFault();
assertNotNull("did not receive fault in exception", fault);
String handlerMsg = fault.getFaultString();
assertNotNull("null message in exception", handlerMsg);
assertTrue("did not receive the expected exception, received: " + handlerMsg, handlerMsg.startsWith(SERVER_PREFIX + 2));
assertTrue("did not get proper message, got: " + handlerMsg, handlerMsg.indexOf("from handleFault") != -1);
}
// check called handlers on server side
String[] called = { "4", "2", "1", "0", "1_FAULT", "2_FAULT" };
List<String> calledHandlers = reportStub.getReport(REPORT_CALLED_HANDLERS);
assertEquals("Did not get proper number of called handlers", called.length, calledHandlers.size());
for (int i = 0; i < called.length; i++) {
assertEquals("did not find expected handler", SERVER_PREFIX + called[i], calledHandlers.get(i));
}
}
use of fromwsdl.handler.common.HandlerTracker in project metro-jax-ws by eclipse-ee4j.
the class SimpleHelloTester method testHello.
/*
* Simple end to end test (mostly for debug work)
*/
public void testHello() throws Exception {
HandlerTracker tracker = HandlerTracker.getClientInstance();
tracker.clearAll();
TestService_Service service = getService();
TestService test = getTestStub(service);
ReportService report = getReportStub(service);
report.clearHandlerTracker();
int foo = -1;
int bar = test.testInt(foo);
assertTrue(foo == bar);
System.out.println("ok");
List<String> closedHandlers = report.getReport(TestConstants.REPORT_CLOSED_HANDLERS);
List<String> handlers = report.getReport(TestConstants.REPORT_CALLED_HANDLERS);
assertNotNull("received null list back from server", handlers);
}
Aggregations