Search in sources :

Example 11 with Message

use of org.apache.cxf.message.Message in project camel by apache.

the class CamelConduitTest method testSendOutRunTrip.

@Test
public void testSendOutRunTrip() throws Exception {
    endpointInfo.setAddress("camel://direct:Producer");
    CamelConduit conduit = setupCamelConduit(endpointInfo, true, false);
    MockEndpoint endpoint = getMockEndpoint("mock:EndpointA");
    endpoint.expectedMessageCount(1);
    Message message = new MessageImpl();
    // set the isOneWay to be false
    sendoutMessage(conduit, message, false, "HelloWorld");
    // verify the endpoint get the response
    assertMockEndpointsSatisfied();
    verifyReceivedMessage("HelloWorld");
}
Also used : Message(org.apache.cxf.message.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 12 with Message

use of org.apache.cxf.message.Message in project camel by apache.

the class DataInInterceptor method handleMessage.

public void handleMessage(Message message) throws Fault {
    DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
    try {
        // put the payload source as a document
        Document doc = StaxUtils.read(xmlReader);
        message.setContent(Source.class, new DOMSource(doc));
    } catch (XMLStreamException e) {
        throw new Fault(new org.apache.cxf.common.i18n.Message("XMLSTREAM_EXCEPTION", JUL_LOG), e);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) XMLStreamException(javax.xml.stream.XMLStreamException) Message(org.apache.cxf.message.Message) Fault(org.apache.cxf.interceptor.Fault) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) Document(org.w3c.dom.Document)

Example 13 with Message

use of org.apache.cxf.message.Message in project camel by apache.

the class RawMessageWSDLGetInterceptor method handleMessage.

public void handleMessage(Message message) throws Fault {
    String method = (String) message.get(Message.HTTP_REQUEST_METHOD);
    String query = (String) message.get(Message.QUERY_STRING);
    if (!"GET".equals(method) || StringUtils.isEmpty(query)) {
        return;
    }
    String baseUri = (String) message.get(Message.REQUEST_URL);
    String ctx = (String) message.get(Message.PATH_INFO);
    Map<String, String> map = UrlUtils.parseQueryString(query);
    if (isRecognizedQuery(map, baseUri, ctx, message.getExchange().getEndpoint().getEndpointInfo())) {
        Document doc = getDocument(message, baseUri, map, ctx);
        Endpoint e = message.getExchange().get(Endpoint.class);
        Message mout = new MessageImpl();
        mout.setExchange(message.getExchange());
        mout = e.getBinding().createMessage(mout);
        mout.setInterceptorChain(OutgoingChainInterceptor.getOutInterceptorChain(message.getExchange()));
        message.getExchange().setOutMessage(mout);
        mout.put(DOCUMENT_HOLDER, doc);
        Iterator<Interceptor<? extends Message>> iterator = mout.getInterceptorChain().iterator();
        while (iterator.hasNext()) {
            Interceptor<? extends Message> inInterceptor = iterator.next();
            if (inInterceptor instanceof AbstractPhaseInterceptor) {
                AbstractPhaseInterceptor<?> interceptor = (AbstractPhaseInterceptor<?>) inInterceptor;
                if (interceptor.getPhase().equals(Phase.PREPARE_SEND) || interceptor.getPhase().equals(Phase.PRE_STREAM)) {
                    // just make sure we keep the right interceptors
                    continue;
                }
            }
            mout.getInterceptorChain().remove(inInterceptor);
        }
        // notice this is being added after the purge above, don't swap the order!
        mout.getInterceptorChain().add(RawMessageWSDLGetOutInterceptor.INSTANCE);
        // skip the service executor and goto the end of the chain.
        message.getInterceptorChain().doInterceptStartingAt(message, OutgoingChainInterceptor.class.getName());
    }
}
Also used : Endpoint(org.apache.cxf.endpoint.Endpoint) Message(org.apache.cxf.message.Message) OutgoingChainInterceptor(org.apache.cxf.interceptor.OutgoingChainInterceptor) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) Document(org.w3c.dom.Document) MessageImpl(org.apache.cxf.message.MessageImpl) Interceptor(org.apache.cxf.interceptor.Interceptor) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) EndpointSelectionInterceptor(org.apache.cxf.binding.soap.interceptor.EndpointSelectionInterceptor) OutgoingChainInterceptor(org.apache.cxf.interceptor.OutgoingChainInterceptor)

Example 14 with Message

use of org.apache.cxf.message.Message in project cxf by apache.

the class TestUtilities method invokeBytes.

public byte[] invokeBytes(String address, String transport, byte[] message) throws Exception {
    EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http");
    ei.setAddress(address);
    ConduitInitiatorManager conduitMgr = getBus().getExtension(ConduitInitiatorManager.class);
    ConduitInitiator conduitInit = conduitMgr.getConduitInitiator(transport);
    Conduit conduit = conduitInit.getConduit(ei, getBus());
    TestMessageObserver obs = new TestMessageObserver();
    conduit.setMessageObserver(obs);
    Message m = new MessageImpl();
    conduit.prepare(m);
    OutputStream os = m.getContent(OutputStream.class);
    os.write(message);
    // TODO: shouldn't have to do this. IO caching needs cleaning
    // up or possibly removal...
    os.flush();
    os.close();
    return obs.getResponseStream().toByteArray();
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Message(org.apache.cxf.message.Message) Conduit(org.apache.cxf.transport.Conduit) ConduitInitiatorManager(org.apache.cxf.transport.ConduitInitiatorManager) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) MessageImpl(org.apache.cxf.message.MessageImpl)

Example 15 with Message

use of org.apache.cxf.message.Message in project ddf by codice.

the class MetricsInInterceptorTest method testHandleMessageWithOneWayClientMessage.

/**
     * Test method for
     * {@link ddf.metrics.interceptor.MetricsInInterceptor#handleMessage(org.apache.cxf.message.Message)}
     * .
     *
     * @throws InterruptedException
     */
@Test
public void testHandleMessageWithOneWayClientMessage() {
    // Setup
    MetricsInInterceptor inInterceptor = new MetricsInInterceptor();
    Message mockMessage = mock(Message.class);
    Exchange ex = new ExchangeImpl();
    Bus mockBus = mock(Bus.class);
    ex.put(Bus.class, mockBus);
    ex.setOneWay(true);
    when(mockBus.getId()).thenReturn("bus_id");
    when(mockMessage.getExchange()).thenReturn(ex);
    when(mockMessage.get(Message.REQUESTOR_ROLE)).thenReturn(true);
    // Perform test
    inInterceptor.handleMessage(mockMessage);
    // validate that there is not an instance of LatencyTimeRecorder on the
    // exchange
    assertNull(ex.get(LatencyTimeRecorder.class));
}
Also used : Exchange(org.apache.cxf.message.Exchange) Bus(org.apache.cxf.Bus) Message(org.apache.cxf.message.Message) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) 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