Search in sources :

Example 71 with IOException

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);
        }
    }
}
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 72 with IOException

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);
}
Also used : IOException(java.io.IOException)

Example 73 with IOException

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());
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) StreamCache(org.apache.camel.StreamCache) OutputStream(java.io.OutputStream) IOException(java.io.IOException)

Example 74 with IOException

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;
}
Also used : CamelContext(org.apache.camel.CamelContext) HashMap(java.util.HashMap) IOException(java.io.IOException) Properties(java.util.Properties) HashMap(java.util.HashMap) Map(java.util.Map) CamelExecutionException(org.apache.camel.CamelExecutionException) IOException(java.io.IOException)

Example 75 with IOException

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;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) IOException(java.io.IOException) FileRepositoryBuilder(org.eclipse.jgit.storage.file.FileRepositoryBuilder) File(java.io.File)

Aggregations

IOException (java.io.IOException)41104 File (java.io.File)7663 InputStream (java.io.InputStream)4105 Test (org.junit.Test)3557 ArrayList (java.util.ArrayList)3023 FileInputStream (java.io.FileInputStream)2674 FileOutputStream (java.io.FileOutputStream)2358 FileNotFoundException (java.io.FileNotFoundException)2146 BufferedReader (java.io.BufferedReader)2028 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1761 InputStreamReader (java.io.InputStreamReader)1677 URL (java.net.URL)1608 HashMap (java.util.HashMap)1552 ByteArrayInputStream (java.io.ByteArrayInputStream)1534 OutputStream (java.io.OutputStream)1349 Path (org.apache.hadoop.fs.Path)1316 Map (java.util.Map)1212 List (java.util.List)1042 Properties (java.util.Properties)994 ServletException (javax.servlet.ServletException)916