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);
}
}
}
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());
}
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);
}
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);
}
}
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);
}
}
Aggregations