use of org.apache.camel.impl.DefaultHeaderFilterStrategy in project camel by apache.
the class DefaultCxfBindingTest method testSetCharsetWithContentType.
@Test
public void testSetCharsetWithContentType() {
DefaultCxfBinding cxfBinding = new DefaultCxfBinding();
cxfBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy());
Exchange exchange = new DefaultExchange(context);
exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "text/xml;charset=ISO-8859-1");
cxfBinding.setCharsetWithContentType(exchange);
String charset = IOHelper.getCharsetName(exchange);
assertEquals("Get a wrong charset", "ISO-8859-1", charset);
exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "text/xml");
cxfBinding.setCharsetWithContentType(exchange);
charset = IOHelper.getCharsetName(exchange);
assertEquals("Get a worng charset name", "UTF-8", charset);
}
use of org.apache.camel.impl.DefaultHeaderFilterStrategy in project camel by apache.
the class DefaultCxfBindingTest method testPopupalteCxfResponseFromExchange.
@Test
public void testPopupalteCxfResponseFromExchange() {
DefaultCxfBinding cxfBinding = new DefaultCxfBinding();
cxfBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy());
Exchange exchange = new DefaultExchange(context, ExchangePattern.InOut);
org.apache.cxf.message.Exchange cxfExchange = new org.apache.cxf.message.ExchangeImpl();
exchange.setProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.PAYLOAD);
exchange.getOut().setHeader("soapAction", "urn:hello:world");
exchange.getOut().setHeader("MyFruitHeader", "peach");
exchange.getOut().addAttachment("att-1", new DataHandler(new FileDataSource("pom.xml")));
exchange.getOut().getAttachmentObject("att-1").setHeader("attachment-header", "value 1");
IMocksControl control = EasyMock.createNiceControl();
Endpoint endpoint = control.createMock(Endpoint.class);
Binding binding = control.createMock(Binding.class);
EasyMock.expect(endpoint.getBinding()).andReturn(binding);
org.apache.cxf.message.Message cxfMessage = new org.apache.cxf.message.MessageImpl();
EasyMock.expect(binding.createMessage()).andReturn(cxfMessage);
cxfExchange.put(Endpoint.class, endpoint);
control.replay();
cxfBinding.populateCxfResponseFromExchange(exchange, cxfExchange);
cxfMessage = cxfExchange.getOutMessage();
assertNotNull(cxfMessage);
Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>) cxfMessage.get(Message.PROTOCOL_HEADERS));
assertNotNull(headers);
assertTrue(headers.size() == 2);
verifyHeader(headers, "soapaction", "urn:hello:world");
verifyHeader(headers, "SoapAction", "urn:hello:world");
verifyHeader(headers, "SOAPAction", "urn:hello:world");
verifyHeader(headers, "myfruitheader", "peach");
verifyHeader(headers, "myFruitHeader", "peach");
verifyHeader(headers, "MYFRUITHEADER", "peach");
Collection<Attachment> attachments = cxfMessage.getAttachments();
assertNotNull(attachments);
assertNotNull(attachments.size() == 1);
Attachment att = attachments.iterator().next();
assertEquals("att-1", att.getId());
assertEquals("value 1", att.getHeader("attachment-header"));
}
use of org.apache.camel.impl.DefaultHeaderFilterStrategy in project camel by apache.
the class DefaultCxfRsBindingTest method testCopyProtocolHeader.
@Test
public void testCopyProtocolHeader() {
DefaultCxfRsBinding cxfRsBinding = new DefaultCxfRsBinding();
cxfRsBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy());
Exchange exchange = new DefaultExchange(context);
Message camelMessage = new DefaultMessage();
org.apache.cxf.message.Message cxfMessage = new MessageImpl();
Map<String, List<String>> headers = new HashMap<String, List<String>>();
headers.put("emptyList", Collections.EMPTY_LIST);
headers.put("zeroSizeList", new ArrayList<String>(0));
cxfMessage.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, headers);
cxfRsBinding.copyProtocolHeader(cxfMessage, camelMessage, exchange);
assertNull("We should get nothing here", camelMessage.getHeader("emptyList"));
assertNull("We should get nothing here", camelMessage.getHeader("zeroSizeList"));
}
use of org.apache.camel.impl.DefaultHeaderFilterStrategy in project camel by apache.
the class MessageHelperTest method testCopyHeadersWithHeaderFilterStrategy.
public void testCopyHeadersWithHeaderFilterStrategy() throws Exception {
CamelContext context = new DefaultCamelContext();
context.start();
message = new DefaultExchange(context).getIn();
Message source = message;
Message target = message.getExchange().getOut();
DefaultHeaderFilterStrategy headerFilterStrategy = new DefaultHeaderFilterStrategy();
headerFilterStrategy.setInFilterPattern("foo");
source.setHeader("foo", 123);
source.setHeader("bar", 456);
target.setHeader("bar", "yes");
MessageHelper.copyHeaders(source, target, headerFilterStrategy, true);
assertEquals(null, target.getHeader("foo"));
assertEquals(456, target.getHeader("bar"));
context.stop();
}
use of org.apache.camel.impl.DefaultHeaderFilterStrategy in project camel by apache.
the class HttpRoundtripHeaderTest method testHttpRoundTripHeadersWithNoIgnoredHeaders.
@Test
public void testHttpRoundTripHeadersWithNoIgnoredHeaders() throws Exception {
MockEndpoint mockEndpoint = resolveMandatoryEndpoint("mock:results", MockEndpoint.class);
mockEndpoint.expectedMessageCount(1);
JettyHttpEndpoint endpoint = context.getEndpoint(jettyUri, JettyHttpEndpoint.class);
// override the default set of ignored headers which includes Content-Length
((DefaultHeaderFilterStrategy) endpoint.getHeaderFilterStrategy()).setOutFilter(null);
// read the response data
InputStream answer = (InputStream) template.requestBody(uri, inputText);
verifyMockGotExpectedText(mockEndpoint, expectedText);
String lastLine = readLastLine(answer);
assertNotNull("last response line", lastLine);
// Content-Length from request will truncate the output to just the inputText
assertEquals("response matches: " + inputText, inputText, lastLine);
}
Aggregations