Search in sources :

Example 1 with List

use of java.util.List in project camel by apache.

the class CassandraComponentConsumerTest method testConsumeAll.

@Test
public void testConsumeAll() throws Exception {
    if (!canTest()) {
        return;
    }
    MockEndpoint mock = getMockEndpoint("mock:resultAll");
    mock.expectedMinimumMessageCount(1);
    mock.whenAnyExchangeReceived(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            Object body = exchange.getIn().getBody();
            assertTrue(body instanceof List);
        }
    });
    mock.await(1, TimeUnit.SECONDS);
    assertMockEndpointsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) List(java.util.List) Test(org.junit.Test)

Example 2 with List

use of java.util.List in project camel by apache.

the class CxfClientCallback method handleException.

public void handleException(Map<String, Object> ctx, Throwable ex) {
    try {
        super.handleException(ctx, ex);
        // need to call the conduitSelector complete method to enable the fail over feature
        ConduitSelector conduitSelector = cxfExchange.get(ConduitSelector.class);
        if (conduitSelector != null) {
            conduitSelector.complete(cxfExchange);
            ex = cxfExchange.getOutMessage().getContent(Exception.class);
            if (ex == null && cxfExchange.getInMessage() != null) {
                ex = cxfExchange.getInMessage().getContent(Exception.class);
            }
            if (ex != null) {
                camelExchange.setException(ex);
            }
        } else {
            camelExchange.setException(ex);
        }
    } finally {
        // add cookies to the cookie store
        if (endpoint.getCookieHandler() != null) {
            try {
                Map<String, List<String>> cxfHeaders = CastUtils.cast((Map<?, ?>) cxfExchange.getInMessage().get(Message.PROTOCOL_HEADERS));
                endpoint.getCookieHandler().storeCookies(camelExchange, endpoint.getRequestUri(camelExchange), cxfHeaders);
            } catch (IOException e) {
                LOG.error("Cannot store cookies", e);
            }
        }
        // process method of org.apache.camel.component.cxf.CxfProducer
        if (!boi.getOperationInfo().isOneWay()) {
            endpoint.getCxfBinding().populateExchangeFromCxfResponse(camelExchange, cxfExchange, ctx);
            camelAsyncCallback.done(false);
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("{} calling handleException", Thread.currentThread().getName());
        }
    }
}
Also used : List(java.util.List) IOException(java.io.IOException) ConduitSelector(org.apache.cxf.endpoint.ConduitSelector) IOException(java.io.IOException)

Example 3 with List

use of java.util.List in project camel by apache.

the class CxfHeaderHelperTest method testPropagateCamelToCxf.

