Search in sources :

Example 6 with ProtocolException

use of javax.xml.ws.ProtocolException in project cxf by apache.

the class HandlerChainInvokerTest method testHandleFaultReturnsTrue.

// JAXB spec 9.3.2.2: Return true This indicates that fault message processing
// should continue. The runtime invokes handle Fault on the next handler or dispatches
// the fault message (see section 9.1.2.2) if there are no further handlers.
@Test
public void testHandleFaultReturnsTrue() {
    ProtocolException pe = new ProtocolException("banzai");
    logicalHandlers[2].setException(pe);
    invoker.setRequestor(true);
    logicalHandlers[0].setHandleFaultRet(true);
    logicalHandlers[1].setHandleFaultRet(true);
    logicalHandlers[2].setHandleFaultRet(true);
    logicalHandlers[3].setHandleFaultRet(true);
    boolean continueProcessing = false;
    try {
        continueProcessing = invoker.invokeLogicalHandlers(false, lmc);
        fail("did not get expected exception");
    } catch (RuntimeException e) {
        assertEquals("banzai", e.getMessage());
    }
    assertFalse(continueProcessing);
    // assertTrue(invoker.isClosed());
    assertEquals(1, logicalHandlers[0].getHandleMessageCount());
    assertEquals(1, logicalHandlers[1].getHandleMessageCount());
    assertEquals(1, logicalHandlers[2].getHandleMessageCount());
    assertEquals(0, logicalHandlers[3].getHandleMessageCount());
    assertEquals(1, logicalHandlers[0].getHandleFaultCount());
    assertEquals(1, logicalHandlers[1].getHandleFaultCount());
    assertEquals(0, logicalHandlers[2].getHandleFaultCount());
    assertEquals(0, logicalHandlers[3].getHandleFaultCount());
    assertTrue(logicalHandlers[1].getInvokeOrderOfHandleFault() < logicalHandlers[0].getInvokeOrderOfHandleFault());
    assertEquals(1, logicalHandlers[0].getCloseCount());
    assertEquals(1, logicalHandlers[1].getCloseCount());
    assertEquals(1, logicalHandlers[2].getCloseCount());
    assertEquals(0, logicalHandlers[3].getCloseCount());
}
Also used : ProtocolException(javax.xml.ws.ProtocolException) Test(org.junit.Test)

Example 7 with ProtocolException

use of javax.xml.ws.ProtocolException in project cxf by apache.

the class ModifyNumberHandler method handleMessage.

public final boolean handleMessage(LogicalMessageContext messageContext) {
    try {
        // get the LogicalMessage from our context
        LogicalMessage msg = messageContext.getMessage();
        // check the payload, if its an AddNumbers request, we'll intervene
        JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
        Object payload = msg.getPayload(jaxbContext);
        Object value = payload;
        if (payload instanceof JAXBElement) {
            value = ((JAXBElement<?>) payload).getValue();
        }
        if (value instanceof AddNumbers) {
            AddNumbers req = (AddNumbers) value;
            int a = req.getArg0();
            req.setArg0(a * 10);
            msg.setPayload(payload, jaxbContext);
        }
        return true;
    } catch (JAXBException ex) {
        throw new ProtocolException(ex);
    }
}
Also used : ProtocolException(javax.xml.ws.ProtocolException) JAXBException(javax.xml.bind.JAXBException) AddNumbers(org.apache.handlers.types.AddNumbers) JAXBContext(javax.xml.bind.JAXBContext) LogicalMessage(javax.xml.ws.LogicalMessage) JAXBElement(javax.xml.bind.JAXBElement)

Example 8 with ProtocolException

use of javax.xml.ws.ProtocolException in project cxf by apache.

the class SmallNumberHandler method handleMessage.

public final boolean handleMessage(LogicalMessageContext messageContext) {
    try {
        boolean outbound = (Boolean) messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
        if (outbound) {
            // get the LogicalMessage from our context
            LogicalMessage msg = messageContext.getMessage();
            // check the payload, if its an AddNumbers request, we'll intervene
            JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
            Object payload = msg.getPayload(jaxbContext);
            if (payload instanceof JAXBElement) {
                payload = ((JAXBElement<?>) payload).getValue();
            }
            if (payload instanceof AddNumbers) {
                AddNumbers req = (AddNumbers) payload;
                // now, if the arguments are small, let's do the calculation here
                int a = req.getArg0();
                int b = req.getArg1();
                if (isSmall(a) && isSmall(b)) {
                    int answer = a + b;
                    // System.out.printf("SmallNumberHandler addNumbers(%d, %d) == %d\n", a, b, answer);
                    // ok, we've done the calculation, so build the
                    // response and set it as the payload of the message
                    AddNumbersResponse resp = new AddNumbersResponse();
                    resp.setReturn(answer);
                    msg.setPayload(new ObjectFactory().createAddNumbersResponse(resp), jaxbContext);
                    Source src = msg.getPayload();
                    msg.setPayload(src);
                    payload = msg.getPayload(jaxbContext);
                    if (payload instanceof JAXBElement) {
                        payload = ((JAXBElement<?>) payload).getValue();
                    }
                    AddNumbersResponse resp2 = (AddNumbersResponse) payload;
                    if (resp2 == resp) {
                        throw new WebServiceException("Shouldn't be the same object");
                    }
                    // returned to the client
                    return false;
                }
            }
        }
        return true;
    } catch (JAXBException ex) {
        throw new ProtocolException(ex);
    }
}
Also used : ProtocolException(javax.xml.ws.ProtocolException) WebServiceException(javax.xml.ws.WebServiceException) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) AddNumbersResponse(org.apache.handlers.types.AddNumbersResponse) JAXBElement(javax.xml.bind.JAXBElement) Source(javax.xml.transform.Source) ObjectFactory(org.apache.handlers.types.ObjectFactory) AddNumbers(org.apache.handlers.types.AddNumbers) LogicalMessage(javax.xml.ws.LogicalMessage)

