Search in sources :

Example 36 with Map

use of java.util.Map 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 37 with Map

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

the class CwComponentTest method setsMeticDimensions.

@Test
public void setsMeticDimensions() throws Exception {
    template.send("direct:start", ExchangePattern.InOnly, new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(CwConstants.METRIC_NAME, "errorCount");
            Map<String, String> dimensionsMap = new LinkedHashMap<String, String>();
            dimensionsMap.put("keyOne", "valueOne");
            dimensionsMap.put("keyTwo", "valueTwo");
            exchange.getIn().setHeader(CwConstants.METRIC_DIMENSIONS, dimensionsMap);
        }
    });
    ArgumentCaptor<PutMetricDataRequest> argument = ArgumentCaptor.forClass(PutMetricDataRequest.class);
    verify(cloudWatchClient).putMetricData(argument.capture());
    List<Dimension> dimensions = argument.getValue().getMetricData().get(0).getDimensions();
    Dimension dimension = dimensions.get(0);
    assertThat(dimensions.size(), is(2));
    assertEquals("keyOne", dimension.getName());
    assertEquals("valueOne", dimension.getValue());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) PutMetricDataRequest(com.amazonaws.services.cloudwatch.model.PutMetricDataRequest) Dimension(com.amazonaws.services.cloudwatch.model.Dimension) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.Test)

Example 38 with Map

use of java.util.Map 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 39 with Map

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

the class BindyKeyValuePairDataFormat method marshal.

@SuppressWarnings("unchecked")
public void marshal(Exchange exchange, Object body, OutputStream outputStream) throws Exception {
    final BindyAbstractFactory factory = getFactory();
    final byte[] crlf = ConverterUtils.getByteReturn(factory.getCarriageReturn());
    final TypeConverter converter = exchange.getContext().getTypeConverter();
    // the body may not be a prepared list of map that bindy expects so help
    // a bit here and create one if needed
    final Iterator<Object> it = ObjectHelper.createIterator(body);
    while (it.hasNext()) {
        Object model = it.next();
        Map<String, Object> row;
        if (model instanceof Map) {
            row = (Map<String, Object>) model;
        } else {
            row = Collections.singletonMap(model.getClass().getName(), model);
        }
        String result = factory.unbind(row);
        outputStream.write(converter.convertTo(byte[].class, exchange, result));
        outputStream.write(crlf);
    }
}
Also used : TypeConverter(org.apache.camel.TypeConverter) BindyAbstractFactory(org.apache.camel.dataformat.bindy.BindyAbstractFactory) HashMap(java.util.HashMap) Map(java.util.Map)

Example 40 with Map

use of java.util.Map 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)

Aggregations

Map (java.util.Map)15646 HashMap (java.util.HashMap)9529 ArrayList (java.util.ArrayList)3619 List (java.util.List)2988 Test (org.junit.Test)2558 Set (java.util.Set)1837 HashSet (java.util.HashSet)1646 IOException (java.io.IOException)1486 Iterator (java.util.Iterator)1307 LinkedHashMap (java.util.LinkedHashMap)1284 TreeMap (java.util.TreeMap)1022 ImmutableMap (com.google.common.collect.ImmutableMap)879 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)729 File (java.io.File)662 Collection (java.util.Collection)576 Collectors (java.util.stream.Collectors)436 ConcurrentMap (java.util.concurrent.ConcurrentMap)375 LinkedList (java.util.LinkedList)333 SSOException (com.iplanet.sso.SSOException)294 Collections (java.util.Collections)288