Search in sources :

Example 21 with SOAPFault

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

the class EndToEndErrorTester method testClientOutboundProtocolException1.

/*
     * Have one of the client handlers throw a protocol exception
     * and check that the proper methods are called. This test
     * is on outbound message with 2.0 handler (so handleFault
     * should not be called on the handler that throws the
     * exception). Testing with soap handler.
     *
     * Exception should result in a fault in the message, which
     * is dispatched to and wrapped by the client.
     *
     * This test checks the fault code as well -- test for
     * bug 6350633.
     */
public void testClientOutboundProtocolException1() throws Exception {
    // the expected fault code local part
    String client = "Client";
    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 + 5, HA_THROW_PROTOCOL_EXCEPTION_OUTBOUND);
    try {
        testStub.testInt(42);
        fail("did not receive an exception");
    } catch (SOAPFaultException e) {
        SOAPFault fault = e.getFault();
        String faultCode = fault.getFaultCode();
        assertTrue("fault code should end with \"" + client + "\": " + faultCode, faultCode.endsWith(client));
    }
    // check result
    String[] called = { "0", "1", "3", "4", "5", "4_FAULT", "3_FAULT", "1_FAULT", "0_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));
    }
    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));
    }
    // should be no destroyed handlers
    List<String> destroyedHandlers = tracker.getDestroyedHandlers();
    assertTrue("Should be 0 destroyed handlers", destroyedHandlers.isEmpty());
}
Also used : HandlerTracker(fromwsdl.handler.common.HandlerTracker) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) SOAPFault(jakarta.xml.soap.SOAPFault)

Example 22 with SOAPFault

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

the class EndToEndErrorTester 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(fromwsdl.handler.common.HandlerTracker) QName(javax.xml.namespace.QName) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) SOAPFault(jakarta.xml.soap.SOAPFault)

Example 23 with SOAPFault

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

the class EndToEndErrorTester 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(fromwsdl.handler.common.HandlerTracker) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) SOAPFault(jakarta.xml.soap.SOAPFault)

Example 24 with SOAPFault

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

the class WsaServerTube method processRequest.

@Override
@NotNull
public NextAction processRequest(Packet request) {
    Message msg = request.getMessage();
    if (msg == null) {
        return doInvoke(next, request);
    }
    // hmm?
    // expose bunch of addressing related properties for advanced applications
    request.addSatellite(new WsaPropertyBag(addressingVersion, soapVersion, request));
    // Store request ReplyTo and FaultTo in requestPacket.invocationProperties
    // so that they can be used after responsePacket is received.
    // These properties are used if a fault is thrown from the subsequent Pipe/Tubes.
    MessageHeaders hl = request.getMessage().getHeaders();
    String msgId;
    try {
        replyTo = AddressingUtils.getReplyTo(hl, addressingVersion, soapVersion);
        faultTo = AddressingUtils.getFaultTo(hl, addressingVersion, soapVersion);
        msgId = AddressingUtils.getMessageID(hl, addressingVersion, soapVersion);
    } catch (InvalidAddressingHeaderException e) {
        LOGGER.log(Level.WARNING, addressingVersion.getInvalidMapText() + ", Problem header:" + e.getProblemHeader() + ", Reason: " + e.getSubsubcode(), e);
        // problematic header must be removed since it can fail during Fault message processing
        hl.remove(e.getProblemHeader());
        SOAPFault soapFault = helper.createInvalidAddressingHeaderFault(e, addressingVersion);
        // WS-A fault processing for one-way methods
        if ((wsdlPort != null) && request.getMessage().isOneWay(wsdlPort)) {
            Packet response = request.createServerResponse(null, wsdlPort, null, binding);
            return doReturnWith(response);
        }
        Message m = Messages.create(soapFault);
        if (soapVersion == SOAPVersion.SOAP_11) {
            FaultDetailHeader s11FaultDetailHeader = new FaultDetailHeader(addressingVersion, addressingVersion.problemHeaderQNameTag.getLocalPart(), e.getProblemHeader());
            m.getHeaders().add(s11FaultDetailHeader);
        }
        Packet response = request.createServerResponse(m, wsdlPort, null, binding);
        return doReturnWith(response);
    }
    // defaulting
    if (replyTo == null) {
        replyTo = addressingVersion.anonymousEpr;
    }
    if (faultTo == null) {
        faultTo = replyTo;
    }
    // Save a copy into the packet such that we can save it with that
    // packet if we're going to deliver the response at a later time
    // (async from the request).
    request.put(WsaPropertyBag.WSA_REPLYTO_FROM_REQUEST, replyTo);
    request.put(WsaPropertyBag.WSA_FAULTTO_FROM_REQUEST, faultTo);
    request.put(WsaPropertyBag.WSA_MSGID_FROM_REQUEST, msgId);
    wbo = getWSDLBoundOperation(request);
    isAnonymousRequired = isAnonymousRequired(wbo);
    Packet p = validateInboundHeaders(request);
    // then do no further processing
    if (p.getMessage() == null) {
        return doReturnWith(p);
    }
    // if we find an error in addressing header, just turn around the direction here
    if (p.getMessage().isFault()) {
        // we'll never use them
        if (isEarlyBackchannelCloseAllowed && !(isAnonymousRequired) && !faultTo.isAnonymous() && request.transportBackChannel != null) {
            request.transportBackChannel.close();
        }
        return processResponse(p);
    }
    // we'll never use them
    if (isEarlyBackchannelCloseAllowed && !(isAnonymousRequired) && !replyTo.isAnonymous() && !faultTo.isAnonymous() && request.transportBackChannel != null) {
        request.transportBackChannel.close();
    }
    return doInvoke(next, p);
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) InvalidAddressingHeaderException(com.sun.xml.ws.addressing.model.InvalidAddressingHeaderException) Message(com.sun.xml.ws.api.message.Message) FaultDetailHeader(com.sun.xml.ws.message.FaultDetailHeader) SOAPFault(jakarta.xml.soap.SOAPFault) MessageHeaders(com.sun.xml.ws.api.message.MessageHeaders) NotNull(com.sun.istack.NotNull)

