Search in sources :

Example 6 with SOAPFault

use of jakarta.xml.soap.SOAPFault in project metro-jax-ws by eclipse-ee4j.

the class WsaTestImpl method createSOAPFault.

SOAPFault createSOAPFault(String message) {
    try {
        SOAPFault fault = SOAPVersion.SOAP_12.saajSoapFactory.createFault();
        fault.setFaultString(message);
        fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
        fault.appendFaultSubcode(new QName("http://example.org/echo", "EmptyEchoString"));
        return fault;
    } catch (SOAPException ex) {
        throw new WebServiceException(ex);
    }
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) SOAPException(jakarta.xml.soap.SOAPException) SOAPFault(jakarta.xml.soap.SOAPFault)

Example 7 with SOAPFault

use of jakarta.xml.soap.SOAPFault in project metro-jax-ws by eclipse-ee4j.

the class AddNumbersClient method testCustomFault.

/**
 * This test tests the functionality of OnewayFeature and AddressingFeature the way it being used in WS-AT implementation
 * In WS-AT impl, Server-side has to send fault messages to predefined coordinator and this test replicates that usage.
 *
 * @throws Exception
 */
public void testCustomFault() throws Exception {
    if (ClientServerTestUtil.useLocal()) {
        System.out.println("Only Testable in HTTP transport!");
        return;
    }
    SOAPFault fault = SOAPFactory.newInstance().createFault("custom fault from client", SOAPConstants.SOAP_SENDER_FAULT);
    InputStream is = getClass().getClassLoader().getResourceAsStream("wsa/fromwsdl/custom/config/AddNumbers.wsdl");
    assertNotNull("WSDL cannot be read", is);
    ArrayList<Element> metadata = new ArrayList<Element>();
    metadata.add((Element) DOMUtil.createDOMNode(is).getFirstChild());
    // WSEndpointReference to = new WSEndpointReference(AddressingVersion.W3C,
    // getAddress(),
    // SERVICE_QNAME,
    // PORT_QNAME,
    // PORT_TYPE_QNAME,
    // metadata,
    // getWsdlAddress(),
    // null);
    OneWayFeature owf = new OneWayFeature();
    owf.setRelatesToID("uuid:foobar");
    Service service = Service.create(SERVICE_QNAME);
    service.addPort(PORT_QNAME, SOAPBinding.SOAP11HTTP_BINDING, getAddress());
    // Dispatch<Source> dispatch = service.createDispatch(to.toSpec(), Source.class,
    // Service.Mode.PAYLOAD,
    // new AddressingFeature(true, true),
    // owf);
    Dispatch<Source> dispatch = service.createDispatch(PORT_QNAME, Source.class, Service.Mode.PAYLOAD, new MemberSubmissionAddressingFeature(true), owf);
    // Since this fault is not a wsdl operation, we need to set SOAPAction for correct wsa:Action
    dispatch.getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, true);
    dispatch.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, "http://example.com/myfault");
    try {
        dispatch.invokeOneWay(new DOMSource(fault));
    } catch (WebServiceException e) {
    // since the server-side is not provider based for this test.
    // it does n't know from the fault message request that it is oneway and throws 500 code.
    // so, expect a WebServcieException here.
    }
// System.out.println(dispatch.getRequestContext().get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY));
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) InputStream(java.io.InputStream) OneWayFeature(com.sun.xml.ws.api.addressing.OneWayFeature) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) WSService(com.sun.xml.ws.api.WSService) SOAPFault(jakarta.xml.soap.SOAPFault) MemberSubmissionAddressingFeature(com.sun.xml.ws.developer.MemberSubmissionAddressingFeature) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source)

Example 8 with SOAPFault

use of jakarta.xml.soap.SOAPFault in project metro-jax-ws by eclipse-ee4j.

the class EndToEndErrorTest method testServerInboundProtocolException1.

/*
     * Have one of the server handlers throw a simple protocol
     * exception and check that the proper methods are called.
     *
     * This test checks the fault code as well -- related to
     * bug 6350633.
     */
public void testServerInboundProtocolException1() throws Exception {
    // the expected fault code local part
    String server = "Server";
    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_INBOUND);
    // so we clear out the client handlers afterwards
    tracker.clearAll();
    try {
        testStub.testInt(3);
        fail("did not receive exception");
    } catch (SOAPFaultException e) {
        SOAPFault fault = e.getFault();
        String faultCode = fault.getFaultCode();
        assertTrue("fault code should end with \"" + server + "\": " + faultCode, faultCode.endsWith(server));
    }
    // 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));
    }
    // too many closes 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());
}
Also used : HandlerTracker(handler.handler_processing.common.HandlerTracker) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) SOAPFault(jakarta.xml.soap.SOAPFault)

Example 9 with SOAPFault

use of jakarta.xml.soap.SOAPFault 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());
}
Also used : HandlerTracker(handler.handler_processing.common.HandlerTracker) QName(javax.xml.namespace.QName) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) SOAPFault(jakarta.xml.soap.SOAPFault)

Example 10 with SOAPFault

use of jakarta.xml.soap.SOAPFault 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));
    }
}
Also used : HandlerTracker(handler.handler_processing.common.HandlerTracker) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) SOAPFault(jakarta.xml.soap.SOAPFault)

Aggregations

SOAPFault (jakarta.xml.soap.SOAPFault)45 SOAPFaultException (jakarta.xml.ws.soap.SOAPFaultException)21 QName (javax.xml.namespace.QName)16 SOAPException (jakarta.xml.soap.SOAPException)12 WebServiceException (jakarta.xml.ws.WebServiceException)11 SOAPMessage (jakarta.xml.soap.SOAPMessage)9 HandlerTracker (fromwsdl.handler.common.HandlerTracker)8 HandlerTracker (handler.handler_processing.common.HandlerTracker)8 Detail (jakarta.xml.soap.Detail)7 Message (com.sun.xml.ws.api.message.Message)5 SOAPBody (jakarta.xml.soap.SOAPBody)5 SOAPFactory (jakarta.xml.soap.SOAPFactory)5 Element (org.w3c.dom.Element)5 SOAPElement (jakarta.xml.soap.SOAPElement)3 InvalidAddressingHeaderException (com.sun.xml.ws.addressing.model.InvalidAddressingHeaderException)2 WSService (com.sun.xml.ws.api.WSService)2 OneWayFeature (com.sun.xml.ws.api.addressing.OneWayFeature)2 MemberSubmissionAddressingFeature (com.sun.xml.ws.developer.MemberSubmissionAddressingFeature)2 FaultDetailHeader (com.sun.xml.ws.message.FaultDetailHeader)2 Iterator (java.util.Iterator)2