Search in sources :

Example 1 with CxfHeaderFilterStrategy

use of org.apache.camel.component.cxf.common.header.CxfHeaderFilterStrategy 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 2 with CxfHeaderFilterStrategy

use of org.apache.camel.component.cxf.common.header.CxfHeaderFilterStrategy in project camel by apache.

the class CxfMessageHeadersRelayTest method testMessageHeadersRelaysSpringContext.

@Test
public void testMessageHeadersRelaysSpringContext() throws Exception {
    CxfEndpoint endpoint = context.getEndpoint("cxf:bean:serviceExtraRelays?headerFilterStrategy=#customMessageFilterStrategy", CxfEndpoint.class);
    CxfHeaderFilterStrategy strategy = (CxfHeaderFilterStrategy) endpoint.getHeaderFilterStrategy();
    List<MessageHeaderFilter> filters = strategy.getMessageHeaderFilters();
    assertEquals("Expected number of filters ", 2, filters.size());
    Map<String, MessageHeaderFilter> messageHeaderFilterMap = strategy.getMessageHeaderFiltersMap();
    for (String ns : new CustomHeaderFilter().getActivationNamespaces()) {
        assertEquals("Expected a filter class for namespace: " + ns, CustomHeaderFilter.class, messageHeaderFilterMap.get(ns).getClass());
    }
}
Also used : MessageHeaderFilter(org.apache.camel.component.cxf.common.header.MessageHeaderFilter) CxfHeaderFilterStrategy(org.apache.camel.component.cxf.common.header.CxfHeaderFilterStrategy) CxfEndpoint(org.apache.camel.component.cxf.CxfEndpoint) Test(org.junit.Test)

Aggregations

CxfHeaderFilterStrategy (org.apache.camel.component.cxf.common.header.CxfHeaderFilterStrategy)2 Test (org.junit.Test)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 List (java.util.List)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 DOMSource (javax.xml.transform.dom.DOMSource)1 CxfEndpoint (org.apache.camel.component.cxf.CxfEndpoint)1 MessageHeaderFilter (org.apache.camel.component.cxf.common.header.MessageHeaderFilter)1 DefaultExchange (org.apache.camel.impl.DefaultExchange)1 HeaderFilterStrategy (org.apache.camel.spi.HeaderFilterStrategy)1 Message (org.apache.cxf.message.Message)1