Example 25 with SOAPFault

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

the class WsaTube method validateInboundHeaders.

/**
 * Validates the inbound message. If an error is found, create
 * a fault message and returns that. Otherwise
 * it will pass through the parameter 'packet' object to the return value.
 */
protected Packet validateInboundHeaders(Packet packet) {
    SOAPFault soapFault;
    FaultDetailHeader s11FaultDetailHeader;
    try {
        checkMessageAddressingProperties(packet);
        return packet;
    } catch (InvalidAddressingHeaderException e) {
        LOGGER.log(Level.WARNING, addressingVersion.getInvalidMapText() + ", Problem header:" + e.getProblemHeader() + ", Reason: " + e.getSubsubcode(), e);
        soapFault = helper.createInvalidAddressingHeaderFault(e, addressingVersion);
        s11FaultDetailHeader = new FaultDetailHeader(addressingVersion, addressingVersion.problemHeaderQNameTag.getLocalPart(), e.getProblemHeader());
    } catch (MissingAddressingHeaderException e) {
        LOGGER.log(Level.WARNING, addressingVersion.getMapRequiredText() + ", Problem header:" + e.getMissingHeaderQName(), e);
        soapFault = helper.newMapRequiredFault(e);
        s11FaultDetailHeader = new FaultDetailHeader(addressingVersion, addressingVersion.problemHeaderQNameTag.getLocalPart(), e.getMissingHeaderQName());
    }
    if (soapFault != null) {
        // WS-A fault processing for one-way methods
        if ((wsdlPort != null) && packet.getMessage().isOneWay(wsdlPort)) {
            return packet.createServerResponse(null, wsdlPort, null, binding);
        }
        Message m = Messages.create(soapFault);
        if (soapVersion == SOAPVersion.SOAP_11) {
            m.getHeaders().add(s11FaultDetailHeader);
        }
        return packet.createServerResponse(m, wsdlPort, null, binding);
    }
    return packet;
}
Also used : InvalidAddressingHeaderException(com.sun.xml.ws.addressing.model.InvalidAddressingHeaderException) MissingAddressingHeaderException(com.sun.xml.ws.addressing.model.MissingAddressingHeaderException) Message(com.sun.xml.ws.api.message.Message) FaultDetailHeader(com.sun.xml.ws.message.FaultDetailHeader) 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