Search in sources :

Example 11 with DefaultExchange

use of org.apache.camel.impl.DefaultExchange 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 12 with DefaultExchange

use of org.apache.camel.impl.DefaultExchange 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 13 with DefaultExchange

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

the class DefaultCxfRsBindingTest method testSetCharsetWithContentType.

@Test
public void testSetCharsetWithContentType() {
    DefaultCxfRsBinding cxfRsBinding = new DefaultCxfRsBinding();
    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "text/xml;charset=ISO-8859-1");
    cxfRsBinding.setCharsetWithContentType(exchange);
    String charset = IOHelper.getCharsetName(exchange);
    assertEquals("Get a wrong charset", "ISO-8859-1", charset);
    exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "text/xml");
    cxfRsBinding.setCharsetWithContentType(exchange);
    charset = IOHelper.getCharsetName(exchange);
    assertEquals("Get a worng charset name", "UTF-8", charset);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Test(org.junit.Test)

Example 14 with DefaultExchange

use of org.apache.camel.impl.DefaultExchange 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 15 with DefaultExchange

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

the class EhcacheAggregationRepositoryOperationTest method testConfirmExist.

@Test
public void testConfirmExist() {
    // Given
    for (int i = 1; i < 4; i++) {
        String key = "Confirm_" + i;
        Exchange exchange = new DefaultExchange(context());
        exchange.setExchangeId("Exchange_" + i);
        aggregationRepository.add(context(), key, exchange);
        assertTrue(exists(key));
    }
    // When
    aggregationRepository.confirm(context(), "Confirm_2");
    // Then
    assertTrue(exists("Confirm_1"));
    assertFalse(exists("Confirm_2"));
    assertTrue(exists("Confirm_3"));
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Test(org.junit.Test)

Aggregations

DefaultExchange (org.apache.camel.impl.DefaultExchange)473 Exchange (org.apache.camel.Exchange)381 Test (org.junit.Test)254 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)127 CamelContext (org.apache.camel.CamelContext)54 RegisteredDelivery (org.jsmpp.bean.RegisteredDelivery)39 HashMap (java.util.HashMap)33 Message (org.apache.camel.Message)32 Before (org.junit.Before)32 Tx (org.nhindirect.common.tx.model.Tx)31 ESMClass (org.jsmpp.bean.ESMClass)30 Processor (org.apache.camel.Processor)22 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)22 Expression (org.apache.camel.Expression)21 File (java.io.File)20 DefaultMessage (org.apache.camel.impl.DefaultMessage)20 ArrayList (java.util.ArrayList)18 ByteArrayInputStream (java.io.ByteArrayInputStream)17 URL (java.net.URL)16 Date (java.util.Date)16