You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Claus Ibsen <cl...@gmail.com> on 2011/06/02 15:12:04 UTC
Re: CXFRS custom response
Hi
I have created a ticket to track this
https://issues.apache.org/jira/browse/CAMEL-4039
On Fri, May 27, 2011 at 11:37 AM, Bruno Dusausoy <br...@yp5.be> wrote:
> Hi,
>
> As previously stated[1] I'm creating a RESTful webservice, defined by this :
>
> public class RestComputationService implements ComputationService {
>
> @POST
> @Path("/computation")
> @Consumes("text/xml")
> @Produces("text/xml")
> @Override
> public Response compute(Request request) {
> return null;
> }
> }
>
> Request and Response are quite misleading, they are *not* the one found in
> the JAXRS package, they are generated from a schema.
>
> I'd like to handle an exception like I would in CXF, that is something like
> this :
>
> Category cat = (Category) getCategoryDAO().getCategory(id);
> if (cat == null) {
> ResponseBuilder builder =
> Response.status(Status.BAD_REQUEST);
> builder.type("application/xml");
> builder.entity("<error>Category Not Found</error>");
> throw new WebApplicationException(builder.build());
> }
>
> I've read in "Camel in Action" that a possible way to do this is to use
> something similar to this :
>
> public class FailureResponseProcessor implements Processor {
> public void process(Exchange exchange) throws Exception {
> String body = exchange.getIn().getBody(String.class);
> Exception e = exchange.getProperty(Exchange.EXCEPTION_CAUGHT,
> Exception.class);
> StringBuilder sb = new StringBuilder();
> sb.append("ERROR: ");
> sb.append(e.getMessage());
> sb.append("\nBODY: ");
> sb.append(body);
> exchange.getIn().setBody(sb.toString());
> }
> }
>
> But if I do this with my CXFRS webservice, I get a CamelExecutionException
> caused by a InvalidPayloadException caused itself by a
> NoTypeConversionAvailableException.
> Indeed, what I put in the body (that is, a String) cannot be transformed to
> an object of type Response by JAXB.
>
> So, question, how can I return a custom response ?
> Can I bypass JAXB and directly access the CXF rsServer in order to respond
> to the client and tell Camel that it doesn't have to do anything else - in
> other words, telling Camel its work is finished for this request ?
> Am I doing right or is my design completely flawed ?
>
> Regards.
> [1]
> http://camel.465427.n5.nabble.com/CXFRS-and-XML-validation-td4428899.html
> --
> Bruno Dusausoy
> YP5 Software
> --
> Pensez environnement : limitez l'impression de ce mail.
> Please don't print this e-mail unless you really need to.
>
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/