Example 9 with ProtocolException

use of javax.xml.ws.ProtocolException in project cxf by apache.

the class TestHandler method handleMessage.

public boolean handleMessage(T ctx) {
    methodCalled("handleMessage");
    printHandlerInfo("handleMessage", isOutbound(ctx));
    boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    boolean ret = getHandleMessageRet();
    if (!isServerSideHandler()) {
        return true;
    }
    try {
        verifyJAXWSProperties(ctx);
    } catch (PingException e) {
        e.printStackTrace();
        throw new ProtocolException(e);
    }
    Object obj = ctx.getMessage().getPayload(jaxbCtx);
    if (obj instanceof Ping || obj instanceof PingResponse) {
        ret = handlePingMessage(outbound, ctx);
    } else if (obj instanceof PingWithArgs) {
        ret = handlePingWithArgsMessage(outbound, ctx);
    }
    return ret;
}
Also used : ProtocolException(javax.xml.ws.ProtocolException) PingWithArgs(org.apache.handler_test.types.PingWithArgs) Ping(org.apache.handler_test.types.Ping) PingResponse(org.apache.handler_test.types.PingResponse) PingException(org.apache.handler_test.PingException)

Example 10 with ProtocolException

use of javax.xml.ws.ProtocolException in project cxf by apache.

the class MAPTestBase method testExplicitMAPs.

@Test
public void testExplicitMAPs() throws Exception {
    try {
        String msgId = "urn:uuid:12345-" + Math.random();
        Map<String, Object> requestContext = ((BindingProvider) greeter).getRequestContext();
        AddressingProperties maps = new AddressingProperties();
        AttributedURIType id = ContextUtils.getAttributedURI(msgId);
        maps.setMessageID(id);
        requestContext.put(CLIENT_ADDRESSING_PROPERTIES, maps);
        String greeting = greeter.greetMe("explicit1");
        assertEquals("unexpected response received from service", "Hello explicit1", greeting);
        checkVerification();
        // message ID fault is expected
        try {
            greeter.greetMe("explicit2");
            fail("expected ProtocolException on duplicate message ID");
        } catch (ProtocolException pe) {
            assertEquals("expected duplicate message ID failure", "Duplicate Message ID " + msgId, pe.getMessage());
            checkVerification();
        }
        // clearing the message ID ensure a duplicate is not sent
        maps.setMessageID(null);
        // maps.setRelatesTo(ContextUtils.getRelatesTo(id.getValue()));
        greeting = greeter.greetMe("explicit3");
        assertEquals("unexpected response received from service", "Hello explicit3", greeting);
    } catch (UndeclaredThrowableException ex) {
        throw (Exception) ex.getCause();
    }
}
Also used : ProtocolException(javax.xml.ws.ProtocolException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) BindingProvider(javax.xml.ws.BindingProvider) Test(org.junit.Test)

Aggregations

ProtocolException (javax.xml.ws.ProtocolException)17 Test (org.junit.Test)10 LogicalMessage (javax.xml.ws.LogicalMessage)4 JAXBContext (javax.xml.bind.JAXBContext)3 JAXBElement (javax.xml.bind.JAXBElement)3 JAXBException (javax.xml.bind.JAXBException)3 Source (javax.xml.transform.Source)3 AddNumbers (org.apache.handlers.types.AddNumbers)3 StringTokenizer (java.util.StringTokenizer)2 SOAPException (javax.xml.soap.SOAPException)2 SOAPMessage (javax.xml.soap.SOAPMessage)2 WebServiceException (javax.xml.ws.WebServiceException)2 WrappedMessageContext (org.apache.cxf.jaxws.context.WrappedMessageContext)2 PingResponse (org.apache.handler_test.types.PingResponse)2 PingWithArgs (org.apache.handler_test.types.PingWithArgs)2 AddNumbersResponse (org.apache.handlers.types.AddNumbersResponse)2 ObjectFactory (org.apache.handlers.types.ObjectFactory)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 MessageFactory (javax.xml.soap.MessageFactory)1 SOAPBody (javax.xml.soap.SOAPBody)1