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));
}
}
}
}
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();
}
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);
}
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);
}
}
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;
}
}
Aggregations