@Test
public void testPropagateCamelToCxf() {
    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setHeader("soapAction", "urn:hello:world");
    exchange.getIn().setHeader("MyFruitHeader", "peach");
    exchange.getIn().setHeader("MyBrewHeader", Arrays.asList("cappuccino", "espresso"));
    exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "text/xml");
    exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, "200");
    exchange.getIn().setHeader(Exchange.HTTP_URI, "/hello/cxf");
    exchange.getIn().setHeader(Exchange.HTTP_METHOD, "GET");
    exchange.getIn().setHeader(Exchange.HTTP_PATH, "/hello/cxf");
    Map<String, Object> requestContext = Collections.singletonMap("request", "true");
    Map<String, Object> responseContext = Collections.singletonMap("response", "true");
    exchange.getIn().setHeader(Client.REQUEST_CONTEXT, requestContext);
    exchange.getIn().setHeader(Client.RESPONSE_CONTEXT, responseContext);
    org.apache.cxf.message.Message cxfMessage = new org.apache.cxf.message.MessageImpl();
    CxfHeaderHelper.propagateCamelToCxf(new DefaultHeaderFilterStrategy(), exchange.getIn().getHeaders(), cxfMessage, exchange);
    assertEquals("text/xml", cxfMessage.get(Message.CONTENT_TYPE));
    assertEquals("200", cxfMessage.get(Message.RESPONSE_CODE));
    assertEquals(requestContext, cxfMessage.get(Client.REQUEST_CONTEXT));
    assertEquals(responseContext, cxfMessage.get(Client.RESPONSE_CONTEXT));
    assertNull(cxfMessage.get(Exchange.HTTP_RESPONSE_CODE));
    // check the protocol headers
    Map<String, List<String>> cxfHeaders = CastUtils.cast((Map<?, ?>) cxfMessage.get(org.apache.cxf.message.Message.PROTOCOL_HEADERS));
    assertNotNull(cxfHeaders);
    assertTrue(cxfHeaders.size() == 7);
    verifyHeader(cxfHeaders, "soapaction", "urn:hello:world");
    verifyHeader(cxfHeaders, "SoapAction", "urn:hello:world");
    verifyHeader(cxfHeaders, "SOAPAction", "urn:hello:world");
    verifyHeader(cxfHeaders, "myfruitheader", "peach");
    verifyHeader(cxfHeaders, "myFruitHeader", "peach");
    verifyHeader(cxfHeaders, "MYFRUITHEADER", "peach");
    verifyHeader(cxfHeaders, "MyBrewHeader", Arrays.asList("cappuccino", "espresso"));
    verifyHeader(cxfHeaders, Message.CONTENT_TYPE, "text/xml");
    verifyHeader(cxfHeaders, Message.REQUEST_URI, "/hello/cxf");
    verifyHeader(cxfHeaders, Message.HTTP_REQUEST_METHOD, "GET");
    verifyHeader(cxfHeaders, Message.PATH_INFO, "/hello/cxf");
    assertNull(cxfHeaders.get(Exchange.HTTP_RESPONSE_CODE));
    assertNull(cxfHeaders.get(Exchange.HTTP_URI));
    assertNull(cxfHeaders.get(Exchange.HTTP_METHOD));
    assertNull(cxfHeaders.get(Exchange.HTTP_PATH));
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Message(org.apache.cxf.message.Message) DefaultHeaderFilterStrategy(org.apache.camel.impl.DefaultHeaderFilterStrategy) DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) List(java.util.List) Test(org.junit.Test)

Example 4 with List

use of java.util.List in project camel by apache.

the class CsvRouteTest method testUnMarshal.

@SuppressWarnings("unchecked")
@Test
public void testUnMarshal() throws Exception {
    MockEndpoint endpoint = getMockEndpoint("mock:daltons");
    endpoint.expectedMessageCount(1);
    endpoint.assertIsSatisfied();
    Exchange exchange = endpoint.getExchanges().get(0);
    // START SNIPPET : unmarshalResult
    List<List<String>> data = (List<List<String>>) exchange.getIn().getBody();
    for (List<String> line : data) {
        LOG.debug(String.format("%s has an IQ of %s and is currently %s", line.get(0), line.get(1), line.get(2)));
    }
// END SNIPPET : unmarshalResult
}
Also used : Exchange(org.apache.camel.Exchange) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) List(java.util.List) Test(org.junit.Test)

Example 5 with List

use of java.util.List in project camel by apache.

the class CsvUnmarshalStreamSpringTest method testCsvUnMarshal.

@Test
public void testCsvUnMarshal() throws Exception {
    line.expectedMessageCount(3);
    template.sendBody("direct:start", CSV_SAMPLE);
    assertMockEndpointsSatisfied();
    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);
}
Also used : List(java.util.List) Test(org.junit.Test)

Aggregations

List (java.util.List)19204 ArrayList (java.util.ArrayList)12470 Test (org.junit.Test)4025 HashMap (java.util.HashMap)3622 Map (java.util.Map)3242 IOException (java.io.IOException)1670 Iterator (java.util.Iterator)1563 LinkedList (java.util.LinkedList)1336 HashSet (java.util.HashSet)1189 Set (java.util.Set)1151 File (java.io.File)921 ImmutableList (com.google.common.collect.ImmutableList)826 Collectors (java.util.stream.Collectors)784 LinkedHashMap (java.util.LinkedHashMap)540 Test (org.testng.annotations.Test)527 Session (org.hibernate.Session)521 Collection (java.util.Collection)496 Collections (java.util.Collections)474 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)471 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)453