You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Espen Tjonneland (JIRA)" <ji...@apache.org> on 2014/12/05 10:21:12 UTC
[jira] [Commented] (CAMEL-8104) rest-dsl - Allow custom error
responses as-is without invoking the output binding
[ https://issues.apache.org/jira/browse/CAMEL-8104?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14235294#comment-14235294 ]
Espen Tjonneland commented on CAMEL-8104:
-----------------------------------------
I wonder if there is still missing some bits here. And I am guessing it is failing due to it being done inside an interceptor.
Consider the following route def:
{code}
public class MyRestRouteDefs extends RouteBuilder {
imports .....;
@Override
public void configure() {
..... config stuff
interceptFrom().id("Create an error")
.bean(CreateAnError.class); //Sets up one interceptor that always creates an error message - just to clarify this issue
restConfiguration().component("servlet").bindingMode(RestBindingMode.json)
.contextPath("/MyContext/api/").port("8080");
RestDefinition privateAPI = rest(ServiceConstants.PRIVATE_API_VERSION_1).description("Private (internal) REST services for MyServices.")
.skipBindingOnErrorCode(true); //Not neccecary (for clarity)
privateAPI.get("/fetchsomething").description("Lists stuff from some service")
.outTypeList(MyPojoForSomething.class)
.route().routeId("A descriptive ID")
.choice()
.when(header(ServiceConstants.REQUEST_VALIDATED).isEqualTo("TRUE"))
.bean(GoAheadAndFillAMyPojoForSomething-into-body.class)
.otherwise()); //Otherwise might not be needed. Added it there to show that it is a branching point.
}
}
public class CreateAnError {
imports .....;
@Handler
public void createAnError (@Body Message requestMessage) {
requestMessage.setHeader(ServiceConstants.REQUEST_VALIDATED, "FALSE");
requestMessage.setHeader(Exchange.HTTP_RESPONSE_CODE, HttpServletResponse.SC_FORBIDDEN);
requestMessage.setHeader(Exchange.CONTENT_TYPE, "text/plain");
requestMessage.setBody("I raised this error inside an interceptor and just wanted to tell you about it");
}
}
{code}
This results in an error:
{code}
com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'Missing': was expecting ('true', 'false' or 'null')
at [Source: java.io.ByteArrayInputStream@67618968; line: 1, column: 9]
at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1419)
{code}
> rest-dsl - Allow custom error responses as-is without invoking the output binding
> ---------------------------------------------------------------------------------
>
> Key: CAMEL-8104
> URL: https://issues.apache.org/jira/browse/CAMEL-8104
> Project: Camel
> Issue Type: Improvement
> Components: camel-core
> Affects Versions: 2.14.0
> Reporter: Claus Ibsen
> Assignee: Claus Ibsen
> Fix For: 2.14.1, 2.15.0
>
>
> See
> http://camel.465427.n5.nabble.com/Rest-DSL-OutType-in-case-of-error-message-problem-tp5759864.html
> We should allow end users to define custom error messages as-is to be used as response.
> We add a flag that enables this out of the box. Then the end user just set a custom body and set the HTTP_RESPONSE_CODE header to >= 300 value to indicate an error. Then rest-dsl does not attempt to bind output.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)