Search in sources :

Example 51 with List

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

the class DefaultAhcBinding method populateCookieHeaders.

private void populateCookieHeaders(RequestBuilder builder, AhcEndpoint endpoint, Exchange exchange, URI uri) throws CamelExchangeException {
    if (endpoint.getCookieHandler() != null) {
        try {
            Map<String, List<String>> cookieHeaders = endpoint.getCookieHandler().loadCookies(exchange, uri);
            for (Map.Entry<String, List<String>> entry : cookieHeaders.entrySet()) {
                String key = entry.getKey();
                if (entry.getValue().size() > 0) {
                    // use the default toString of a ArrayList to create in the form [xxx, yyy]
                    // if multi valued, for a single value, then just output the value as is
                    String s = entry.getValue().size() > 1 ? entry.getValue().toString() : entry.getValue().get(0);
                    builder.addHeader(key, s);
                }
            }
        } catch (IOException e) {
            throw new CamelExchangeException("Error loading cookies", exchange, e);
        }
    }
}
Also used : CamelExchangeException(org.apache.camel.CamelExchangeException) List(java.util.List) IOException(java.io.IOException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 52 with List

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

the class AmazonDDBClientMock method batchGetItem.

@SuppressWarnings("unchecked")
@Override
public BatchGetItemResult batchGetItem(BatchGetItemRequest batchGetItemRequest) {
    this.batchGetItemRequest = batchGetItemRequest;
    Map<String, List<Map<String, AttributeValue>>> responseMap = new HashMap<String, List<Map<String, AttributeValue>>>();
    List<Map<String, AttributeValue>> p = new ArrayList<Map<String, AttributeValue>>();
    p.add(getAttributes());
    responseMap.put("DOMAIN1", p);
    Map<String, AttributeValue> keysMap = new HashMap<String, AttributeValue>();
    keysMap.put("1", new AttributeValue("UNPROCESSED_KEY"));
    Map<String, KeysAndAttributes> unprocessedKeys = new HashMap<String, KeysAndAttributes>();
    unprocessedKeys.put("DOMAIN1", new KeysAndAttributes().withKeys(keysMap));
    return new BatchGetItemResult().withResponses(responseMap).withUnprocessedKeys(unprocessedKeys);
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) BatchGetItemResult(com.amazonaws.services.dynamodbv2.model.BatchGetItemResult) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) KeysAndAttributes(com.amazonaws.services.dynamodbv2.model.KeysAndAttributes) HashMap(java.util.HashMap) Map(java.util.Map)

Example 53 with List

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

the class BindyKeyValuePairDataFormat method unmarshal.

public Object unmarshal(Exchange exchange, InputStream inputStream) throws Exception {
    BindyKeyValuePairFactory factory = (BindyKeyValuePairFactory) getFactory();
    // List of Pojos
    List<Map<String, Object>> models = new ArrayList<Map<String, Object>>();
    // Pojos of the model
    Map<String, Object> model;
    // Map to hold the model @OneToMany classes while binding
    Map<String, List<Object>> lists = new HashMap<String, List<Object>>();
    InputStreamReader in = new InputStreamReader(inputStream, IOHelper.getCharsetName(exchange));
    // Scanner is used to read big file
    Scanner scanner = new Scanner(in);
    // Retrieve the pair separator defined to split the record
    ObjectHelper.notNull(factory.getPairSeparator(), "The pair separator property of the annotation @Message");
    String separator = factory.getPairSeparator();
    int count = 0;
    try {
        while (scanner.hasNextLine()) {
            // Read the line
            String line = scanner.nextLine().trim();
            if (ObjectHelper.isEmpty(line)) {
                // skip if line is empty
                continue;
            }
            // Increment counter
            count++;
            // Create POJO
            model = factory.factory();
            // Split the message according to the pair separator defined in
            // annotated class @Message
            List<String> result = Arrays.asList(line.split(separator));
            if (result.size() == 0 || result.isEmpty()) {
                throw new java.lang.IllegalArgumentException("No records have been defined in the KVP");
            }
            if (result.size() > 0) {
                // Bind data from message with model classes
                // Counter is used to detect line where error occurs
                factory.bind(result, model, count, lists);
                // Link objects together
                factory.link(model);
                // Add objects graph to the list
                models.add(model);
                LOG.debug("Graph of objects created: {}", model);
            }
        }
        // If this is the case (correspond to an empty stream, ...)
        if (models.size() == 0) {
            throw new java.lang.IllegalArgumentException("No records have been defined in the CSV");
        } else {
            return extractUnmarshalResult(models);
        }
    } finally {
        scanner.close();
        IOHelper.close(in, "in", LOG);
    }
}
Also used : Scanner(java.util.Scanner) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BindyKeyValuePairFactory(org.apache.camel.dataformat.bindy.BindyKeyValuePairFactory) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 54 with List

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

the class GroovySumFilterTest method testSendNotMatchingMessage.

@Test
public void testSendNotMatchingMessage() throws Exception {
    getMockEndpoint("mock:high").expectedMessageCount(0);
    getMockEndpoint("mock:low").expectedMessageCount(1);
    List orders = new ArrayList();
    orders.add(new Order("Camel in Action", 50));
    orders.add(new Order("ActiveMQ in Action", 40));
    template.sendBody("direct:start", orders);
    assertMockEndpointsSatisfied();
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 55 with List

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

the class GsonMarshalListTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            GsonDataFormat formatPojo = new GsonDataFormat();
            Type genericType = new TypeToken<List<TestPojo>>() {
            }.getType();
            formatPojo.setUnmarshalGenericType(genericType);
            from("direct:inPojo").marshal(formatPojo);
            from("direct:backPojo").unmarshal(formatPojo).to("mock:reversePojo");
        }
    };
}
Also used : Type(java.lang.reflect.Type) RouteBuilder(org.apache.camel.builder.RouteBuilder) List(java.util.List) ArrayList(java.util.ArrayList)

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