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