Search in sources :

Example 76 with IOException

use of java.io.IOException in project camel by apache.

the class AbstractGoogleDriveTestSupport method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    final InputStream in = getClass().getResourceAsStream(TEST_OPTIONS_PROPERTIES);
    if (in == null) {
        throw new IOException(TEST_OPTIONS_PROPERTIES + " could not be found");
    }
    final StringBuilder builder = new StringBuilder();
    final BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
    String line;
    while ((line = reader.readLine()) != null) {
        builder.append(line).append(LINE_SEPARATOR);
    }
    propertyText = builder.toString();
    final Properties properties = new Properties();
    try {
        properties.load(new StringReader(propertyText));
    } catch (IOException e) {
        throw new IOException(String.format("%s could not be loaded: %s", TEST_OPTIONS_PROPERTIES, e.getMessage()), e);
    }
    //
    //        // cache test properties
    //        refreshToken = properties.getProperty(REFRESH_TOKEN_PROPERTY);
    //        testFolderId = properties.getProperty("testFolderId");
    //        testFileId = properties.getProperty("testFileId");
    //        testUserId = properties.getProperty("testUserId");
    //
    Map<String, Object> options = new HashMap<String, Object>();
    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
        options.put(entry.getKey().toString(), entry.getValue());
    }
    final GoogleDriveConfiguration configuration = new GoogleDriveConfiguration();
    IntrospectionSupport.setProperties(configuration, options);
    // add GoogleDriveComponent  to Camel context
    final CamelContext context = super.createCamelContext();
    final GoogleDriveComponent component = new GoogleDriveComponent(context);
    component.setConfiguration(configuration);
    context.addComponent("google-drive", component);
    return context;
}
Also used : CamelContext(org.apache.camel.CamelContext) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) HashMap(java.util.HashMap) Map(java.util.Map)

Example 77 with IOException

use of java.io.IOException in project camel by apache.

the class HawtDBAggregationRepository method confirm.

public void confirm(final CamelContext camelContext, final String exchangeId) {
    LOG.debug("Confirming exchangeId [{}]", exchangeId);
    try {
        final Buffer confirmKeyBuffer = codec.marshallKey(exchangeId);
        hawtDBFile.execute(new Work<Buffer>() {

            public Buffer execute(Transaction tx) {
                SortedIndex<Buffer, Buffer> indexCompleted = hawtDBFile.getRepositoryIndex(tx, getRepositoryNameCompleted(), true);
                Buffer buffer = indexCompleted.remove(confirmKeyBuffer);
                LOG.trace("Removed confirm index {} -> {}", confirmKeyBuffer, buffer);
                return buffer;
            }

            @Override
            public String toString() {
                return "Confirming exchangeId [" + exchangeId + "]";
            }
        });
    } catch (IOException e) {
        throw new RuntimeException("Error confirming exchangeId " + exchangeId + " from repository " + repositoryName, e);
    }
}
Also used : Buffer(org.fusesource.hawtbuf.Buffer) Transaction(org.fusesource.hawtdb.api.Transaction) SortedIndex(org.fusesource.hawtdb.api.SortedIndex) IOException(java.io.IOException)

Example 78 with IOException

use of java.io.IOException in project camel by apache.

the class HawtDBAggregationRepository method recover.

public Exchange recover(CamelContext camelContext, final String exchangeId) {
    Exchange answer = null;
    try {
        final Buffer confirmKeyBuffer = codec.marshallKey(exchangeId);
        Buffer rc = hawtDBFile.execute(new Work<Buffer>() {

            public Buffer execute(Transaction tx) {
                SortedIndex<Buffer, Buffer> indexCompleted = hawtDBFile.getRepositoryIndex(tx, getRepositoryNameCompleted(), false);
                if (indexCompleted == null) {
                    return null;
                }
                return indexCompleted.get(confirmKeyBuffer);
            }

            @Override
            public String toString() {
                return "Recovering exchangeId [" + exchangeId + "]";
            }
        });
        if (rc != null) {
            answer = codec.unmarshallExchange(camelContext, rc);
        }
    } catch (IOException e) {
        throw new RuntimeException("Error recovering exchangeId " + exchangeId + " from repository " + repositoryName, e);
    }
    LOG.debug("Recovering exchangeId [{}] -> {}", exchangeId, answer);
    return answer;
}
Also used : Exchange(org.apache.camel.Exchange) Buffer(org.fusesource.hawtbuf.Buffer) Transaction(org.fusesource.hawtdb.api.Transaction) SortedIndex(org.fusesource.hawtdb.api.SortedIndex) IOException(java.io.IOException)

Example 79 with IOException

use of java.io.IOException in project camel by apache.

the class HawtDBAggregationRepository method doAdd.

protected Exchange doAdd(final CamelContext camelContext, final String key, final Exchange exchange, final boolean handleOptimisticLockingException) {
    LOG.debug("Adding key [{}] -> {}", key, exchange);
    try {
        // If we could guarantee that the key and exchange are immutable,
        // then we could have stuck them directly into the index, 
        // HawtDB could then eliminate the need to marshal and un-marshal  
        // in some cases.  But since we can't.. we are going to force
        // early marshaling.
        final Buffer keyBuffer = codec.marshallKey(key);
        final Buffer exchangeBuffer = codec.marshallExchange(camelContext, exchange, allowSerializedHeaders);
        Buffer rc = hawtDBFile.execute(new Work<Buffer>() {

            public Buffer execute(Transaction tx) {
                SortedIndex<Buffer, Buffer> index = hawtDBFile.getRepositoryIndex(tx, repositoryName, true);
                Buffer buffer = index.put(keyBuffer, exchangeBuffer);
                LOG.trace("Added key index {}", keyBuffer);
                return buffer;
            }

            @Override
            public String toString() {
                return "Adding key [" + key + "]";
            }
        }, handleOptimisticLockingException);
        if (rc == null) {
            return null;
        }
        // only return old exchange if enabled
        if (isReturnOldExchange()) {
            return codec.unmarshallExchange(camelContext, rc);
        }
    } catch (IOException e) {
        throw new RuntimeException("Error adding to repository " + repositoryName + " with key " + key, e);
    }
    return null;
}
Also used : Buffer(org.fusesource.hawtbuf.Buffer) Transaction(org.fusesource.hawtdb.api.Transaction) SortedIndex(org.fusesource.hawtdb.api.SortedIndex) IOException(java.io.IOException)

Example 80 with IOException

use of java.io.IOException in project camel by apache.

the class HawtDBFile method stop.

public void stop() {
    File file = getFile();
    LOG.debug("Stopping HawtDB using file: {}", file);
    try {
        close();
    } catch (IOException e) {
        LOG.warn("Error closing HawtDB file " + file + ". This exception will be ignored.", e);
    }
    pageFile = null;
}
Also used : IOException(java.io.IOException) TxPageFile(org.fusesource.hawtdb.api.TxPageFile) 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