use of jakarta.xml.soap.SOAPFault in project metro-jax-ws by eclipse-ee4j.
the class HandleFaultTest 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 jakarta.xml.soap.SOAPFault in project metro-jax-ws by eclipse-ee4j.
the class TestApp method testHandlerException1.
/**
* Have a handler throw a protocol exception and make sure
* the proper values are in the soap fault. Test for 6353191.
*/
public void testHandlerException1() throws Exception {
// the expected fault code local part
String code = "Sender";
try {
// clear handlers (should be none) and add helper handler
ClientServerTestUtil.clearHandlers((BindingProvider) stub);
ExceptionThrowingHandler handler = new ExceptionThrowingHandler("ProtocolException");
ClientServerTestUtil.addHandlerToBinding(handler, (BindingProvider) stub);
// make the call
try {
stub.echo("have a nice day");
fail("did not receive any exception");
} catch (SOAPFaultException e) {
SOAPFault fault = e.getFault();
String faultCode = fault.getFaultCode();
assertTrue("fault code should end with \"" + code + "\": " + faultCode, faultCode.endsWith(code));
} catch (Exception e) {
fail("did not receive soap fault exception. received " + e.toString());
}
} finally {
// always clear the handlers
ClientServerTestUtil.clearHandlers((BindingProvider) stub);
}
}
use of jakarta.xml.soap.SOAPFault in project metro-jax-ws by eclipse-ee4j.
the class EchoClientTest method test1193.
public void test1193() throws Exception {
try {
SOAPMessage response = invoke12(createDispatchWithWSDLWithoutAddressing(), MESSAGES.getReplyToRefpsEchoMessage(), S12_NS, getAddress(), ECHO_IN_ACTION, "test1193");
fail("SOAPFaultException must be thrown");
} catch (SOAPFaultException e) {
assertNotNull(e.getFault());
SOAPFault f = e.getFault();
assertEquals(new QName("http://schemas.xmlsoap.org/soap/envelope/", "VersionMismatch"), f.getFaultCodeAsQName());
}
}
use of jakarta.xml.soap.SOAPFault in project metro-jax-ws by eclipse-ee4j.
the class AllResponsesTest method testNonAnonymousFaultTo2.
/**
* Fault response case
* @throws Exception
*/
public void testNonAnonymousFaultTo2() throws Exception {
invokeAsync(createDispatchWithoutAddressing(), TestMessages.NON_ANONYMOUS_FAULT_TO_COMPLETE_FAULTY_MESSAGE, S11_NS, nonAnonAddress, action, endpointAddress, "testNonAnonymousReplyTo");
// Lets see we get a response in 60 s
SOAPMessage m = respMsgExchanger.exchange(null, TestMessages.CLIENT_MAX_TIMEOUT, TimeUnit.SECONDS);
// System.out.println("****************************");
// m.writeTo(System.out);
// System.out.println("\n****************************");
SOAPBody sb = m.getSOAPBody();
assertTrue(sb.hasFault());
SOAPFault fault = sb.getFault();
assertEquals(fault.getFaultString(), "Negative numbers can't be added!");
}
use of jakarta.xml.soap.SOAPFault in project metro-jax-ws by eclipse-ee4j.
the class TestEndpoint method createSFE.
private SOAPFaultException createSFE() {
try {
SOAPFactory fac = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPFault sf = fac.createFault("Some error message.", new QName("http://www.w3.org/2003/05/soap-envelope", "Receiver"));
sf.setFaultNode("http://testNode");
return new SOAPFaultException(sf);
} catch (SOAPException e) {
throw new WebServiceException(e);
}
}
Aggregations