use of jakarta.xml.ws.ProtocolException in project metro-jax-ws by eclipse-ee4j.
the class TestApp method testMustUnderstand2.
/*
* MU test here for soap 1.2. Test verifies that the not
* understood headers are returned to the client as
* headers in the response message.
*/
public void testMustUnderstand2() throws Exception {
String next_1_2 = "http://www.w3.org/2003/05/soap-envelope/role/next";
try {
// clear handlers (should be none) and add helper handler
ClientServerTestUtil.clearHandlers((BindingProvider) stub);
MUHelperHandler handler = new MUHelperHandler();
ClientServerTestUtil.addHandlerToBinding(handler, (BindingProvider) stub);
// have the handler add two headers
QName header1 = new QName("urn:mutest", "badheader1");
QName header2 = new QName("urn:mutest", "badheader2");
handler.setMUHeader(header1, next_1_2);
handler.setMUHeader(header2, next_1_2);
List<QName> expectedHeaders = new ArrayList<QName>();
expectedHeaders.add(header1);
expectedHeaders.add(header2);
handler.setExpectedHeaders(expectedHeaders);
// make the call
try {
stub.echo("have a nice day");
fail("did not receive any exception");
} catch (ProtocolException e) {
if (e instanceof SOAPFaultException) {
// pass
} else {
fail("did not receive soap fault, received: " + e.toString());
}
} catch (Exception e) {
fail("did not receive protocol exception. received " + e.toString());
}
} finally {
// always clear the handlers
ClientServerTestUtil.clearHandlers((BindingProvider) stub);
}
}
use of jakarta.xml.ws.ProtocolException in project metro-jax-ws by eclipse-ee4j.
the class SOAPTestHandler method handleMessage.
public boolean handleMessage(SOAPMessageContext smc) {
try {
SOAPMessage message = smc.getMessage();
SOAPBody body = message.getSOAPBody();
SOAPElement paramElement = (SOAPElement) body.getFirstChild().getFirstChild();
int number = Integer.parseInt(paramElement.getValue());
if (number == THROW_RUNTIME_EXCEPTION) {
throw new RuntimeException("EXPECTED EXCEPTION");
} else if (number == THROW_PROTOCOL_EXCEPTION) {
throw new ProtocolException("EXPECTED EXCEPTION");
} else if (number == THROW_SOAPFAULT_EXCEPTION) {
// todo
}
paramElement.setValue(String.valueOf(++number));
} catch (SOAPException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
return true;
}
use of jakarta.xml.ws.ProtocolException in project metro-jax-ws by eclipse-ee4j.
the class HandleFaultTester method testClientReturnFalse1.
/*
* Have one of the client handlers throw a protocol exception
* and another handler return false during the handleFault
* method. Handler 5 throws protocol, handler 1 returns
* false.
*/
public void testClientReturnFalse1() 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 + 1, HF_RETURN_FALSE);
tracker.setHandlerAction(CLIENT_PREFIX + 5, HA_THROW_PROTOCOL_EXCEPTION_OUTBOUND);
try {
testStub.testInt(42);
fail("did not receive an exception");
} catch (ProtocolException pe) {
// ok
} catch (Exception oops) {
fail("did not receive WebServiceException. received: " + oops);
}
// check called handlers
String[] called = { "0", "1", "3", "4", "5", "4_FAULT", "3_FAULT", "1_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();
assertEquals("should be no handlers destroyed", 0, destroyedHandlers.size());
}
use of jakarta.xml.ws.ProtocolException in project metro-jax-ws by eclipse-ee4j.
the class HandleFaultTester method testClientException3.
/*
* Same as testClientException21 except that a
* test-specific protocol exception is used, and
* the test checks to make sure the exact exception
* is wrapped in the web service exception.
* ProtocolExceptions are not rewrapped in WebServiceException
*/
public void testClientException3() 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_TEST_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("did not receive proper cause of exception. should " + "be TestProtocolException, not " + pe.getClass().toString(), pe instanceof TestProtocolException);
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 jakarta.xml.ws.ProtocolException in project metro-jax-ws by eclipse-ee4j.
the class EndToEndErrorTester method testClientInboundProtocolException1.
/*
* 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 soap handler.
*/
public void testClientInboundProtocolException1() throws Exception {
int badHandler = 5;
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 };
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