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