use of jakarta.xml.ws.ProtocolException in project metro-jax-ws by eclipse-ee4j.
the class EndToEndErrorTester method testServerOutboundSOAPFault1.
/*
* Have one of the server handlers throw a soap protocol
* exception and check that the proper methods are called.
*/
public void testServerOutboundSOAPFault1() 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_SOAP_FAULT_EXCEPTION_OUTBOUND);
// clear out the client handlers afterwards and set instructions
tracker.clearAll();
for (int i = 0; i < numTotalHandlers; i++) {
tracker.setHandlerAction(CLIENT_PREFIX + i, HA_REGISTER_HANDLE_XYZ);
}
try {
testStub.testInt(3);
fail("did not receive exception");
} catch (ProtocolException e) {
// ok
}
// check result
List<String> clientCalledHandlers = tracker.getCalledHandlers();
List<String> clientClosedHandlers = tracker.getClosedHandlers();
// check client handlers
String[] clientCalled = { "0", "1", "3", "4", "5", "7", "7_FAULT", "5_FAULT", "4_FAULT", "3_FAULT", "1_FAULT", "0_FAULT" };
int[] clientClosed = { 7, 5, 4, 3, 1, 0 };
assertEquals("Did not get proper number of called handlers", clientCalled.length, clientCalledHandlers.size());
for (int i = 0; i < clientCalled.length; i++) {
assertEquals("did not find expected handler", CLIENT_PREFIX + clientCalled[i], clientCalledHandlers.get(i));
}
assertEquals("Did not get proper number of closed handlers", clientClosed.length, clientClosedHandlers.size());
for (int i = 0; i < clientClosed.length; i++) {
assertEquals("did not find expected handler", CLIENT_PREFIX + clientClosed[i], clientClosedHandlers.get(i));
}
// check server after client because it makes calls through the handlers
String[] serverCalled = { "4", "2", "1", "0", "0", "1", "2" };
List<String> serverCalledHandlers = reportStub.getReport(REPORT_CALLED_HANDLERS);
assertEquals("Did not get proper number of called handlers", serverCalled.length, serverCalledHandlers.size());
for (int i = 0; i < serverCalled.length; i++) {
assertEquals("did not find expected handler", SERVER_PREFIX + serverCalled[i], serverCalledHandlers.get(i));
}
// too many closes on server to check them all
// should be no destroyed handlers
List<String> destroyedHandlers = reportStub.getReport(REPORT_DESTROYED_HANDLERS);
assertEquals("Should be 0 destroyed handlers", 0, destroyedHandlers.size());
}
use of jakarta.xml.ws.ProtocolException in project metro-jax-ws by eclipse-ee4j.
the class SOAPFaultBuilder method createException.
/**
* This should be called from the client side to throw an {@link Exception} for a given soap mesage
*/
public Throwable createException(Map<QName, CheckedExceptionImpl> exceptions) throws JAXBException {
DetailType dt = getDetail();
Node detail = null;
if (dt != null)
detail = dt.getDetail(0);
// return ProtocolException if the detail is not present or there is no checked exception
if (detail == null || exceptions == null) {
// throw a protocol exception
return attachServerException(getProtocolException());
}
// check if the detail is a checked exception, if not throw a ProtocolException
QName detailName = new QName(detail.getNamespaceURI(), detail.getLocalName());
CheckedExceptionImpl ce = exceptions.get(detailName);
if (ce == null) {
// No Checked exception for the received detail QName, throw a SOAPFault exception
return attachServerException(getProtocolException());
}
if (ce.getExceptionType().equals(ExceptionType.UserDefined)) {
return attachServerException(createUserDefinedException(ce));
}
Class exceptionClass = ce.getExceptionClass();
try {
Constructor constructor = exceptionClass.getConstructor(String.class, (Class) ce.getDetailType().type);
Exception exception = (Exception) constructor.newInstance(getFaultString(), getJAXBObject(detail, ce));
return attachServerException(exception);
} catch (Exception e) {
throw new WebServiceException(e);
}
}
use of jakarta.xml.ws.ProtocolException in project metro-jax-ws by eclipse-ee4j.
the class HandleFaultTester method testClientFaultAndProtocolException1.
/*
* Have one of the client handlers insert a fault message
* with fault string msg1 and throw a protocol
* exception with message msg2. Another handler should
* get a message in the handleFault method containing
* a fault with the msg1 fault string.
*
* This tests that the runtime doesn't replace a fault if
* one is already there.
*
* Also checks exception received to make sure the right
* message is there. Check for bug 6232841.
*/
public void testClientFaultAndProtocolException1() 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.setHandlerAction(CLIENT_PREFIX + 7, HA_INSERT_FAULT_AND_THROW_PE_OUTBOUND);
tracker.setHandleFaultAction(CLIENT_PREFIX + 4, HF_CHECK_FAULT_MESSAGE_STRING);
try {
testStub.testInt(42);
fail("did not receive an exception");
} catch (ProtocolException e) {
assertTrue("did not get correct message", e.getMessage().contains(MESSAGE_IN_FAULT));
} catch (Exception oops) {
fail("did not receive WebServiceException. received: " + oops);
}
// check called handlers
String[] called = { "0", "1", "3", "4", "5", "7", "5_FAULT", "4_FAULT", "3_FAULT", "1_FAULT", "0_FAULT" };
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
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 testClientException1.
/*
* Have one of the client handlers throw a protocol exception
* and another handler throw a new exception during the
* handleFault method. Handler 5 throws protocol, handler 4
* throws new exception. Should receive the new exception and
* have proper handlers called.
*
* The new exception will be wrapped by the client runtime
* in a web service exception.
*/
public void testClientException1() 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_RUNTIME_EXCEPTION);
tracker.setHandlerAction(CLIENT_PREFIX + 5, HA_THROW_PROTOCOL_EXCEPTION_OUTBOUND);
try {
testStub.testInt(42);
fail("did not receive any exception");
} catch (ProtocolException pe) {
fail("should not have received original (protocol) exception");
} catch (WebServiceException wse) {
Throwable t = wse.getCause();
assertNotNull("did not receive cause of exception", t);
assertTrue("did not receive proper cause of exception", t instanceof RuntimeException);
String msg = t.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);
}
// 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 only no handlers destroyed", destroyedHandlers.isEmpty());
}
use of jakarta.xml.ws.ProtocolException 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());
}
Aggregations