Search in sources :

Example 1 with ProtocolException

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

the class TieHandler method createResponse.

public Message createResponse(JavaCallInfo call) {
    Message responseMessage;
    if (call.getException() == null) {
        responseMessage = isOneWay ? null : createResponseMessage(call.getParameters(), call.getReturnValue());
    } else {
        Throwable e = call.getException();
        Throwable serviceException = getServiceException(e);
        if (e instanceof InvocationTargetException || serviceException != null) {
            // if (!(cause instanceof RuntimeException) && cause instanceof Exception) {
            if (serviceException != null) {
                // Service specific exception
                LOGGER.log(Level.FINE, serviceException.getMessage(), serviceException);
                responseMessage = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, javaMethodModel.getCheckedException(serviceException.getClass()), serviceException);
            } else {
                Throwable cause = e.getCause();
                if (cause instanceof ProtocolException) {
                    // Application code may be throwing it intentionally
                    LOGGER.log(Level.FINE, cause.getMessage(), cause);
                } else {
                    // Probably some bug in application code
                    LOGGER.log(Level.SEVERE, cause.getMessage(), cause);
                }
                responseMessage = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, cause);
            }
        } else if (e instanceof DispatchException) {
            responseMessage = ((DispatchException) e).fault;
        } else {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
            responseMessage = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, e);
        }
    }
    return responseMessage;
}
Also used : ProtocolException(jakarta.xml.ws.ProtocolException) Message(com.sun.xml.ws.api.message.Message) JAXBMessage(com.sun.xml.ws.message.jaxb.JAXBMessage) DispatchException(com.sun.xml.ws.wsdl.DispatchException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with ProtocolException

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

the class SOAPHandlerProcessor method insertFaultMessage.

/**
 * Replace the message in the given message context with a
 * fault message. If the context already contains a fault
 * message, then return without changing it.
 *
 * <p>This method should only be called during a request,
 * because during a response an exception from a handler
 * is dispatched rather than replacing the message with
 * a fault. So this method can use the MESSAGE_OUTBOUND_PROPERTY
 * to determine whether it is being called on the client
 * or the server side. If this changes in the spec, then
 * something else will need to be passed to the method
 * to determine whether the fault code is client or server.
 */
void insertFaultMessage(C context, ProtocolException exception) {
    try {
        if (!context.getPacketMessage().isFault()) {
            Message faultMessage = Messages.create(binding.getSOAPVersion(), exception, determineFaultCode(binding.getSOAPVersion()));
            context.setPacketMessage(faultMessage);
        }
    } catch (Exception e) {
        // severe since this is from runtime and not handler
        logger.log(Level.SEVERE, "exception while creating fault message in handler chain", e);
        throw new RuntimeException(e);
    }
}
Also used : Message(com.sun.xml.ws.api.message.Message) ProtocolException(jakarta.xml.ws.ProtocolException)

Example 3 with ProtocolException

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

the class FaultImpl method echo.

public java.lang.String echo(java.lang.String type) throws Fault1Exception, Fault2Exception, Fault3Exception, Fault4Exception {
    if (type.equals("Fault1")) {
        FooException fault = new FooException();
        fault.setVarInt(1);
        fault.setVarString("1");
        fault.setVarFloat(1);
        System.out.println("Throwing Fault1Exception");
        throw new Fault1Exception("Fault1 message", fault);
    } else if (type.equals("Fault1-SOAPFaultException")) {
        FooException fault = new FooException();
        fault.setVarInt(1);
        fault.setVarString("1");
        fault.setVarFloat(1);
        System.out.println("Throwing Fault1Exception with Cause");
        throw new Fault1Exception("Fault1 message", fault, createSOAPFaultException());
    } else if (type.equals("Fault2")) {
        String fault = "fault2";
        System.out.println("Throwing Fault2Exception");
        throw new Fault2Exception("Fault2 message", fault);
    } else if (type.equals("Fault3")) {
        Integer fault = Integer.valueOf("1");
        System.out.println("Throwing Fault3Exception");
        throw new Fault3Exception("Fault3 message", fault);
    } else if (type.equals("Fault4")) {
        Fault4 fault = new Fault4();
        fault.setMessage("fault4");
        fault.setCount(1);
        System.out.println("Throwing Fault4Exception");
        throw new Fault4Exception("Fault4 message", fault);
    } else if (type.equals("SOAPFaultException")) {
        throw createSOAPFaultException();
    } else if (type.equals("NullPointerException")) {
        Object o = null;
        o.hashCode();
    } else if (type.equals("ProtocolException")) {
        throw new ProtocolException();
    } else if (type.equals("ProtocolException2")) {
        throw new ProtocolException("FaultImpl");
    } else if (type.equals("multipleDetails")) {
        createSaajBug();
    } else if (type.equals("nullBean")) {
        throw new Fault2Exception(null, null, new WebServiceException("User exception!"));
    } else if (type.equals("echo")) {
        // used in MU test
        return "echo";
    }
    return "Unknown fault: " + type;
}
Also used : ProtocolException(jakarta.xml.ws.ProtocolException) WebServiceException(jakarta.xml.ws.WebServiceException)

Example 4 with ProtocolException

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

the class EndToEndErrorTest method testClientInboundProtocolException2.

/*
     * Have one of the client handlers throw a proper exception
     * and check that the proper methods are called. This test
     * is on inbound message. Testing with logical handler.
     *
     * Is this a valid test case?
     */
public void testClientInboundProtocolException2() throws Exception {
    int badHandler = 1;
    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 + badHandler, HA_THROW_PROTOCOL_EXCEPTION_INBOUND);
    try {
        testStub.testInt(42);
        fail("should have received a web service exception");
    } catch (ProtocolException e) {
        assertTrue("ProtocolException message not as expected, but got:" + e.getMessage(), e.getMessage().contains(CLIENT_PREFIX + badHandler));
    }
    // check called handlers
    int[] called = { 0, 1, 3, 4, 5, 7, 7, 5, 4, 3, 1 };
    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 -- none in jaxws 2.0
    List<String> destroyedHandlers = tracker.getDestroyedHandlers();
    assertTrue("destroyed handler list should be empty", destroyedHandlers.isEmpty());
}
Also used : ProtocolException(jakarta.xml.ws.ProtocolException) HandlerTracker(handler.handler_processing.common.HandlerTracker)

