Search in sources :

Example 6 with DefaultHeaderFilterStrategy

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);
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultHeaderFilterStrategy(org.apache.camel.impl.DefaultHeaderFilterStrategy) Test(org.junit.Test)

Example 7 with DefaultHeaderFilterStrategy

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"));
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Binding(org.apache.cxf.binding.Binding) Message(org.apache.cxf.message.Message) DefaultHeaderFilterStrategy(org.apache.camel.impl.DefaultHeaderFilterStrategy) Attachment(org.apache.cxf.message.Attachment) DataHandler(javax.activation.DataHandler) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) IMocksControl(org.easymock.IMocksControl) Endpoint(org.apache.cxf.endpoint.Endpoint) FileDataSource(javax.activation.FileDataSource) List(java.util.List) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 8 with DefaultHeaderFilterStrategy

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"));
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultMessage(org.apache.camel.impl.DefaultMessage) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) HashMap(java.util.HashMap) DefaultHeaderFilterStrategy(org.apache.camel.impl.DefaultHeaderFilterStrategy) DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) ArrayList(java.util.ArrayList) List(java.util.List) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 9 with DefaultHeaderFilterStrategy

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();
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultExchange(org.apache.camel.impl.DefaultExchange) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) DefaultHeaderFilterStrategy(org.apache.camel.impl.DefaultHeaderFilterStrategy) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Example 10 with DefaultHeaderFilterStrategy

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);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) InputStream(java.io.InputStream) DefaultHeaderFilterStrategy(org.apache.camel.impl.DefaultHeaderFilterStrategy) Test(org.junit.Test)

Aggregations

DefaultHeaderFilterStrategy (org.apache.camel.impl.DefaultHeaderFilterStrategy)15 Test (org.junit.Test)14 DefaultExchange (org.apache.camel.impl.DefaultExchange)13 Exchange (org.apache.camel.Exchange)12 List (java.util.List)10 Message (org.apache.cxf.message.Message)8 TreeMap (java.util.TreeMap)6 MessageImpl (org.apache.cxf.message.MessageImpl)6 HashMap (java.util.HashMap)5 DataHandler (javax.activation.DataHandler)4 FileDataSource (javax.activation.FileDataSource)4 Attachment (org.apache.cxf.message.Attachment)4 HashSet (java.util.HashSet)2 Message (org.apache.camel.Message)2 DefaultMessage (org.apache.camel.impl.DefaultMessage)2 AttachmentImpl (org.apache.cxf.attachment.AttachmentImpl)2 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 CamelContext (org.apache.camel.CamelContext)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1