Search in sources :

Example 6 with IOException

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);
    }
}
Also used : DefaultClassResolver(org.apache.camel.impl.DefaultClassResolver) NoFactoryAvailableException(org.apache.camel.NoFactoryAvailableException) IOException(java.io.IOException) NoFactoryAvailableException(org.apache.camel.NoFactoryAvailableException) IOException(java.io.IOException) Test(org.junit.Test)

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

Example 8 with IOException

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());
        }
    }
}
Also used : List(java.util.List) IOException(java.io.IOException) ConduitSelector(org.apache.cxf.endpoint.ConduitSelector) IOException(java.io.IOException)

Example 9 with IOException

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);
    }
}
Also used : Bus(org.apache.cxf.Bus) MessageObserver(org.apache.cxf.transport.MessageObserver) Executor(java.util.concurrent.Executor) AutomaticWorkQueue(org.apache.cxf.workqueue.AutomaticWorkQueue) WorkQueueManager(org.apache.cxf.workqueue.WorkQueueManager) IOException(java.io.IOException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 10 with IOException

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();
}
Also used : Exchange(org.apache.cxf.message.Exchange) OutputStream(java.io.OutputStream) IOException(java.io.IOException) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

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