Search in sources :

Example 1 with PingException

use of org.apache.handler_test.PingException 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 2 with PingException

use of org.apache.handler_test.PingException in project cxf by apache.

the class HandlerInvocationTest method testServerEndpointRemoteFault.

@Test
public void testServerEndpointRemoteFault() throws PingException {
    TestHandler<LogicalMessageContext> handler1 = new TestHandler<>(false);
    TestHandler<LogicalMessageContext> handler2 = new TestHandler<LogicalMessageContext>(false) {

        public boolean handleFault(LogicalMessageContext ctx) {
            super.handleFault(ctx);
            try {
                Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
                if (!outbound) {
                    LogicalMessage msg = ctx.getMessage();
                    String payload = convertDOMToString(msg.getPayload());
                    assertTrue(payload.indexOf("<faultstring>" + "servant throws SOAPFaultException" + "</faultstring>") > -1);
                }
            } catch (Exception e) {
                e.printStackTrace();
                fail(e.toString());
            }
            return true;
        }

        private String convertDOMToString(Source s) throws TransformerException {
            StringWriter stringWriter = new StringWriter();
            StreamResult streamResult = new StreamResult(stringWriter);
            TransformerFactory transformerFactory = TransformerFactory.newInstance();
            transformerFactory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
            Transformer transformer = transformerFactory.newTransformer();
            transformer.setOutputProperty(OutputKeys.INDENT, "no");
            transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
            transformer.setOutputProperty(OutputKeys.METHOD, "xml");
            transformer.transform(s, streamResult);
            return stringWriter.toString();
        }
    };
    TestSOAPHandler soapHandler1 = new TestSOAPHandler(false);
    TestSOAPHandler soapHandler2 = new TestSOAPHandler(false) {

        public boolean handleFault(SOAPMessageContext ctx) {
            super.handleFault(ctx);
            try {
                Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
                if (!outbound) {
                    SOAPEnvelope env = ctx.getMessage().getSOAPPart().getEnvelope();
                    assertTrue("expected SOAPFault in SAAJ model", env.getBody().hasFault());
                }
            } catch (Exception e) {
                e.printStackTrace();
                fail(e.toString());
            }
            return true;
        }
    };
    addHandlersToChain((BindingProvider) handlerTest, handler1, handler2, soapHandler1, soapHandler2);
    try {
        handlerTest.pingWithArgs("servant throw SOAPFaultException");
        fail("did not get expected Exception");
    } catch (SOAPFaultException sfe) {
    // expected
    }
    assertEquals(1, handler1.getHandleMessageInvoked());
    assertEquals(1, handler2.getHandleMessageInvoked());
    assertEquals(1, soapHandler1.getHandleMessageInvoked());
    assertEquals(1, soapHandler2.getHandleMessageInvoked());
    assertEquals(1, handler2.getHandleFaultInvoked());
    assertEquals(1, handler1.getHandleFaultInvoked());
    assertEquals(1, soapHandler1.getHandleFaultInvoked());
    assertEquals(1, soapHandler2.getHandleFaultInvoked());
    assertEquals(1, handler1.getCloseInvoked());
    assertEquals(1, handler2.getCloseInvoked());
    assertEquals(1, soapHandler1.getCloseInvoked());
    assertEquals(1, soapHandler2.getCloseInvoked());
    assertTrue(handler2.getInvokeOrderOfClose() < handler1.getInvokeOrderOfClose());
}
Also used : LogicalMessageContext(javax.xml.ws.handler.LogicalMessageContext) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) PingException(org.apache.handler_test.PingException) ProtocolException(javax.xml.ws.ProtocolException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) TransformerException(javax.xml.transform.TransformerException) WebServiceException(javax.xml.ws.WebServiceException) Source(javax.xml.transform.Source) StringWriter(java.io.StringWriter) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) LogicalMessage(javax.xml.ws.LogicalMessage) HandlerTest(org.apache.handler_test.HandlerTest) Test(org.junit.Test)

Example 3 with PingException

use of org.apache.handler_test.PingException in project cxf by apache.

the class HandlerTestImpl method pingWithArgs.

public final List<String> pingWithArgs(String handlerCommand) throws PingException {
    List<String> ret = new ArrayList<>();
    ret.add(handlerCommand);
    ret.addAll(getHandlersInfo(context.getMessageContext()));
    if (handlerCommand.contains("servant throw exception")) {
        PingFaultDetails details = new PingFaultDetails();
        details.setDetail(ret.toString());
        throw new PingException("from servant", details);
    } else if (handlerCommand.contains("servant throw RuntimeException")) {
        throw new RuntimeException("servant throw RuntimeException");
    } else if (handlerCommand.contains("servant throw SOAPFaultException")) {
        throw createSOAPFaultException("servant throws SOAPFaultException");
    } else if (handlerCommand.contains("servant throw WebServiceException")) {
        RuntimeException re = new RuntimeException("servant throws RuntimeException");
        throw new WebServiceException("RemoteException with nested RuntimeException", re);
    }
    return ret;
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) ArrayList(java.util.ArrayList) PingFaultDetails(org.apache.handler_test.types.PingFaultDetails) PingException(org.apache.handler_test.PingException)

Aggregations

PingException (org.apache.handler_test.PingException)3 ProtocolException (javax.xml.ws.ProtocolException)2 WebServiceException (javax.xml.ws.WebServiceException)2 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)1 Source (javax.xml.transform.Source)1 Transformer (javax.xml.transform.Transformer)1 TransformerException (javax.xml.transform.TransformerException)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 StreamResult (javax.xml.transform.stream.StreamResult)1 LogicalMessage (javax.xml.ws.LogicalMessage)1 LogicalMessageContext (javax.xml.ws.handler.LogicalMessageContext)1 SOAPMessageContext (javax.xml.ws.handler.soap.SOAPMessageContext)1 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)1 HandlerTest (org.apache.handler_test.HandlerTest)1 Ping (org.apache.handler_test.types.Ping)1 PingFaultDetails (org.apache.handler_test.types.PingFaultDetails)1 PingResponse (org.apache.handler_test.types.PingResponse)1 PingWithArgs (org.apache.handler_test.types.PingWithArgs)1