Example 5 with ProtocolException

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

the class EndToEndErrorTest method testServerOutboundProtocolException1.

/*
     * Have one of the server handlers throw a simple protocol
     * exception and check that the proper methods are called.
     */
public void testServerOutboundProtocolException1() 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_PROTOCOL_EXCEPTION_OUTBOUND);
    // so we clear out the client handlers afterwards
    tracker.clearAll();
    try {
        testStub.testInt(3);
        fail("did not receive exception");
    } catch (ProtocolException e) {
    // ok
    }
    // check result
    String[] called = { "4", "2", "1", "0", "0", "1", "2" };
    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);
    assertTrue("Should be no destroyed handlers", destroyedHandlers.isEmpty());
}
Also used : ProtocolException(jakarta.xml.ws.ProtocolException) HandlerTracker(handler.handler_processing.common.HandlerTracker)

Aggregations

ProtocolException (jakarta.xml.ws.ProtocolException)36 WebServiceException (jakarta.xml.ws.WebServiceException)14 SOAPFaultException (jakarta.xml.ws.soap.SOAPFaultException)13 HandlerTracker (fromwsdl.handler.common.HandlerTracker)11 HandlerTracker (handler.handler_processing.common.HandlerTracker)11 TestProtocolException (fromwsdl.handler.common.TestProtocolException)5 TestProtocolException (handler.handler_processing.common.TestProtocolException)5 QName (javax.xml.namespace.QName)4 Message (com.sun.xml.ws.api.message.Message)2 MUHelperHandler (fromwsdl.soap12.fault.client.handlers.MUHelperHandler)2 SOAPBody (jakarta.xml.soap.SOAPBody)2 SOAPElement (jakarta.xml.soap.SOAPElement)2 SOAPException (jakarta.xml.soap.SOAPException)2 SOAPMessage (jakarta.xml.soap.SOAPMessage)2 Node (org.w3c.dom.Node)2 SerializationException (com.sun.xml.ws.encoding.soap.SerializationException)1 JAXBMessage (com.sun.xml.ws.message.jaxb.JAXBMessage)1 CheckedExceptionImpl (com.sun.xml.ws.model.CheckedExceptionImpl)1 DispatchException (com.sun.xml.ws.wsdl.DispatchException)1 ExceptionThrowingHandler (fromwsdl.soap12.fault.client.handlers.ExceptionThrowingHandler)1