Search in sources :

Example 6 with Message

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

the class DefaultCxfMessageMapper method createCxfMessageFromCamelExchange.

public Message createCxfMessageFromCamelExchange(Exchange camelExchange, HeaderFilterStrategy headerFilterStrategy) {
    org.apache.cxf.message.Message answer = CxfMessageHelper.getCxfInMessage(headerFilterStrategy, camelExchange, false);
    org.apache.camel.Message camelMessage = camelExchange.getIn();
    String requestContentType = getRequestContentType(camelMessage);
    String acceptContentTypes = camelMessage.getHeader("Accept", String.class);
    if (acceptContentTypes == null) {
        acceptContentTypes = "*/*";
    }
    String enc = getCharacterEncoding(camelMessage);
    String requestURI = getRequestURI(camelMessage);
    String path = getPath(camelMessage);
    String basePath = getBasePath(camelExchange);
    String verb = getVerb(camelMessage);
    String queryString = getQueryString(camelMessage);
    answer.put(org.apache.cxf.message.Message.REQUEST_URI, requestURI);
    answer.put(org.apache.cxf.message.Message.BASE_PATH, basePath);
    answer.put(org.apache.cxf.message.Message.HTTP_REQUEST_METHOD, verb);
    answer.put(org.apache.cxf.message.Message.PATH_INFO, path);
    answer.put(org.apache.cxf.message.Message.CONTENT_TYPE, requestContentType);
    answer.put(org.apache.cxf.message.Message.ACCEPT_CONTENT_TYPE, acceptContentTypes);
    answer.put(org.apache.cxf.message.Message.ENCODING, enc);
    answer.put(org.apache.cxf.message.Message.QUERY_STRING, queryString);
    HttpServletRequest request = (HttpServletRequest) camelMessage.getHeader(Exchange.HTTP_SERVLET_REQUEST);
    answer.put(CXF_HTTP_REQUEST, request);
    if (request != null) {
        setSecurityContext(answer, request);
    }
    Object response = camelMessage.getHeader(Exchange.HTTP_SERVLET_RESPONSE);
    answer.put(CXF_HTTP_RESPONSE, response);
    LOG.trace("Processing {}, requestContentType = {}, acceptContentTypes = {}, encoding = {}, path = {}, basePath = {}, verb = {}", new Object[] { camelExchange, requestContentType, acceptContentTypes, enc, path, basePath, verb });
    return answer;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Message(org.apache.cxf.message.Message)

Example 7 with Message

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

the class CamelDestinationTest method testRoundTripDestinationWithFault.

@Test
public void testRoundTripDestinationWithFault() throws Exception {
    inMessage = null;
    EndpointInfo conduitEpInfo = new EndpointInfo();
    conduitEpInfo.setAddress("camel://direct:Producer");
    // set up the conduit send to be true
    CamelConduit conduit = setupCamelConduit(conduitEpInfo, true, false);
    final Message outMessage = new MessageImpl();
    endpointInfo.setAddress("camel://direct:EndpointA");
    final CamelDestination destination = setupCamelDestination(endpointInfo, true);
    destination.setCheckException(true);
    // set up MessageObserver for handling the conduit message
    MessageObserver observer = new MessageObserver() {

        public void onMessage(Message m) {
            try {
                Exchange exchange = new ExchangeImpl();
                exchange.setInMessage(m);
                m.setExchange(exchange);
                verifyReceivedMessage(m, "HelloWorld");
                //verifyHeaders(m, outMessage);
                // setup the message for
                Conduit backConduit;
                backConduit = getBackChannel(destination, m);
                // wait for the message to be got from the conduit
                Message replyMessage = new MessageImpl();
                replyMessage.setContent(Exception.class, new RuntimeCamelException());
                sendoutMessage(backConduit, replyMessage, true, "HelloWorld Fault");
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    MockEndpoint error = context.getEndpoint("mock:error", MockEndpoint.class);
    error.expectedMessageCount(1);
    //this call will active the camelDestination
    destination.setMessageObserver(observer);
    // set is one way false for get response from destination
    // need to use another thread to send the request message
    sendoutMessage(conduit, outMessage, false, "HelloWorld");
    // wait for the message to be got from the destination,
    // create the thread to handler the Destination incoming message
    verifyReceivedMessage(inMessage, "HelloWorld Fault");
    error.assertIsSatisfied();
    destination.shutdown();
}
Also used : MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) IOException(java.io.IOException) WebServiceException(javax.xml.ws.WebServiceException) DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Conduit(org.apache.cxf.transport.Conduit) RuntimeCamelException(org.apache.camel.RuntimeCamelException) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 8 with Message

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

the class CamelTransportTestSupport method setupCamelConduit.

protected CamelConduit setupCamelConduit(EndpointInfo endpointInfo, boolean send, boolean decoupled) {
    if (decoupled) {
    // setup the reference type
    } else {
        target = EasyMock.createMock(EndpointReferenceType.class);
    }
    CamelConduit camelConduit = new CamelConduit(context, bus, endpointInfo, target);
    if (send) {
        // setMessageObserver
        observer = new MessageObserver() {

            public void onMessage(Message m) {
                inMessage = m;
            }
        };
        camelConduit.setMessageObserver(observer);
    }
    return camelConduit;
}
Also used : EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message)

Example 9 with Message

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

the class CxfMessageHelperTest method testGetCxfInMessage.

// setup the default context for testing
@Test
public void testGetCxfInMessage() throws Exception {
    HeaderFilterStrategy headerFilterStrategy = new CxfHeaderFilterStrategy();
    org.apache.camel.Exchange exchange = new DefaultExchange(context);
    // String
    exchange.getIn().setBody("hello world");
    org.apache.cxf.message.Message message = CxfMessageHelper.getCxfInMessage(headerFilterStrategy, exchange, false);
    // test message
    InputStream is = message.getContent(InputStream.class);
    assertNotNull("The input stream should not be null", is);
    assertEquals("Don't get the right message", toString(is), "hello world");
    // DOMSource
    URL request = this.getClass().getResource("RequestBody.xml");
    File requestFile = new File(request.toURI());
    FileInputStream inputStream = new FileInputStream(requestFile);
    XMLStreamReader xmlReader = StaxUtils.createXMLStreamReader(inputStream);
    DOMSource source = new DOMSource(StaxUtils.read(xmlReader));
    exchange.getIn().setBody(source);
    message = CxfMessageHelper.getCxfInMessage(headerFilterStrategy, exchange, false);
    is = message.getContent(InputStream.class);
    assertNotNull("The input stream should not be null", is);
    assertEquals("Don't get the right message", toString(is), REQUEST_STRING);
    // File
    exchange.getIn().setBody(requestFile);
    message = CxfMessageHelper.getCxfInMessage(headerFilterStrategy, exchange, false);
    is = message.getContent(InputStream.class);
    assertNotNull("The input stream should not be null", is);
    assertEquals("Don't get the right message", toString(is), REQUEST_STRING);
    // transport header's case insensitiveness
    // String
    exchange.getIn().setBody("hello world");
    exchange.getIn().setHeader("soapAction", "urn:hello:world");
    message = CxfMessageHelper.getCxfInMessage(headerFilterStrategy, exchange, false);
    // test message
    Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS));
    // verify there is no duplicate
    assertNotNull("The headers must be present", headers);
    assertTrue("There must be one header entry", headers.size() == 1);
    // verify the soapaction can be retrieved in case-insensitive ways
    verifyHeader(headers, "soapaction", "urn:hello:world");
    verifyHeader(headers, "SoapAction", "urn:hello:world");
    verifyHeader(headers, "SOAPAction", "urn:hello:world");
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) DOMSource(javax.xml.transform.dom.DOMSource) XMLStreamReader(javax.xml.stream.XMLStreamReader) CxfHeaderFilterStrategy(org.apache.camel.component.cxf.common.header.CxfHeaderFilterStrategy) Message(org.apache.cxf.message.Message) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) CxfHeaderFilterStrategy(org.apache.camel.component.cxf.common.header.CxfHeaderFilterStrategy) HeaderFilterStrategy(org.apache.camel.spi.HeaderFilterStrategy) URL(java.net.URL) FileInputStream(java.io.FileInputStream) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Example 10 with Message

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

the class CamelConduitTest method testPrepareSend.

@Test
public void testPrepareSend() throws Exception {
    endpointInfo.setAddress("camel://direct:Producer");
    CamelConduit conduit = setupCamelConduit(endpointInfo, false, false);
    Message message = new MessageImpl();
    try {
        conduit.prepare(message);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    verifyMessageContent(message);
}
Also used : Message(org.apache.cxf.message.Message) MessageImpl(org.apache.cxf.message.MessageImpl) IOException(java.io.IOException) 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