Search in sources :

Example 36 with IOException

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

the class ContextScopedOnExceptionNotHandledRouteScopedErrorHandlerRefIssueTwoRoutesTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            onException(IllegalArgumentException.class).handled(false).to("mock:handled").end();
            from("direct:foo").errorHandler(new ErrorHandlerBuilderRef("myDLC")).to("mock:foo").throwException(new IOException("Damn IO"));
            from("direct:start").errorHandler(new ErrorHandlerBuilderRef("myDLC")).to("mock:a").throwException(new IllegalArgumentException("Damn"));
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) IOException(java.io.IOException) ErrorHandlerBuilderRef(org.apache.camel.builder.ErrorHandlerBuilderRef)

Example 37 with IOException

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

the class MultipleErrorHandlerOnExceptionIssueTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            onException(IllegalArgumentException.class).handled(true).to("mock:handled");
            from("seda:a").errorHandler(deadLetterChannel("mock:dead.a").maximumRedeliveries(3).redeliveryDelay(0).retryAttemptedLogLevel(LoggingLevel.WARN).asyncDelayedRedelivery()).to("mock:a").throwException(new IllegalArgumentException("Forced A"));
            from("seda:b").errorHandler(deadLetterChannel("mock:dead.b").maximumRedeliveries(2).redeliveryDelay(0).retryAttemptedLogLevel(LoggingLevel.WARN)).to("mock:b").throwException(new IOException("Some IO error"));
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) IOException(java.io.IOException)

Example 38 with IOException

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

the class ManagedFailoverLoadBalancerTest method testManageFailoverLoadBalancer.

public void testManageFailoverLoadBalancer() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    getMockEndpoint("mock:foo").whenAnyExchangeReceived(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            throw new IOException("Forced");
        }
    });
    MockEndpoint bar = getMockEndpoint("mock:bar");
    bar.expectedMessageCount(1);
    template.sendBodyAndHeader("direct:start", "Hello World", "foo", "123");
    assertMockEndpointsSatisfied();
    // get the stats for the route
    MBeanServer mbeanServer = getMBeanServer();
    // get the object name for the delayer
    ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"mysend\"");
    // should be on route1
    String routeId = (String) mbeanServer.getAttribute(on, "RouteId");
    assertEquals("route1", routeId);
    String camelId = (String) mbeanServer.getAttribute(on, "CamelId");
    assertEquals("camel-1", camelId);
    String state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals(ServiceStatus.Started.name(), state);
    Integer size = (Integer) mbeanServer.getAttribute(on, "Size");
    assertEquals(2, size.intValue());
    Boolean roundRobin = (Boolean) mbeanServer.getAttribute(on, "RoundRobin");
    assertEquals(true, roundRobin.booleanValue());
    Boolean sticky = (Boolean) mbeanServer.getAttribute(on, "Sticky");
    assertEquals(true, sticky.booleanValue());
    Integer attempts = (Integer) mbeanServer.getAttribute(on, "MaximumFailoverAttempts");
    assertEquals(3, attempts.intValue());
    String exceptions = (String) mbeanServer.getAttribute(on, "Exceptions");
    assertEquals("java.io.IOException,java.sql.SQLException", exceptions);
    String id = (String) mbeanServer.getAttribute(on, "LastGoodProcessorId");
    assertEquals("bar", id);
    TabularData data = (TabularData) mbeanServer.invoke(on, "exceptionStatistics", null, null);
    assertNotNull(data);
    assertEquals(2, data.size());
    data = (TabularData) mbeanServer.invoke(on, "explain", new Object[] { false }, new String[] { "boolean" });
    assertNotNull(data);
    assertEquals(3, data.size());
    data = (TabularData) mbeanServer.invoke(on, "explain", new Object[] { true }, new String[] { "boolean" });
    assertNotNull(data);
    assertEquals(5, data.size());
    String json = (String) mbeanServer.invoke(on, "informationJson", null, null);
    assertNotNull(json);
    assertTrue(json.contains("\"description\": \"Balances message processing among a number of nodes"));
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) IOException(java.io.IOException) SQLException(java.sql.SQLException) IOException(java.io.IOException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData)

Example 39 with IOException

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

the class FailOverLoadBalanceNotInheritedErrorHandlerTest method createRouteBuilder.

protected RouteBuilder createRouteBuilder() {
    return new RouteBuilder() {

        public void configure() {
            // after failover is done, then we should be routed to dead
            errorHandler(deadLetterChannel("mock:dead"));
            from("direct:start").loadBalance().failover(3, false, true).throwException(new IllegalArgumentException()).throwException(new IOException()).throwException(new ConnectException()).end().end().to("mock:result");
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) IOException(java.io.IOException) ConnectException(java.net.ConnectException)

Example 40 with IOException

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

the class FailOverLoadBalanceWrappedExceptionTest method createRouteBuilder.

protected RouteBuilder createRouteBuilder() {
    return new RouteBuilder() {

        public void configure() {
            from("direct:start").loadBalance().failover(IOException.class).to("direct:x", "direct:y", "direct:z");
            from("direct:x").to("mock:x").process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    // socket exception is an io exception
                    throw new CamelExchangeException("foo", exchange, new SocketException("Forced"));
                }
            });
            from("direct:y").to("mock:y").process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    throw new IOException("Forced");
                }
            });
            from("direct:z").to("mock:z");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) CamelExchangeException(org.apache.camel.CamelExchangeException) SocketException(java.net.SocketException) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) IOException(java.io.IOException) SocketException(java.net.SocketException) IOException(java.io.IOException) CamelExchangeException(org.apache.camel.CamelExchangeException)

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