use of jakarta.xml.ws.soap.SOAPFaultException in project metro-jax-ws by eclipse-ee4j.
the class EndToEndErrorTest method testServerInboundSoapFaultException1.
/*
* Have one of the server handlers throw a soap fault
* exception and check that the proper methods are called.
*/
public void testServerInboundSoapFaultException1() 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_INBOUND);
// so we clear out the client handlers afterwards
tracker.clearAll();
try {
testStub.testInt(3);
fail("did not receive any exception");
} catch (SOAPFaultException e) {
// check some details
SOAPFault fault = e.getFault();
assertEquals("did not get proper fault actor", "faultActor", fault.getFaultActor());
assertEquals("did not get proper fault string", "fault", fault.getFaultString());
assertEquals("did not get proper fault code", new QName("uri", "local", "prefix"), fault.getFaultCodeAsQName());
}
// check result
String[] called = { "4", "2", "4_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));
}
// should be no destroyed handlers
List<String> destroyedHandlers = reportStub.getReport(REPORT_DESTROYED_HANDLERS);
assertTrue("Should be 0 destroyed handlers", destroyedHandlers.isEmpty());
}
use of jakarta.xml.ws.soap.SOAPFaultException in project metro-jax-ws by eclipse-ee4j.
the class HandleFaultTest method testServerException1.
/*
* Have one of the server handlers throw a protocol exception
* and another handler throw a different exception during the
* handleFault method. Handler 2 throws first exception, then
* handler 4. Should receive the new exception.
*/
public void testServerException1() throws Exception {
TestService_Service service = getService();
TestService testStub = getTestStub(service);
ReportService reportStub = getReportStub(service);
HandlerTracker tracker = HandlerTracker.getClientInstance();
reportStub.clearHandlerTracker();
// tell the server handlers to register themselves
for (int i = 0; i < numTotalServerHandlers; i++) {
reportStub.setInstruction(SERVER_PREFIX + i, HA_REGISTER_HANDLE_XYZ);
}
// this handler will register being called before throwing PE
reportStub.setInstruction(SERVER_PREFIX + 2, HA_THROW_PROTOCOL_EXCEPTION_INBOUND);
// the HF_ action does not override the HA_ action
reportStub.setInstruction(SERVER_PREFIX + 4, HF_THROW_RUNTIME_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 + 4));
}
// check called handlers on server side
String[] called = { "4", "2", "4_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 jakarta.xml.ws.soap.SOAPFaultException in project metro-jax-ws by eclipse-ee4j.
the class AddNumbersTest method testClientValidationFailure.
public void testClientValidationFailure() {
SchemaValidationFeature feature = new SchemaValidationFeature();
AddNumbersPortType port = service.getAddNumbersPort(feature);
// more than 4 digits, so doesn't pass validation
int number1 = 10001;
int number2 = 20;
try {
port.addNumbers(number1, number2);
fail("Client Schema Validation didn't work");
} catch (SOAPFaultException se) {
fail("Client Schema Validation didn't work");
} catch (WebServiceException se) {
// Expected exception - Client side validation failed as expected
}
}
use of jakarta.xml.ws.soap.SOAPFaultException in project metro-jax-ws by eclipse-ee4j.
the class HandlerClientTest method testServerRtException2.
public void testServerRtException2() throws Exception {
HandlerTracker tracker = HandlerTracker.getClientInstance();
tracker.clearAll();
Hello12 stub = create12Stub();
ReportService report = createReportStub();
report.clearHandlerTracker();
try {
int bar = stub.hello12(handler.single_handlertube.common.TestConstants.SERVER_THROW_RUNTIME_EXCEPTION);
assert (false);
} catch (SOAPFaultException e) {
// as expected.
System.out.println("ok");
}
List<String> expClientCalled = Arrays.asList(new String[] { "client2", "client2_FAULT" });
List<String> gotClientCalled = tracker.getCalledHandlers();
Assert.assertTrue(handler.single_handlertube.common.TestConstants.ERR_CLIENT_CALLED_HANDLERS, checkEqual(expClientCalled, gotClientCalled));
List<String> expServerCalled = Arrays.asList(new String[] { "server1", "server1_FAULT" });
List<String> gotServerCalled = report.getReport(handler.single_handlertube.common.TestConstants.REPORT_CALLED_HANDLERS);
Assert.assertTrue(handler.single_handlertube.common.TestConstants.ERR_SERVER_CALLED_HANDLERS, checkEqual(expServerCalled, gotServerCalled));
List<String> expClientClosed = Arrays.asList(new String[] { "client2" });
List<String> gotClientClosed = tracker.getClosedHandlers();
Assert.assertTrue(handler.single_handlertube.common.TestConstants.ERR_CLIENT_CLOSED_HANDLERS, checkEqual(expClientClosed, gotClientClosed));
List<String> expServerClosed = Arrays.asList(new String[] { "server1" });
List<String> gotServerClosed = report.getReport(handler.single_handlertube.common.TestConstants.REPORT_CLOSED_HANDLERS);
Assert.assertTrue(handler.single_handlertube.common.TestConstants.ERR_SERVER_CLOSED_HANDLERS, checkEqual(expServerClosed, gotServerClosed));
}
use of jakarta.xml.ws.soap.SOAPFaultException in project metro-jax-ws by eclipse-ee4j.
the class HandlerClientTest method testServerRtException1.
public void testServerRtException1() throws Exception {
HandlerTracker tracker = HandlerTracker.getClientInstance();
tracker.clearAll();
Hello stub = createStub();
ReportService report = createReportStub();
report.clearHandlerTracker();
try {
int bar = stub.hello(handler.single_handlertube.common.TestConstants.SERVER_THROW_RUNTIME_EXCEPTION);
assert (false);
} catch (SOAPFaultException e) {
// as expected.
System.out.println("ok");
}
List<String> expClientCalled = Arrays.asList(new String[] { "client1", "client1_FAULT" });
List<String> gotClientCalled = tracker.getCalledHandlers();
Assert.assertTrue(handler.single_handlertube.common.TestConstants.ERR_CLIENT_CALLED_HANDLERS, checkEqual(expClientCalled, gotClientCalled));
List<String> expServerCalled = Arrays.asList(new String[] { "server2", "server2_FAULT" });
List<String> gotServerCalled = report.getReport(handler.single_handlertube.common.TestConstants.REPORT_CALLED_HANDLERS);
Assert.assertTrue(handler.single_handlertube.common.TestConstants.ERR_SERVER_CALLED_HANDLERS, checkEqual(expServerCalled, gotServerCalled));
List<String> expClientClosed = Arrays.asList(new String[] { "client1" });
List<String> gotClientClosed = tracker.getClosedHandlers();
Assert.assertTrue(handler.single_handlertube.common.TestConstants.ERR_CLIENT_CLOSED_HANDLERS, checkEqual(expClientClosed, gotClientClosed));
List<String> expServerClosed = Arrays.asList(new String[] { "server2" });
List<String> gotServerClosed = report.getReport(handler.single_handlertube.common.TestConstants.REPORT_CLOSED_HANDLERS);
Assert.assertTrue(handler.single_handlertube.common.TestConstants.ERR_SERVER_CLOSED_HANDLERS, checkEqual(expServerClosed, gotServerClosed));
}
Aggregations