use of java.util.List in project camel by apache.
the class CsvUnmarshalTest method shouldUseLazyLoading.
@Test
public void shouldUseLazyLoading() throws Exception {
line.expectedMessageCount(3);
template.sendBody("direct:lazy", CSV_SAMPLE);
line.assertIsSatisfied();
List body1 = line.getExchanges().get(0).getIn().getBody(List.class);
List body2 = line.getExchanges().get(1).getIn().getBody(List.class);
List body3 = line.getExchanges().get(2).getIn().getBody(List.class);
assertEquals(Arrays.asList("A", "B", "C"), body1);
assertEquals(Arrays.asList("1", "2", "3"), body2);
assertEquals(Arrays.asList("one", "two", "three"), body3);
}
use of java.util.List in project camel by apache.
the class DefaultCxfBinding method getContentFromCxf.
protected static Object getContentFromCxf(Message message, DataFormat dataFormat, String encoding) {
Set<Class<?>> contentFormats = message.getContentFormats();
Object answer = null;
if (contentFormats != null) {
if (LOG.isTraceEnabled()) {
for (Class<?> contentFormat : contentFormats) {
LOG.trace("Content format={} value={}", contentFormat, message.getContent(contentFormat));
}
}
if (dataFormat == DataFormat.POJO) {
answer = message.getContent(List.class);
if (answer == null) {
answer = message.getContent(Object.class);
if (answer != null) {
answer = new MessageContentsList(answer);
}
}
} else if (dataFormat == DataFormat.PAYLOAD) {
List<SoapHeader> headers = CastUtils.cast((List<?>) message.get(Header.HEADER_LIST));
Map<String, String> nsMap = new HashMap<String, String>();
answer = new CxfPayload<SoapHeader>(headers, getPayloadBodyElements(message, nsMap), nsMap);
} else if (dataFormat.dealias() == DataFormat.RAW) {
answer = message.getContent(InputStream.class);
if (answer == null) {
answer = message.getContent(Reader.class);
if (answer != null) {
if (encoding == null) {
encoding = "UTF-8";
}
LOG.trace("file encoding is = {}", encoding);
answer = new ReaderInputStream((Reader) answer, Charset.forName(encoding));
}
}
} else if (dataFormat.dealias() == DataFormat.CXF_MESSAGE && message.getContent(List.class) != null) {
// CAMEL-6404 added check point of message content
// The message content of list could be null if there is a fault message is received
answer = message.getContent(List.class).get(0);
}
LOG.trace("Extracted body from CXF message = {}", answer);
}
return answer;
}
use of java.util.List in project camel by apache.
the class CxfHeaderHelperTest method testPropagateCxfToCamel.
@Test
public void testPropagateCxfToCamel() {
Exchange exchange = new DefaultExchange(context);
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("Content-Length", Arrays.asList("241"));
cxfHeaders.put("soapAction", Arrays.asList("urn:hello:world"));
cxfHeaders.put("myfruitheader", Arrays.asList("peach"));
cxfHeaders.put("mybrewheader", Arrays.asList("cappuccino", "espresso"));
cxfHeaders.put(Message.CONTENT_TYPE, Arrays.asList("text/xml"));
cxfHeaders.put(Message.ENCODING, Arrays.asList("UTF-8"));
// Ignored
cxfHeaders.put(Message.RESPONSE_CODE, Arrays.asList("201"));
cxfHeaders.put(Message.REQUEST_URI, Arrays.asList("/base/hello/cxf"));
cxfHeaders.put(Message.HTTP_REQUEST_METHOD, Arrays.asList("GET"));
cxfHeaders.put(Message.PATH_INFO, Arrays.asList("/base/hello/cxf"));
cxfHeaders.put(Message.BASE_PATH, Arrays.asList("/base"));
cxfMessage.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, cxfHeaders);
cxfMessage.put(Message.RESPONSE_CODE, "200");
Map<String, Object> requestContext = Collections.singletonMap("request", "true");
Map<String, Object> responseContext = Collections.singletonMap("response", "true");
cxfMessage.put(Client.REQUEST_CONTEXT, requestContext);
cxfMessage.put(Client.RESPONSE_CONTEXT, responseContext);
CxfHeaderHelper.propagateCxfToCamel(new DefaultHeaderFilterStrategy(), cxfMessage, exchange.getIn(), exchange);
Map<String, Object> camelHeaders = exchange.getIn().getHeaders();
assertEquals("urn:hello:world", camelHeaders.get("soapaction"));
assertEquals("urn:hello:world", camelHeaders.get("SoapAction"));
assertEquals("241", camelHeaders.get("content-length"));
assertEquals("peach", camelHeaders.get("MyFruitHeader"));
assertEquals(Arrays.asList("cappuccino", "espresso"), camelHeaders.get("MyBrewHeader"));
assertEquals("text/xml; charset=UTF-8", camelHeaders.get(Exchange.CONTENT_TYPE));
assertEquals("/base/hello/cxf", camelHeaders.get(Exchange.HTTP_URI));
assertEquals("GET", camelHeaders.get(Exchange.HTTP_METHOD));
assertEquals("/hello/cxf", camelHeaders.get(Exchange.HTTP_PATH));
assertEquals("200", camelHeaders.get(Exchange.HTTP_RESPONSE_CODE));
assertEquals(requestContext, camelHeaders.get(Client.REQUEST_CONTEXT));
assertEquals(responseContext, camelHeaders.get(Client.RESPONSE_CONTEXT));
assertNull(camelHeaders.get(Message.RESPONSE_CODE));
assertNull(camelHeaders.get(Message.REQUEST_URI));
assertNull(camelHeaders.get(Message.HTTP_REQUEST_METHOD));
assertNull(camelHeaders.get(Message.PATH_INFO));
assertNull(camelHeaders.get(Message.RESPONSE_CODE));
}
use of java.util.List in project camel by apache.
the class CxfMessageHelperTest method testGetCxfInMessage.
// setup the default context for testing
@Test
public void testGetCxfInMessage() throws Exception {
HeaderFilterStrategy headerFilterStrategy = new CxfHeaderFilterStrategy();
org.apache.camel.Exchange exchange = new DefaultExchange(context);
// String
exchange.getIn().setBody("hello world");
org.apache.cxf.message.Message message = CxfMessageHelper.getCxfInMessage(headerFilterStrategy, exchange, false);
// test message
InputStream is = message.getContent(InputStream.class);
assertNotNull("The input stream should not be null", is);
assertEquals("Don't get the right message", toString(is), "hello world");
// DOMSource
URL request = this.getClass().getResource("RequestBody.xml");
File requestFile = new File(request.toURI());
FileInputStream inputStream = new FileInputStream(requestFile);
XMLStreamReader xmlReader = StaxUtils.createXMLStreamReader(inputStream);
DOMSource source = new DOMSource(StaxUtils.read(xmlReader));
exchange.getIn().setBody(source);
message = CxfMessageHelper.getCxfInMessage(headerFilterStrategy, exchange, false);
is = message.getContent(InputStream.class);
assertNotNull("The input stream should not be null", is);
assertEquals("Don't get the right message", toString(is), REQUEST_STRING);
// File
exchange.getIn().setBody(requestFile);
message = CxfMessageHelper.getCxfInMessage(headerFilterStrategy, exchange, false);
is = message.getContent(InputStream.class);
assertNotNull("The input stream should not be null", is);
assertEquals("Don't get the right message", toString(is), REQUEST_STRING);
// transport header's case insensitiveness
// String
exchange.getIn().setBody("hello world");
exchange.getIn().setHeader("soapAction", "urn:hello:world");
message = CxfMessageHelper.getCxfInMessage(headerFilterStrategy, exchange, false);
// test message
Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS));
// verify there is no duplicate
assertNotNull("The headers must be present", headers);
assertTrue("There must be one header entry", headers.size() == 1);
// verify the soapaction can be retrieved in case-insensitive ways
verifyHeader(headers, "soapaction", "urn:hello:world");
verifyHeader(headers, "SoapAction", "urn:hello:world");
verifyHeader(headers, "SOAPAction", "urn:hello:world");
}
use of java.util.List in project camel by apache.
the class CsvDataFormatCustomRecordConverterTest method unmarshalTest.
@Test
public void unmarshalTest() throws InterruptedException {
MockEndpoint mock = getMockEndpoint("mock:unmarshaled");
mock.expectedMessageCount(1);
template.sendBody("direct:unmarshal", getData());
mock.assertIsSatisfied();
Message message = mock.getReceivedExchanges().get(0).getIn();
List<List<String>> body = CastUtils.cast((List) message.getBody());
assertNotNull(body);
assertEquals(body.size(), 1);
List<String> row = body.get(0);
assertEquals(row.size(), 3);
assertEquals(row.toString(), "[Hello, Again, Democracy]");
}
Aggregations