use of java.io.IOException in project camel by apache.
the class DefaultPackageScanClassResolver method doLoadJarClassEntries.
/**
* Loads all the class entries from the JAR.
*
* @param stream the inputstream of the jar file to be examined for classes
* @param urlPath the url of the jar file to be examined for classes
* @return all the .class entries from the JAR
*/
protected List<String> doLoadJarClassEntries(InputStream stream, String urlPath) {
List<String> entries = new ArrayList<String>();
JarInputStream jarStream = null;
try {
jarStream = new JarInputStream(stream);
JarEntry entry;
while ((entry = jarStream.getNextJarEntry()) != null) {
String name = entry.getName();
if (name != null) {
name = name.trim();
if (!entry.isDirectory() && name.endsWith(".class")) {
entries.add(name);
}
}
}
} catch (IOException ioe) {
log.warn("Cannot search jar file '" + urlPath + " due to an IOException: " + ioe.getMessage(), ioe);
} finally {
IOHelper.close(jarStream, urlPath, log);
}
return entries;
}
use of java.io.IOException in project camel by apache.
the class FileIdempotentRepository method appendToStore.
/**
* Appends the given message id to the file store
*
* @param messageId the message id
*/
protected void appendToStore(final String messageId) {
LOG.debug("Appending {} to idempotent filestore: {}", messageId, fileStore);
FileOutputStream fos = null;
try {
// create store parent directory if missing
File storeParentDirectory = fileStore.getParentFile();
if (storeParentDirectory != null && !storeParentDirectory.exists()) {
LOG.info("Parent directory of file store {} doesn't exist. Creating.", fileStore);
if (fileStore.getParentFile().mkdirs()) {
LOG.info("Parent directory of file store {} successfully created.", fileStore);
} else {
LOG.warn("Parent directory of file store {} cannot be created.", fileStore);
}
}
// create store if missing
if (!fileStore.exists()) {
FileUtil.createNewFile(fileStore);
}
// append to store
fos = new FileOutputStream(fileStore, true);
fos.write(messageId.getBytes());
fos.write(STORE_DELIMITER.getBytes());
} catch (IOException e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
} finally {
IOHelper.close(fos, "Appending to file idempotent repository", LOG);
}
}
use of java.io.IOException in project camel by apache.
the class FileIdempotentRepository method trunkStore.
/**
* Trunks the file store when the max store size is hit by rewriting the 1st level cache
* to the file store.
*/
protected void trunkStore() {
LOG.info("Trunking idempotent filestore: {}", fileStore);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(fileStore);
for (String key : cache.keySet()) {
fos.write(key.getBytes());
fos.write(STORE_DELIMITER.getBytes());
}
} catch (IOException e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
} finally {
IOHelper.close(fos, "Trunking file idempotent repository", LOG);
}
}
use of java.io.IOException in project camel by apache.
the class WireTapProcessor method configureExchange.
protected Exchange configureExchange(Exchange exchange, ExchangePattern pattern) throws IOException {
Exchange answer;
if (copy) {
// use a copy of the original exchange
answer = configureCopyExchange(exchange);
} else {
// use a new exchange
answer = configureNewExchange(exchange);
}
// prepare the exchange
if (newExchangeExpression != null) {
Object body = newExchangeExpression.evaluate(answer, Object.class);
if (body != null) {
answer.getIn().setBody(body);
}
}
if (newExchangeProcessors != null) {
for (Processor processor : newExchangeProcessors) {
try {
processor.process(answer);
} catch (Exception e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
}
}
}
// if the body is a stream cache we must use a copy of the stream in the wire tapped exchange
Message msg = answer.hasOut() ? answer.getOut() : answer.getIn();
if (msg.getBody() instanceof StreamCache) {
// in parallel processing case, the stream must be copied, therefore get the stream
StreamCache cache = (StreamCache) msg.getBody();
StreamCache copied = cache.copy(answer);
if (copied != null) {
msg.setBody(copied);
}
}
// invoke on prepare on the exchange if specified
if (onPrepare != null) {
try {
onPrepare.process(answer);
} catch (Exception e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
}
}
return answer;
}
use of java.io.IOException in project camel by apache.
the class ExceptionBuilderWithHandledExceptionTest method testUnhandledException.
public void testUnhandledException() throws Exception {
MockEndpoint result = getMockEndpoint(RESULT_QUEUE);
result.expectedMessageCount(0);
MockEndpoint mock = getMockEndpoint(ERROR_QUEUE);
mock.expectedMessageCount(1);
mock.expectedHeaderReceived(MESSAGE_INFO, "Handled exchange with IOException");
try {
template.sendBodyAndHeader("direct:a", "Hello IOE", "foo", "something that does not match");
fail("Should have thrown a IOException");
} catch (RuntimeCamelException e) {
assertTrue(e.getCause() instanceof IOException);
// expected, failure is not handled because predicate doesn't match
}
MockEndpoint.assertIsSatisfied(result, mock);
}
Aggregations