I am new to Camel and try to learn idioms and best practices. I am writing web services that should handle several different errors. Here is my error handling and routing:
onException(JsonParseException.class).inOut("direct:syntaxError").handled(true);
onException(UnrecognizedPropertyException.class).inOut("direct:syntaxError").handled(true);
// Route service through direct to allow testing.
from("servlet:///service?matchOnUriPrefix=true").inOut("direct:service");
from("direct:service")
.choice()
.when(body().isEqualTo(null))
.inOut("direct:syntaxError")
.otherwise()
.unmarshal().json(lJsonLib, AuthorizationParameters.class).inOut("bean:mybean?method=serviceMethod").marshal().json(lJsonLib);
As you can see, I have special processing (content based routing) for processing a request with a zero body. Is there a way to handle this more elegantly? I write several services of this type, and it seems that they can be much cleaner.
Spina source
share