Search in sources :

Example 56 with Message

use of org.apache.cxf.message.Message in project tesb-rt-se by Talend.

the class CorrelationIDProcessor method process.

static void process(Message message, Assertion policy) throws SAXException, IOException, ParserConfigurationException {
    if (LOG.isLoggable(Level.FINE)) {
        LOG.log(Level.FINE, "Message process for correlation ID started");
    }
    String correlationId = null;
    // get ID from SOAP header
    correlationId = CorrelationIdSoapCodec.readCorrelationId(message);
    // get ID from Http header
    if (null == correlationId) {
        correlationId = CorrelationIdProtocolHeaderCodec.readCorrelationId(message);
    }
    // get from message
    if (null == correlationId) {
        // Get ID from Message
        correlationId = (String) message.get(CorrelationIDFeature.MESSAGE_CORRELATION_ID);
    }
    if ((message.getContent(javax.xml.stream.XMLStreamWriter.class) != null) && (message.getContent(javax.xml.stream.XMLStreamWriter.class) instanceof SAAJStreamWriter)) {
        NodeList nodeList = ((SAAJStreamWriter) message.getContent(javax.xml.stream.XMLStreamWriter.class)).getDocument().getElementsByTagNameNS("http://www.talend.com/esb/sam/correlationId/v1", "correlationId");
        if (nodeList.getLength() > 0) {
            correlationId = nodeList.item(0).getTextContent();
        }
    }
    // get from message exchange
    if (null == correlationId) {
        // Get ID from Message exchange
        Exchange ex = message.getExchange();
        if (null != ex) {
            Message reqMsg = null;
            if (MessageUtils.isOutbound(message)) {
                reqMsg = ex.getInMessage();
            } else {
                reqMsg = ex.getOutMessage();
            }
            if (null != reqMsg) {
                correlationId = (String) reqMsg.get(CorrelationIDFeature.MESSAGE_CORRELATION_ID);
            }
        }
    }
    // If correlationId is null we should add it to headers
    if (null == correlationId) {
        MethodType mType = CorrelationIDAssertion.MethodType.CALLBACK;
        if (policy instanceof CorrelationIDAssertion) {
            mType = ((CorrelationIDAssertion) policy).getMethodType();
        }
        if (MethodType.XPATH.equals(mType) && !MessageUtils.isFault(message)) {
            XPathProcessor proc = new XPathProcessor(policy, message);
            correlationId = proc.getCorrelationID();
        } else if (MethodType.CALLBACK.equals(mType)) {
            CorrelationIDCallbackHandler handler = (CorrelationIDCallbackHandler) message.get(CorrelationIDFeature.CORRELATION_ID_CALLBACK_HANDLER);
            if (null == handler) {
                handler = (CorrelationIDCallbackHandler) message.getContextualProperty(CorrelationIDFeature.CORRELATION_ID_CALLBACK_HANDLER);
            }
            if (handler != null)
                correlationId = handler.getCorrelationId();
        }
        // request
        if (null == correlationId) {
            correlationId = ContextUtils.generateUUID();
        }
    }
    message.put(CorrelationIDFeature.MESSAGE_CORRELATION_ID, correlationId);
    if (isRestMessage(message)) {
        // Add correlationId to http header
        if (null == CorrelationIdProtocolHeaderCodec.readCorrelationId(message)) {
            CorrelationIdProtocolHeaderCodec.writeCorrelationId(message, correlationId);
        }
    } else {
        // Add correlationId to soap header
        if (null == CorrelationIdSoapCodec.readCorrelationId(message)) {
            CorrelationIdSoapCodec.writeCorrelationId(message, correlationId);
        }
    }
}
Also used : MethodType(org.talend.esb.policy.correlation.impl.CorrelationIDAssertion.MethodType) Message(org.apache.cxf.message.Message) NodeList(org.w3c.dom.NodeList) SAAJStreamWriter(org.apache.cxf.binding.soap.saaj.SAAJStreamWriter) Exchange(org.apache.cxf.message.Exchange) CorrelationIDCallbackHandler(org.talend.esb.policy.correlation.CorrelationIDCallbackHandler)

