use of jakarta.xml.ws.ProtocolException in project metro-jax-ws by eclipse-ee4j.
the class TestHandler method incrementArgument.
private Source incrementArgument(Source source) throws TransformerException {
Transformer xFormer = TransformerFactory.newInstance().newTransformer();
xFormer.setOutputProperty("omit-xml-declaration", "yes");
DOMResult dResult = new DOMResult();
xFormer.transform(source, dResult);
Node documentNode = dResult.getNode();
Node envelopeNode = documentNode.getFirstChild();
Node requestResponseNode = envelopeNode.getLastChild().getFirstChild();
Node textNode = requestResponseNode.getFirstChild().getFirstChild();
int orig = Integer.parseInt(textNode.getNodeValue());
// check for error tests
if (orig == THROW_HTTP_EXCEPTION) {
throw new HTTPException(500);
} else if (orig == THROW_RUNTIME_EXCEPTION) {
throw new RuntimeException("EXPECTED EXCEPTION");
} else if (orig == THROW_PROTOCOL_EXCEPTION) {
throw new ProtocolException("TEST EXCEPTION FROM HANDLER");
}
textNode.setNodeValue(String.valueOf(++orig));
return new DOMSource(documentNode);
}
use of jakarta.xml.ws.ProtocolException in project metro-jax-ws by eclipse-ee4j.
the class EndToEndErrorTester method testServerInboundRuntimeException2.
/*
* Have one of the server handlers throw a runtime
* exception and check that the proper methods are called.
* This test uses a protocol handler.
*/
public void testServerInboundRuntimeException2() throws Exception {
TestService_Service service = getService();
TestService testStub = getTestStub(service);
ReportService reportStub = getReportStub(service);
HandlerTracker tracker = HandlerTracker.getClientInstance();
// these lines make calls to the server
reportStub.clearHandlerTracker();
for (int i = 0; i < numTotalHandlers; i++) {
reportStub.setInstruction(SERVER_PREFIX + i, HA_REGISTER_HANDLE_XYZ);
}
reportStub.setInstruction(SERVER_PREFIX + 2, HA_THROW_RUNTIME_EXCEPTION_INBOUND);
// so we clear out the client handlers afterwards
tracker.clearAll();
try {
testStub.testInt(3);
fail("did not receive exception");
} catch (ProtocolException e) {
// ok
}
// check result
String[] called = { "4", "2" };
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));
}
// should be no destroyed handlers
List<String> destroyedHandlers = reportStub.getReport(REPORT_DESTROYED_HANDLERS);
assertTrue("Should be no destroyed handlers", destroyedHandlers.isEmpty());
}
use of jakarta.xml.ws.ProtocolException in project metro-jax-ws by eclipse-ee4j.
the class EndToEndErrorTester method testServerInboundRuntimeException1.
/*
* Have one of the server handlers throw a runtime
* exception and check that the proper methods are called.
* This test uses a logical handler.
*/
public void testServerInboundRuntimeException1() throws Exception {
TestService_Service service = getService();
TestService testStub = getTestStub(service);
ReportService reportStub = getReportStub(service);
HandlerTracker tracker = HandlerTracker.getClientInstance();
// these lines make calls to the server
reportStub.clearHandlerTracker();
for (int i = 0; i < numTotalHandlers; i++) {
reportStub.setInstruction(SERVER_PREFIX + i, HA_REGISTER_HANDLE_XYZ);
}
reportStub.setInstruction(SERVER_PREFIX + 1, HA_THROW_RUNTIME_EXCEPTION_INBOUND);
// so we clear out the client handlers afterwards
tracker.clearAll();
try {
testStub.testInt(3);
fail("did not receive exception");
} catch (ProtocolException e) {
// pass
}
// check result
String[] called = { "4", "2", "1" };
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));
}
// should be no destroyed handlers
List<String> destroyedHandlers = reportStub.getReport(REPORT_DESTROYED_HANDLERS);
assertTrue("Should be no destroyed handlers", destroyedHandlers.isEmpty());
}
use of jakarta.xml.ws.ProtocolException in project metro-jax-ws by eclipse-ee4j.
the class EndToEndErrorTester method testServerOutboundProtocolException1.
/*
* Have one of the server handlers throw a simple protocol
* exception and check that the proper methods are called.
*/
public void testServerOutboundProtocolException1() throws Exception {
TestService_Service service = getService();
TestService testStub = getTestStub(service);
ReportService reportStub = getReportStub(service);
HandlerTracker tracker = HandlerTracker.getClientInstance();
// these lines make calls to the server
reportStub.clearHandlerTracker();
for (int i = 0; i < numTotalHandlers; i++) {
reportStub.setInstruction(SERVER_PREFIX + i, HA_REGISTER_HANDLE_XYZ);
}
reportStub.setInstruction(SERVER_PREFIX + 2, HA_THROW_PROTOCOL_EXCEPTION_OUTBOUND);
// so we clear out the client handlers afterwards
tracker.clearAll();
try {
testStub.testInt(3);
fail("did not receive exception");
} catch (ProtocolException e) {
// ok
}
// check result
String[] called = { "4", "2", "1", "0", "0", "1", "2" };
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));
}
// too many closes to check them all
// should be no destroyed handlers
List<String> destroyedHandlers = reportStub.getReport(REPORT_DESTROYED_HANDLERS);
assertTrue("Should be no destroyed handlers", destroyedHandlers.isEmpty());
}
use of jakarta.xml.ws.ProtocolException in project metro-jax-ws by eclipse-ee4j.
the class EndToEndErrorTester method testClientInboundProtocolException2.
/*
* Have one of the client handlers throw a proper exception
* and check that the proper methods are called. This test
* is on inbound message. Testing with logical handler.
*
* Is this a valid test case?
*/
public void testClientInboundProtocolException2() throws Exception {
int badHandler = 1;
TestService_Service service = getService();
TestService testStub = getTestStub(service);
ReportService reportStub = getReportStub(service);
HandlerTracker tracker = HandlerTracker.getClientInstance();
reportStub.clearHandlerTracker();
tracker.clearAll();
for (int i = 0; i < numTotalHandlers; i++) {
tracker.setHandlerAction(CLIENT_PREFIX + i, HA_REGISTER_HANDLE_XYZ);
}
tracker.setHandlerAction(CLIENT_PREFIX + badHandler, HA_THROW_PROTOCOL_EXCEPTION_INBOUND);
try {
testStub.testInt(42);
fail("should have received a web service exception");
} catch (ProtocolException e) {
assertTrue("ProtocolException message not as expected, but got:" + e.getMessage(), e.getMessage().contains(CLIENT_PREFIX + badHandler));
}
// check called handlers
int[] called = { 0, 1, 3, 4, 5, 7, 7, 5, 4, 3, 1 };
int[] closed = { 7, 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 -- none in jaxws 2.0
List<String> destroyedHandlers = tracker.getDestroyedHandlers();
assertTrue("destroyed handler list should be empty", destroyedHandlers.isEmpty());
}
Aggregations