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