use of java.io.IOException in project camel by apache.
the class OsgiFactoryFinderTest method testFindClass.
@Test
public void testFindClass() throws Exception {
OsgiFactoryFinder finder = new OsgiFactoryFinder(getBundleContext(), new DefaultClassResolver(), "META-INF/services/org/apache/camel/component/");
Class<?> clazz = finder.findClass("file_test", "strategy.factory.");
assertNotNull("We should get the file strategy factory here", clazz);
try {
clazz = finder.findClass("nofile", "strategy.factory.");
fail("We should get exception here");
} catch (Exception ex) {
assertTrue("Should get NoFactoryAvailableException", ex instanceof NoFactoryAvailableException);
}
try {
clazz = finder.findClass("file_test", "nostrategy.factory.");
fail("We should get exception here");
} catch (Exception ex) {
assertTrue("Should get IOException", ex instanceof IOException);
}
}
use of java.io.IOException in project camel by apache.
the class CryptoDataFormat method getInlinedInitializationVector.
private byte[] getInlinedInitializationVector(Exchange exchange, InputStream encryptedStream) throws IOException {
byte[] iv = getInitializationVector(exchange);
if (inline) {
try {
int ivLength = new DataInputStream(encryptedStream).readInt();
iv = new byte[ivLength];
int read = encryptedStream.read(iv);
if (read != ivLength) {
throw new IOException(String.format("Attempted to read a '%d' byte initialization vector from inputStream but only" + " '%d' bytes were retrieved", ivLength, read));
}
} catch (IOException e) {
throw new IOException("Error reading initialization vector from encrypted stream", e);
}
}
return iv;
}
use of java.io.IOException in project camel by apache.
the class CxfClientCallback method handleException.
public void handleException(Map<String, Object> ctx, Throwable ex) {
try {
super.handleException(ctx, ex);
// need to call the conduitSelector complete method to enable the fail over feature
ConduitSelector conduitSelector = cxfExchange.get(ConduitSelector.class);
if (conduitSelector != null) {
conduitSelector.complete(cxfExchange);
ex = cxfExchange.getOutMessage().getContent(Exception.class);
if (ex == null && cxfExchange.getInMessage() != null) {
ex = cxfExchange.getInMessage().getContent(Exception.class);
}
if (ex != null) {
camelExchange.setException(ex);
}
} else {
camelExchange.setException(ex);
}
} finally {
// add cookies to the cookie store
if (endpoint.getCookieHandler() != null) {
try {
Map<String, List<String>> cxfHeaders = CastUtils.cast((Map<?, ?>) cxfExchange.getInMessage().get(Message.PROTOCOL_HEADERS));
endpoint.getCookieHandler().storeCookies(camelExchange, endpoint.getRequestUri(camelExchange), cxfHeaders);
} catch (IOException e) {
LOG.error("Cannot store cookies", e);
}
}
// process method of org.apache.camel.component.cxf.CxfProducer
if (!boi.getOperationInfo().isOneWay()) {
endpoint.getCxfBinding().populateExchangeFromCxfResponse(camelExchange, cxfExchange, ctx);
camelAsyncCallback.done(false);
}
if (LOG.isDebugEnabled()) {
LOG.debug("{} calling handleException", Thread.currentThread().getName());
}
}
}
use of java.io.IOException in project camel by apache.
the class CamelOutputStream method asyncInvokeFromWorkQueue.
protected void asyncInvokeFromWorkQueue(final org.apache.camel.Exchange exchange) throws IOException {
Runnable runnable = new Runnable() {
public void run() {
try {
syncInvoke(exchange);
} catch (Throwable e) {
((PhaseInterceptorChain) outMessage.getInterceptorChain()).abort();
outMessage.setContent(Exception.class, e);
((PhaseInterceptorChain) outMessage.getInterceptorChain()).unwind(outMessage);
MessageObserver mo = outMessage.getInterceptorChain().getFaultObserver();
if (mo == null) {
mo = outMessage.getExchange().get(MessageObserver.class);
}
mo.onMessage(outMessage);
}
}
};
try {
Executor ex = outMessage.getExchange().get(Executor.class);
if (ex != null) {
outMessage.getExchange().put(Executor.class.getName() + ".USING_SPECIFIED", Boolean.TRUE);
ex.execute(runnable);
} else {
WorkQueueManager mgr = outMessage.getExchange().get(Bus.class).getExtension(WorkQueueManager.class);
AutomaticWorkQueue qu = mgr.getNamedWorkQueue("camel-cxf-conduit");
if (qu == null) {
qu = mgr.getAutomaticWorkQueue();
}
// need to set the time out somewhere
qu.execute(runnable);
}
} catch (RejectedExecutionException rex) {
if (!hasLoggedAsyncWarning) {
LOG.warn("Executor rejected background task to retrieve the response. Suggest increasing the workqueue settings.");
hasLoggedAsyncWarning = true;
}
LOG.info("Executor rejected background task to retrieve the response, running on current thread.");
syncInvoke(exchange);
}
}
use of java.io.IOException in project camel by apache.
the class CamelTransportTestSupport method sendoutMessage.
protected void sendoutMessage(Conduit conduit, Message message, Boolean isOneWay, String content) throws IOException {
Exchange cxfExchange = message.getExchange();
if (cxfExchange == null) {
cxfExchange = new ExchangeImpl();
cxfExchange.setOneWay(isOneWay);
message.setExchange(cxfExchange);
cxfExchange.setInMessage(message);
}
try {
conduit.prepare(message);
} catch (IOException ex) {
assertFalse("CamelConduit can't perpare to send out message", false);
ex.printStackTrace();
}
OutputStream os = message.getContent(OutputStream.class);
assertTrue("The OutputStream should not be null ", os != null);
os.write(content.getBytes());
os.close();
}
Aggregations