use of java.io.IOException 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.io.IOException in project camel by apache.
the class IOHelperTest method testIOException.
public void testIOException() {
IOException io = new IOException("Damn", new IllegalArgumentException("Damn"));
assertEquals("Damn", io.getMessage());
assertTrue(io.getCause() instanceof IllegalArgumentException);
}
use of java.io.IOException in project camel by apache.
the class MessageHelperTest method testResetStreamCache.
/*
* Tests the {@link MessageHelper#resetStreamCache(Message)} method
*/
public void testResetStreamCache() throws Exception {
// should not throw exceptions when Message or message body is null
MessageHelper.resetStreamCache(null);
MessageHelper.resetStreamCache(message);
// handle StreamCache
final ValueHolder<Boolean> reset = new ValueHolder<Boolean>(Boolean.FALSE);
message.setBody(new StreamCache() {
@SuppressWarnings("deprecation")
public void reset() {
reset.set(Boolean.TRUE);
}
public void writeTo(OutputStream os) throws IOException {
// noop
}
public StreamCache copy(Exchange exchange) throws IOException {
return null;
}
public boolean inMemory() {
return true;
}
@Override
public long length() {
return 0;
}
});
MessageHelper.resetStreamCache(message);
assertTrue("Should have reset the stream cache", reset.get());
}
use of java.io.IOException in project camel by apache.
the class AbstractBraintreeTestSupport method createCamelContext.
@Override
protected CamelContext createCamelContext() throws Exception {
final CamelContext context = super.createCamelContext();
// read Braintree component configuration from TEST_OPTIONS_PROPERTIES
final Properties properties = new Properties();
try {
properties.load(getClass().getResourceAsStream(TEST_OPTIONS_PROPERTIES));
} catch (Exception e) {
throw new IOException(String.format("%s could not be loaded: %s", TEST_OPTIONS_PROPERTIES, e.getMessage()), e);
}
Map<String, Object> options = new HashMap<>();
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
options.put(entry.getKey().toString(), entry.getValue());
}
addOptionIfMissing(options, "environment", "CAMEL_BRAINTREE_ENVIRONMENT");
addOptionIfMissing(options, "merchantId", "CAMEL_BRAINTREE_MERCHANT_ID");
addOptionIfMissing(options, "publicKey", "CAMEL_BRAINTREE_PUBLIC_KEY");
addOptionIfMissing(options, "privateKey", "CAMEL_BRAINTREE_PRIVATE_KEY");
final BraintreeConfiguration configuration = new BraintreeConfiguration();
configuration.setHttpLogLevel(BraintreeLogHandler.DEFAULT_LOGGER_VERSION);
configuration.setHttpLogName(BraintreeLogHandler.DEFAULT_LOGGER_NAME);
IntrospectionSupport.setProperties(configuration, options);
// add BraintreeComponent to Camel context
final BraintreeComponent component = new BraintreeComponent(context);
component.setConfiguration(configuration);
context.addComponent("braintree", component);
return context;
}
use of java.io.IOException in project camel by apache.
the class AbstractGitConsumer method getLocalRepository.
private Repository getLocalRepository() throws IOException {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repo = null;
try {
repo = // scan environment GIT_* variables
builder.setGitDir(new File(endpoint.getLocalPath(), ".git")).readEnvironment().findGitDir().build();
} catch (IOException e) {
LOG.error("There was an error, cannot open " + endpoint.getLocalPath() + " repository");
throw e;
}
return repo;
}
Aggregations