use of java.util.List 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 java.util.List in project camel by apache.
the class LoadDistributorFeatureTest method startRoute.
private void startRoute(DefaultCamelContext ctx, final String proxy, final String real) throws Exception {
ctx.addRoutes(new RouteBuilder() {
public void configure() {
List<String> serviceList = new ArrayList<String>();
serviceList.add(SERVICE_ADDRESS_1);
serviceList.add(SERVICE_ADDRESS_2);
SequentialStrategy strategy = new SequentialStrategy();
strategy.setAlternateAddresses(serviceList);
LoadDistributorFeature ldf = new LoadDistributorFeature();
ldf.setStrategy(strategy);
CxfEndpoint endpoint = (CxfEndpoint) (endpoint(real));
endpoint.getFeatures().add(ldf);
from(proxy).to(endpoint);
}
});
ctx.start();
}
use of java.util.List 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 java.util.List in project camel by apache.
the class CxfRsConsumerSimpleBindingTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() {
from(CXF_RS_ENDPOINT_URI).recipientList(simple("direct:${header.operationName}"));
from("direct:getCustomer").process(new Processor() {
public void process(Exchange exchange) throws Exception {
assertNotNull(exchange.getIn().getHeader("id"));
long id = exchange.getIn().getHeader("id", Long.class);
if (id == 123) {
assertEquals("123", exchange.getIn().getHeader("id"));
assertEquals(MessageContentsList.class, exchange.getIn().getBody().getClass());
exchange.getOut().setBody(new Customer(123, "Raul"));
exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 200);
} else if (id == 456) {
exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 404);
} else {
fail();
}
}
});
from("direct:updateCustomer").process(new Processor() {
public void process(Exchange exchange) throws Exception {
assertEquals("123", exchange.getIn().getHeader("id"));
Customer c = exchange.getIn().getBody(Customer.class);
assertEquals(123, c.getId());
assertNotNull(c);
}
});
from("direct:newCustomer").process(new Processor() {
public void process(Exchange exchange) throws Exception {
Customer c = exchange.getIn().getBody(Customer.class);
assertNotNull(c);
assertEquals(123, c.getId());
}
});
from("direct:listVipCustomers").process(new Processor() {
public void process(Exchange exchange) throws Exception {
assertEquals("gold", exchange.getIn().getHeader("status", String.class));
assertEquals(MessageContentsList.class, exchange.getIn().getBody().getClass());
assertEquals(0, exchange.getIn().getBody(MessageContentsList.class).size());
CustomerList response = new CustomerList();
List<Customer> list = new ArrayList<Customer>(2);
list.add(new Customer(123, "Raul"));
list.add(new Customer(456, "Raul2"));
response.setCustomers(list);
exchange.getOut().setBody(response);
}
});
from("direct:updateVipCustomer").process(new Processor() {
public void process(Exchange exchange) throws Exception {
assertEquals("gold", exchange.getIn().getHeader("status", String.class));
assertEquals("123", exchange.getIn().getHeader("id"));
Customer c = exchange.getIn().getBody(Customer.class);
assertEquals(123, c.getId());
assertNotNull(c);
}
});
from("direct:deleteVipCustomer").process(new Processor() {
public void process(Exchange exchange) throws Exception {
assertEquals("gold", exchange.getIn().getHeader("status", String.class));
assertEquals("123", exchange.getIn().getHeader("id"));
}
});
from("direct:uploadImageInputStream").process(new Processor() {
public void process(Exchange exchange) throws Exception {
assertEquals("123", exchange.getIn().getHeader("id"));
assertEquals("image/jpeg", exchange.getIn().getHeader("Content-Type"));
assertTrue(InputStream.class.isAssignableFrom(exchange.getIn().getBody().getClass()));
InputStream is = exchange.getIn().getBody(InputStream.class);
is.close();
exchange.getOut().setBody(null);
}
});
from("direct:uploadImageDataHandler").process(new Processor() {
public void process(Exchange exchange) throws Exception {
assertEquals("123", exchange.getIn().getHeader("id"));
assertEquals("image/jpeg", exchange.getIn().getHeader("Content-Type"));
assertTrue(DataHandler.class.isAssignableFrom(exchange.getIn().getBody().getClass()));
DataHandler dh = exchange.getIn().getBody(DataHandler.class);
assertEquals("image/jpeg", dh.getContentType());
dh.getInputStream().close();
exchange.getOut().setBody(null);
}
});
from("direct:multipartPostWithParametersAndPayload").process(new Processor() {
public void process(Exchange exchange) throws Exception {
assertEquals("abcd", exchange.getIn().getHeader("query"));
assertEquals("123", exchange.getIn().getHeader("id"));
assertNotNull(exchange.getIn().getAttachment("part1"));
assertNotNull(exchange.getIn().getAttachment("part2"));
assertNull(exchange.getIn().getHeader("part1"));
assertNull(exchange.getIn().getHeader("part2"));
assertEquals(Customer.class, exchange.getIn().getHeader("body").getClass());
exchange.getOut().setBody(null);
}
});
from("direct:multipartPostWithoutParameters").process(new Processor() {
public void process(Exchange exchange) throws Exception {
assertNotNull(exchange.getIn().getAttachment("part1"));
assertNotNull(exchange.getIn().getAttachment("part2"));
assertNull(exchange.getIn().getHeader("part1"));
assertNull(exchange.getIn().getHeader("part2"));
assertEquals(Customer.class, exchange.getIn().getHeader("body").getClass());
exchange.getOut().setBody(null);
}
});
}
};
}
use of java.util.List in project camel by apache.
the class HeaderTesterWithInsertionImpl method validateOutOfBandHander.
@Override
protected boolean validateOutOfBandHander() {
MessageContext ctx = context == null ? null : context.getMessageContext();
if (!relayHeaders) {
if (ctx != null && !ctx.containsKey(Header.HEADER_LIST) || (ctx.containsKey(Header.HEADER_LIST) && ((List<?>) ctx.get(Header.HEADER_LIST)).size() == 0)) {
return true;
}
return false;
}
boolean success = false;
if (ctx != null && ctx.containsKey(Header.HEADER_LIST)) {
List<Header> oobHdr = CastUtils.cast((List<?>) ctx.get(Header.HEADER_LIST));
if (oobHdr.size() != 2) {
throw new RuntimeException("test failed expected 2 soap headers but found " + oobHdr.size());
}
verifyHeader(oobHdr.get(0), "testOobHeader", "testOobHeaderValue");
verifyHeader(oobHdr.get(1), "New_testOobHeader", "New_testOobHeaderValue");
oobHdr.clear();
success = true;
} else {
throw new RuntimeException("MessageContext is null or doesnot contain OOBHeaders");
}
return success;
}
Aggregations