Search in sources :

Example 11 with DefaultHeaderFilterStrategy

use of org.apache.camel.impl.DefaultHeaderFilterStrategy in project camel by apache.

the class DefaultCxfBindingTest method testPopupalteExchangeFromCxfRequestWithHeaderMerged.

@Test
public void testPopupalteExchangeFromCxfRequestWithHeaderMerged() {
    DefaultCxfBinding cxfBinding = new DefaultCxfBinding();
    cxfBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy());
    Exchange exchange = new DefaultExchange(context);
    exchange.setProperty(CxfConstants.CAMEL_CXF_PROTOCOL_HEADERS_MERGED, Boolean.TRUE);
    org.apache.cxf.message.Exchange cxfExchange = new org.apache.cxf.message.ExchangeImpl();
    exchange.setProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.PAYLOAD);
    org.apache.cxf.message.Message cxfMessage = new org.apache.cxf.message.MessageImpl();
    Map<String, List<String>> headers = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
    headers.put("myfruitheader", Arrays.asList("peach"));
    headers.put("mybrewheader", Arrays.asList("cappuccino", "espresso"));
    cxfMessage.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, headers);
    cxfExchange.setInMessage(cxfMessage);
    cxfBinding.populateExchangeFromCxfRequest(cxfExchange, exchange);
    Map<String, Object> camelHeaders = exchange.getIn().getHeaders();
    assertNotNull(camelHeaders);
    assertEquals("peach", camelHeaders.get("MyFruitHeader"));
    assertEquals("cappuccino, espresso", camelHeaders.get("MyBrewHeader"));
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Message(org.apache.cxf.message.Message) DefaultHeaderFilterStrategy(org.apache.camel.impl.DefaultHeaderFilterStrategy) TreeMap(java.util.TreeMap) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) List(java.util.List) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 12 with DefaultHeaderFilterStrategy

use of org.apache.camel.impl.DefaultHeaderFilterStrategy in project camel by apache.

the class DefaultCxfBindingTest method testPopupalteExchangeFromCxfRequest.

@Test
public void testPopupalteExchangeFromCxfRequest() {
    DefaultCxfBinding cxfBinding = new DefaultCxfBinding();
    cxfBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy());
    Exchange exchange = new DefaultExchange(context);
    org.apache.cxf.message.Exchange cxfExchange = new org.apache.cxf.message.ExchangeImpl();
    exchange.setProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.PAYLOAD);
    org.apache.cxf.message.Message cxfMessage = new org.apache.cxf.message.MessageImpl();
    Map<String, List<String>> headers = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
    headers.put("content-type", Arrays.asList("text/xml;charset=UTF-8"));
    headers.put("Content-Length", Arrays.asList("241"));
    headers.put("soapAction", Arrays.asList("urn:hello:world"));
    headers.put("myfruitheader", Arrays.asList("peach"));
    headers.put("mybrewheader", Arrays.asList("cappuccino", "espresso"));
    cxfMessage.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, headers);
    Set<Attachment> attachments = new HashSet<Attachment>();
    AttachmentImpl attachment = new AttachmentImpl("att-1", new DataHandler(new FileDataSource("pom.xml")));
    attachment.setHeader("attachment-header", "value 1");
    attachments.add(attachment);
    cxfMessage.setAttachments(attachments);
    cxfExchange.setInMessage(cxfMessage);
    cxfBinding.populateExchangeFromCxfRequest(cxfExchange, exchange);
    Map<String, Object> camelHeaders = exchange.getIn().getHeaders();
    assertNotNull(camelHeaders);
    assertEquals("urn:hello:world", camelHeaders.get("soapaction"));
    assertEquals("urn:hello:world", camelHeaders.get("SoapAction"));
    assertEquals("text/xml;charset=UTF-8", camelHeaders.get("content-type"));
    assertEquals("241", camelHeaders.get("content-length"));
    assertEquals("peach", camelHeaders.get("MyFruitHeader"));
    assertEquals(Arrays.asList("cappuccino", "espresso"), camelHeaders.get("MyBrewHeader"));
    Map<String, org.apache.camel.Attachment> camelAttachments = exchange.getIn().getAttachmentObjects();
    assertNotNull(camelAttachments);
    assertNotNull(camelAttachments.get("att-1"));
    assertEquals("value 1", camelAttachments.get("att-1").getHeader("attachment-header"));
}
Also used : DefaultHeaderFilterStrategy(org.apache.camel.impl.DefaultHeaderFilterStrategy) Attachment(org.apache.cxf.message.Attachment) DataHandler(javax.activation.DataHandler) FileDataSource(javax.activation.FileDataSource) List(java.util.List) HashSet(java.util.HashSet) DefaultExchange(org.apache.camel.impl.DefaultExchange) Message(org.apache.cxf.message.Message) TreeMap(java.util.TreeMap) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) AttachmentImpl(org.apache.cxf.attachment.AttachmentImpl) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 13 with DefaultHeaderFilterStrategy

