Search in sources :

Example 21 with CamelException

use of org.apache.camel.CamelException in project camel by apache.

the class HandleFaultInterceptor method handleFault.

/**
     * Handles the fault message by converting it to an Exception
     */
protected void handleFault(Exchange exchange) {
    // Take the fault message out before we keep on going
    Message msg = exchange.hasOut() ? exchange.getOut() : exchange.getIn();
    if (msg.isFault()) {
        final Object faultBody = msg.getBody();
        if (faultBody != null && exchange.getException() == null) {
            // remove fault as we are converting it to an exception
            if (exchange.hasOut()) {
                exchange.setOut(null);
            } else {
                exchange.setIn(null);
            }
            if (faultBody instanceof Throwable) {
                exchange.setException((Throwable) faultBody);
            } else {
                // wrap it in an exception
                String data = exchange.getContext().getTypeConverter().convertTo(String.class, exchange, faultBody);
                exchange.setException(new CamelException(data));
            }
        }
    }
}
Also used : Message(org.apache.camel.Message) CamelException(org.apache.camel.CamelException)

Example 22 with CamelException

use of org.apache.camel.CamelException in project camel by apache.

the class SplitterTest method testSplitterWithException.

public void testSplitterWithException() throws Exception {
    MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
    resultEndpoint.expectedMessageCount(4);
    resultEndpoint.expectedHeaderReceived("foo", "bar");
    MockEndpoint failedEndpoint = getMockEndpoint("mock:failed");
    failedEndpoint.expectedMessageCount(1);
    failedEndpoint.expectedHeaderReceived("foo", "bar");
    Exchange result = template.request("direct:exception", new Processor() {

        public void process(Exchange exchange) {
            Message in = exchange.getIn();
            in.setBody("James,Guillaume,Hiram,Rob,Exception");
            in.setHeader("foo", "bar");
        }
    });
    assertTrue("The result exchange should have a camel exception", result.getException() instanceof CamelException);
    assertMockEndpointsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Message(org.apache.camel.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) CamelException(org.apache.camel.CamelException)

Example 23 with CamelException

use of org.apache.camel.CamelException in project camel by apache.

the class SplitterParallelBigFileTest method xxxtestSplitParallelBigFile.

// disabled due manual test
public void xxxtestSplitParallelBigFile() throws Exception {
    StopWatch watch = new StopWatch();
    NotifyBuilder builder = new NotifyBuilder(context).whenDone(lines + 1).create();
    boolean done = builder.matches(120, TimeUnit.SECONDS);
    log.info("Took " + TimeUtils.printDuration(watch.stop()));
    if (!done) {
        throw new CamelException("Could not split file in 2 minutes");
    }
// need a little sleep for capturing memory profiling
// Thread.sleep(60 * 1000);
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) CamelException(org.apache.camel.CamelException) StopWatch(org.apache.camel.util.StopWatch)

Example 24 with CamelException

use of org.apache.camel.CamelException in project camel by apache.

the class AbstractCamelContextFactoryBean method installRoutes.

/**
     * Strategy to install all available routes into the context
     */
protected void installRoutes() throws Exception {
    List<RouteBuilder> builders = new ArrayList<RouteBuilder>();
    // lets add RoutesBuilder's added from references
    if (getBuilderRefs() != null) {
        for (RouteBuilderDefinition builderRef : getBuilderRefs()) {
            RoutesBuilder routes = builderRef.createRoutes(getContext());
            if (routes != null) {
                this.builders.add(routes);
            } else {
                throw new CamelException("Cannot find any routes with this RouteBuilder reference: " + builderRef);
            }
        }
    }
    // install already configured routes
    for (RoutesBuilder routeBuilder : this.builders) {
        getContext().addRoutes(routeBuilder);
    }
    // install builders
    for (RouteBuilder builder : builders) {
        // Inject the annotated resource
        postProcessBeforeInit(builder);
        getContext().addRoutes(builder);
    }
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) CamelException(org.apache.camel.CamelException) ArrayList(java.util.ArrayList) RouteBuilderDefinition(org.apache.camel.model.RouteBuilderDefinition) RoutesBuilder(org.apache.camel.RoutesBuilder)

Example 25 with CamelException

use of org.apache.camel.CamelException in project camel by apache.

the class AbstractApiComponent method createEndpoint.

protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    // split remaining path to get API name and method
    final String[] pathElements = remaining.split("/");
    String apiNameStr;
    String methodName;
    switch(pathElements.length) {
        case 1:
            apiNameStr = "";
            methodName = pathElements[0];
            break;
        case 2:
            apiNameStr = pathElements[0];
            methodName = pathElements[1];
            break;
        default:
            throw new CamelException("Invalid URI path [" + remaining + "], must be of the format " + collection.getApiNames() + "/<operation-name>");
    }
    try {
        // get API enum from apiName string
        final E apiName = getApiName(apiNameStr);
        final T endpointConfiguration = createEndpointConfiguration(apiName);
        final Endpoint endpoint = createEndpoint(uri, methodName, apiName, endpointConfiguration);
        // set endpoint property inBody
        setProperties(endpoint, parameters);
        // configure endpoint properties and initialize state
        endpoint.configureProperties(parameters);
        return endpoint;
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof IllegalArgumentException) {
            throw new CamelException("Invalid URI path prefix [" + remaining + "], must be one of " + collection.getApiNames());
        }
        throw e;
    }
}
Also used : Endpoint(org.apache.camel.Endpoint) CamelException(org.apache.camel.CamelException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

CamelException (org.apache.camel.CamelException)28 RouteBuilder (org.apache.camel.builder.RouteBuilder)6 SalesforceException (org.apache.camel.component.salesforce.api.SalesforceException)6 IOException (java.io.IOException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 CamelExecutionException (org.apache.camel.CamelExecutionException)3 SyncResponseCallback (org.apache.camel.component.salesforce.internal.client.SyncResponseCallback)3 PushTopic (org.apache.camel.component.salesforce.internal.dto.PushTopic)3 QueryRecordsPushTopic (org.apache.camel.component.salesforce.internal.dto.QueryRecordsPushTopic)3 XMLReader (org.xml.sax.XMLReader)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 StringWriter (java.io.StringWriter)2 ConnectException (java.net.ConnectException)2 Exchange (org.apache.camel.Exchange)2 Message (org.apache.camel.Message)2 Message (org.cometd.bayeux.Message)2 ClientSessionChannel (org.cometd.bayeux.client.ClientSessionChannel)2 Channel (org.jboss.netty.channel.Channel)2 ChannelFuture (org.jboss.netty.channel.ChannelFuture)2 Test (org.junit.Test)2