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");
}
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());
}
}
Aggregations