use of org.apache.camel.impl.DefaultHeaderFilterStrategy in project camel by apache.

the class DefaultCxfBindingTest method testPopupalteExchangeFromCxfResponseOfNullBody.

@Test
public void testPopupalteExchangeFromCxfResponseOfNullBody() {
    DefaultCxfBinding cxfBinding = new DefaultCxfBinding();
    cxfBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy());
    Exchange exchange = new DefaultExchange(context);
    org.apache.cxf.message.Exchange cxfExchange = new org.apache.cxf.message.ExchangeImpl();
    exchange.setProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.PAYLOAD);
    Map<String, Object> responseContext = new HashMap<String, Object>();
    responseContext.put(org.apache.cxf.message.Message.RESPONSE_CODE, Integer.valueOf(200));
    Map<String, List<String>> headers = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
    responseContext.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, headers);
    org.apache.cxf.message.Message cxfMessage = new org.apache.cxf.message.MessageImpl();
    cxfExchange.setInMessage(cxfMessage);
    cxfBinding.populateExchangeFromCxfResponse(exchange, cxfExchange, responseContext);
    CxfPayload<?> cxfPayload = exchange.getOut().getBody(CxfPayload.class);
    assertNotNull(cxfPayload);
    List<?> body = cxfPayload.getBody();
    assertNotNull(body);
    assertEquals(0, body.size());
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) HashMap(java.util.HashMap) Message(org.apache.cxf.message.Message) DefaultHeaderFilterStrategy(org.apache.camel.impl.DefaultHeaderFilterStrategy) TreeMap(java.util.TreeMap) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) List(java.util.List) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 14 with DefaultHeaderFilterStrategy

use of org.apache.camel.impl.DefaultHeaderFilterStrategy in project camel by apache.

the class DefaultCxfBindingTest method testPopulateCxfRequestFromExchange.

@Test
public void testPopulateCxfRequestFromExchange() {
    DefaultCxfBinding cxfBinding = new DefaultCxfBinding();
    cxfBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy());
    Exchange exchange = new DefaultExchange(context);
    org.apache.cxf.message.Exchange cxfExchange = new org.apache.cxf.message.ExchangeImpl();
    exchange.setProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.PAYLOAD);
    Map<String, Object> requestContext = new HashMap<String, Object>();
    exchange.getIn().setHeader("soapAction", "urn:hello:world");
    exchange.getIn().setHeader("MyFruitHeader", "peach");
    exchange.getIn().setHeader("MyBrewHeader", Arrays.asList("cappuccino", "espresso"));
    exchange.getIn().addAttachment("att-1", new DataHandler(new FileDataSource("pom.xml")));
    exchange.getIn().getAttachmentObject("att-1").setHeader("attachment-header", "value 1");
    cxfBinding.populateCxfRequestFromExchange(cxfExchange, exchange, requestContext);
    // check the protocol headers
    Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>) requestContext.get(Message.PROTOCOL_HEADERS));
    assertNotNull(headers);
    assertEquals(3, headers.size());
    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");
    verifyHeader(headers, "MyBrewHeader", Arrays.asList("cappuccino", "espresso"));
    Set<Attachment> attachments = CastUtils.cast((Set<?>) requestContext.get(CxfConstants.CAMEL_CXF_ATTACHMENTS));
    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) HashMap(java.util.HashMap) 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) FileDataSource(javax.activation.FileDataSource) List(java.util.List) Test(org.junit.Test)

Example 15 with DefaultHeaderFilterStrategy

use of org.apache.camel.impl.DefaultHeaderFilterStrategy in project camel by apache.

the class CxfHeaderHelperTest method testPropagateCxfToCamelWithMerged.

@Test
public void testPropagateCxfToCamelWithMerged() {
    Exchange exchange = new DefaultExchange(context);
    exchange.setProperty(CxfConstants.CAMEL_CXF_PROTOCOL_HEADERS_MERGED, Boolean.TRUE);
    org.apache.cxf.message.Message cxfMessage = new org.apache.cxf.message.MessageImpl();
    Map<String, List<String>> cxfHeaders = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
    cxfHeaders.put("myfruitheader", Arrays.asList("peach"));
    cxfHeaders.put("mybrewheader", Arrays.asList("cappuccino", "espresso"));
    cxfMessage.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, cxfHeaders);
    CxfHeaderHelper.propagateCxfToCamel(new DefaultHeaderFilterStrategy(), cxfMessage, exchange.getIn(), exchange);
    Map<String, Object> camelHeaders = exchange.getIn().getHeaders();
    assertEquals("peach", camelHeaders.get("MyFruitHeader"));
    assertEquals("cappuccino, espresso", camelHeaders.get("MyBrewHeader"));
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Message(org.apache.cxf.message.Message) DefaultHeaderFilterStrategy(org.apache.camel.impl.DefaultHeaderFilterStrategy) TreeMap(java.util.TreeMap) DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) List(java.util.List) 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