Example 57 with Message

use of org.apache.cxf.message.Message in project tesb-rt-se by Talend.

the class CompressionOutInterceptorTest method handleRuntimeException1.

@Test
public void handleRuntimeException1() throws Exception {
    CompressionOutInterceptor c = new CompressionOutInterceptor() {

        public void wrapOriginalOutputStream(Message message) throws Fault {
            throw new RuntimeException();
        }
    };
    try {
        c.handleMessage(CompressionCommonTest.getMessageStub(null, null));
    } catch (RuntimeException ex) {
        return;
    }
    fail("No exception is not expected");
}
Also used : Message(org.apache.cxf.message.Message) CompressionOutInterceptor(org.talend.esb.policy.compression.impl.CompressionOutInterceptor) Test(org.junit.Test)

Example 58 with Message

use of org.apache.cxf.message.Message in project tesb-rt-se by Talend.

the class CompressionPolicyBuilderTest method testCompressionPolicyBuilder.

@Test
public void testCompressionPolicyBuilder() {
    Collection<Assertion> c = new ArrayList<Assertion>();
    AssertionInfoMap aim = new AssertionInfoMap(c);
    Message m = CompressionCommonTest.getMessageStub(aim, null);
    try {
        assertNull(CompressionPolicyBuilder.getAssertion(m));
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }
}
Also used : Message(org.apache.cxf.message.Message) Assertion(org.apache.neethi.Assertion) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap) SAXException(org.xml.sax.SAXException) Test(org.junit.Test)

Example 59 with Message

use of org.apache.cxf.message.Message in project tesb-rt-se by Talend.

the class STSRESTOutInterceptorTest method handleMessageNotRequestor.

@Test
public void handleMessageNotRequestor() throws Exception {
    STSRESTOutInterceptor i = new STSRESTOutInterceptor();
    Message message = createMock(Message.class);
    message.get(Message.REQUESTOR_ROLE);
    expectLastCall().andReturn(false).anyTimes();
    STSClient stsClient = createMock(STSClient.class);
    i.setStsClient(stsClient);
    assertSame(stsClient, i.getStsClient());
    replay(message);
    i.handleMessage(message);
    verify(message);
}
Also used : STSClient(org.apache.cxf.ws.security.trust.STSClient) Message(org.apache.cxf.message.Message) STSRESTOutInterceptor(org.talend.esb.security.saml.STSRESTOutInterceptor) Test(org.junit.Test)

Example 60 with Message

use of org.apache.cxf.message.Message in project tesb-rt-se by Talend.

the class STSRESTOutInterceptorTest method handleMessageNoStsClient.

@Test
public void handleMessageNoStsClient() throws Exception {
    STSRESTOutInterceptor i = new STSRESTOutInterceptor();
    Message message = createMock(Message.class);
    message.get(Message.REQUESTOR_ROLE);
    expectLastCall().andReturn(true).anyTimes();
    i.setStsClient(null);
    assertSame(null, i.getStsClient());
    replay(message);
    i.handleMessage(message);
    verify(message);
}
Also used : Message(org.apache.cxf.message.Message) STSRESTOutInterceptor(org.talend.esb.security.saml.STSRESTOutInterceptor) Test(org.junit.Test)

Aggregations

Message (org.apache.cxf.message.Message)1002 Test (org.junit.Test)507 MessageImpl (org.apache.cxf.message.MessageImpl)291 Exchange (org.apache.cxf.message.Exchange)199 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)169 Endpoint (org.apache.cxf.endpoint.Endpoint)91 Interceptor (org.apache.cxf.interceptor.Interceptor)87 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)85 ArrayList (java.util.ArrayList)83 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)76 List (java.util.List)75 IOException (java.io.IOException)73 OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)73 Method (java.lang.reflect.Method)69 Bus (org.apache.cxf.Bus)69 QName (javax.xml.namespace.QName)62 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)55 HashMap (java.util.HashMap)53 Fault (org.apache.cxf.interceptor.Fault)51 ByteArrayInputStream (java.io.ByteArrayInputStream)49