-
1. Re: Throwing exceptions on camel routes
mielket Jun 19, 2009 10:07 AM (in response to brett_brettl)See http://camel.apache.org/message-router.html:
Choice without otherwise
If you use a choice without adding an otherwise, any unmatched exchanges will be dropped by default. If you prefer to have an exception for an unmatched exchange, you can add a throwFault to the otherwise.
....otherwise().throwFault("No matching when clause found on choice block");
... and try
Also see
http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/model/ThrowFaultType.html
-
2. Re: Throwing exceptions on camel routes
brett_brettl Jun 22, 2009 10:20 AM (in response to mielket)I have tried using , however now I am getting a Type Conversion error.
org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: class org.apache.camel.impl.DefaultMessage to the required type: java.io.InputStream with value Message: org.apache.camel.CamelException: java.lang.Exception at org.apache.camel.impl.converter.DefaultTypeConverter.doConvertTo(DefaultTypeConverter.java:147) at org.apache.camel.impl.converter.DefaultTypeConverter.convertTo(DefaultTypeConverter.java:90) at org.apache.camel.impl.converter.DefaultTypeConverter.convertTo(DefaultTypeConverter.java:86) at org.apache.camel.impl.MessageSupport.getBody(MessageSupport.java:85) at org.apache.camel.impl.MessageSupport.getBody(MessageSupport.java:52) at org.apache.camel.component.http.DefaultHttpBinding.doWriteResponse(DefaultHttpBinding.java:122) at org.apache.camel.component.http.DefaultHttpBinding.doWriteFaultResponse(DefaultHttpBinding.java:95) at org.apache.camel.component.http.DefaultHttpBinding.writeResponse(DefaultHttpBinding.java:62) at org.apache.camel.component.jetty.CamelContinuationServlet.service(CamelContinuationServlet.java:76) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:502) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:363) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766) at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.Server.handle(Server.java:324) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:534) at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:879) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:741) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:207) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:403) at org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228) at org.mortbay.jetty.security.SslSocketConnector$SslConnection.run(SslSocketConnector.java:636) at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:522)
I tried to look up how to create my own type converter to get around this. According to http://camel.apache.org/type-converter.html I can make a type converter by making a Converter class and method like the following:
@Converter public class DefaultMessageConverter { @Converter public static InputStream toInputStream(DefaultMessage dm) { return new ByteArrayInputStream(dm.getExchange().getIn().getBody().toString().getBytes()); } }
The directions also specify to add a file called TypeConverter to the directory META-INF/services/org/apache/camel/ and include the name of the package that my DefaultMessageConverter class is in. I did all of this but I sill get the exact same error. Are the directions listed at http://camel.apache.org/type-converter.html only for Camel 2.0 and not 1.6.0.0? Does anyone see any reason why my converter would not be picked up?
Brett
-
3. Re: Throwing exceptions on camel routes
davsclaus Jun 22, 2009 11:07 AM (in response to brett_brettl)Hi
That is a bug.
I have created a ticket
https://issues.apache.org/activemq/browse/CAMEL-1739
You can use a Processor to throw the exception. Then its a real exception and should work better.
from(x)
...
.process(new MyExceptionThrower)
And then just throw your exception from this processor in the process method.
-
4. Re: Throwing exceptions on camel routes
davsclaus Jun 22, 2009 11:08 AM (in response to davsclaus)In Spring DSL then use
-
5. Re: Throwing exceptions on camel routes
brett_brettl Jun 22, 2009 2:21 PM (in response to davsclaus)Thanks, that worked.
Brett
Edited by: brett on Jun 22, 2009 6:21 PM