You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Alan Camillo <al...@gmail.com> on 2014/12/09 16:27:45 UTC

Rest DSL IN/OUT types

Hello!

I've had some problems trying the new rest dsl from camel and I'd like to
know if there is a way to do this:

restConfiguration()
    .component("netty-http")
    .host("0.0.0.0")
    .bindingMode(*RestBindingMode.auto*)
    .port("{{server.port}}");

rest("/mail")
    .post("/send")
        .consumes("text/xml")
        .produces("text/xml")
        .type(A.class)
        .to("direct:msg");

Until here I received a A.class from the clients with no problem.
But from "direct:msg" I'd like to return a (xml) String to the client. Like
this:

from("direct:msg").routeId("direct:msg")
    .log("message received: ${body}")
    .setBody(new ConstantExpression("<?xml version=\"1.0\"
encoding=\"UTF-8\"?><ok>ok</ok>"));

And than, error:
java.io.IOException: javax.xml.bind.MarshalException
 - with linked exception:
[com.sun.istack.SAXException2: unable to marshal type "java.lang.String" as
an element because it is missing an @XmlRootElement annotation]

Look obvious, but I'd like to know if there a way to do this.
Thanks!
Alan Camillo

Re: Rest DSL IN/OUT types

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

I logged a ticket to track this
https://issues.apache.org/jira/browse/CAMEL-8136

On Tue, Dec 9, 2014 at 5:01 PM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> Ah yeah as it marshalled using JAXB for IN it defaults to do the
> reverse on out. But as you have auto mode, we could likely detect that
> if the message body does not have @Jaxb annotations it should use it
> as-is. Also we could detect if the body is a String and use that
> as-is, as its assume xml content to be returned as-is.
>
> On Tue, Dec 9, 2014 at 4:27 PM, Alan Camillo <al...@gmail.com> wrote:
>> Hello!
>>
>> I've had some problems trying the new rest dsl from camel and I'd like to
>> know if there is a way to do this:
>>
>> restConfiguration()
>>     .component("netty-http")
>>     .host("0.0.0.0")
>>     .bindingMode(*RestBindingMode.auto*)
>>     .port("{{server.port}}");
>>
>> rest("/mail")
>>     .post("/send")
>>         .consumes("text/xml")
>>         .produces("text/xml")
>>         .type(A.class)
>>         .to("direct:msg");
>>
>> Until here I received a A.class from the clients with no problem.
>> But from "direct:msg" I'd like to return a (xml) String to the client. Like
>> this:
>>
>> from("direct:msg").routeId("direct:msg")
>>     .log("message received: ${body}")
>>     .setBody(new ConstantExpression("<?xml version=\"1.0\"
>> encoding=\"UTF-8\"?><ok>ok</ok>"));
>>
>> And than, error:
>> java.io.IOException: javax.xml.bind.MarshalException
>>  - with linked exception:
>> [com.sun.istack.SAXException2: unable to marshal type "java.lang.String" as
>> an element because it is missing an @XmlRootElement annotation]
>>
>> Look obvious, but I'd like to know if there a way to do this.
>> Thanks!
>> Alan Camillo
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
> hawtio: http://hawt.io/
> fabric8: http://fabric8.io/



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: Rest DSL IN/OUT types

Posted by Alan Camillo <al...@gmail.com>.
Fantastic!
Thank you again!

On Tue, Dec 9, 2014 at 5:21 PM, Claus Ibsen <cl...@gmail.com> wrote:

> Hi
>
> Yeah found it outs really camel-jaxb that should support this.
>
> So to support your use case in 2.14.1, you set the
> mustBeJAXBElement=false which you can configure on the rest data
> format property.
>
> For example
>
>
>
> restConfiguration().component("restlet").host("localhost").port(portNum).bindingMode(RestBindingMode.auto)
>                         // turn off must be JAXB as we create the
> output type ourselves as xml in a String type
>                         .dataFormatProperty("mustBeJAXBElement", "false");
>
> On Tue, Dec 9, 2014 at 8:14 PM, Alan Camillo <al...@gmail.com>
> wrote:
> > I see you are working on this.
> > I'll follow your fix.
> >
> > Alan Camillo
> >
> > On Tue, Dec 9, 2014 at 2:17 PM, Claus Ibsen <cl...@gmail.com>
> wrote:
> >
> >> Hi
> >>
> >> Yeah sounds good.
> >>
> >> Its this guy
> >> org.apache.camel.processor.binding.RestBindingProcessor
> >>
> >> which we need to enhance to allow the RestBindingMarshalOnCompletion
> >> part not to do a jaxb in those situations
> >>
> >>
> >>
> >>
> >> On Tue, Dec 9, 2014 at 5:13 PM, Alan Camillo <al...@gmail.com>
> >> wrote:
> >> > It'll be nice. Imagine could use a template engine to create some
> >> returns and mix this with some bindings.
> >> >
> >> > I will look the src and if I could help I can try.
> >> > Thanks!
> >> > Alan
> >> >
> >> >> Em 09/12/2014, às 14:01, Claus Ibsen <cl...@gmail.com>
> escreveu:
> >> >>
> >> >> Hi
> >> >>
> >> >> Ah yeah as it marshalled using JAXB for IN it defaults to do the
> >> >> reverse on out. But as you have auto mode, we could likely detect
> that
> >> >> if the message body does not have @Jaxb annotations it should use it
> >> >> as-is. Also we could detect if the body is a String and use that
> >> >> as-is, as its assume xml content to be returned as-is.
> >> >>
> >> >>> On Tue, Dec 9, 2014 at 4:27 PM, Alan Camillo <alancamillo@gmail.com
> >
> >> wrote:
> >> >>> Hello!
> >> >>>
> >> >>> I've had some problems trying the new rest dsl from camel and I'd
> like
> >> to
> >> >>> know if there is a way to do this:
> >> >>>
> >> >>> restConfiguration()
> >> >>>    .component("netty-http")
> >> >>>    .host("0.0.0.0")
> >> >>>    .bindingMode(*RestBindingMode.auto*)
> >> >>>    .port("{{server.port}}");
> >> >>>
> >> >>> rest("/mail")
> >> >>>    .post("/send")
> >> >>>        .consumes("text/xml")
> >> >>>        .produces("text/xml")
> >> >>>        .type(A.class)
> >> >>>        .to("direct:msg");
> >> >>>
> >> >>> Until here I received a A.class from the clients with no problem.
> >> >>> But from "direct:msg" I'd like to return a (xml) String to the
> client.
> >> Like
> >> >>> this:
> >> >>>
> >> >>> from("direct:msg").routeId("direct:msg")
> >> >>>    .log("message received: ${body}")
> >> >>>    .setBody(new ConstantExpression("<?xml version=\"1.0\"
> >> >>> encoding=\"UTF-8\"?><ok>ok</ok>"));
> >> >>>
> >> >>> And than, error:
> >> >>> java.io.IOException: javax.xml.bind.MarshalException
> >> >>> - with linked exception:
> >> >>> [com.sun.istack.SAXException2: unable to marshal type
> >> "java.lang.String" as
> >> >>> an element because it is missing an @XmlRootElement annotation]
> >> >>>
> >> >>> Look obvious, but I'd like to know if there a way to do this.
> >> >>> Thanks!
> >> >>> Alan Camillo
> >> >>
> >> >>
> >> >>
> >> >> --
> >> >> Claus Ibsen
> >> >> -----------------
> >> >> Red Hat, Inc.
> >> >> Email: cibsen@redhat.com
> >> >> Twitter: davsclaus
> >> >> Blog: http://davsclaus.com
> >> >> Author of Camel in Action: http://www.manning.com/ibsen
> >> >> hawtio: http://hawt.io/
> >> >> fabric8: http://fabric8.io/
> >>
> >>
> >>
> >> --
> >> Claus Ibsen
> >> -----------------
> >> Red Hat, Inc.
> >> Email: cibsen@redhat.com
> >> Twitter: davsclaus
> >> Blog: http://davsclaus.com
> >> Author of Camel in Action: http://www.manning.com/ibsen
> >> hawtio: http://hawt.io/
> >> fabric8: http://fabric8.io/
> >>
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
> hawtio: http://hawt.io/
> fabric8: http://fabric8.io/
>

Re: Rest DSL IN/OUT types

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Yeah found it outs really camel-jaxb that should support this.

So to support your use case in 2.14.1, you set the
mustBeJAXBElement=false which you can configure on the rest data
format property.

For example


restConfiguration().component("restlet").host("localhost").port(portNum).bindingMode(RestBindingMode.auto)
                        // turn off must be JAXB as we create the
output type ourselves as xml in a String type
                        .dataFormatProperty("mustBeJAXBElement", "false");

On Tue, Dec 9, 2014 at 8:14 PM, Alan Camillo <al...@gmail.com> wrote:
> I see you are working on this.
> I'll follow your fix.
>
> Alan Camillo
>
> On Tue, Dec 9, 2014 at 2:17 PM, Claus Ibsen <cl...@gmail.com> wrote:
>
>> Hi
>>
>> Yeah sounds good.
>>
>> Its this guy
>> org.apache.camel.processor.binding.RestBindingProcessor
>>
>> which we need to enhance to allow the RestBindingMarshalOnCompletion
>> part not to do a jaxb in those situations
>>
>>
>>
>>
>> On Tue, Dec 9, 2014 at 5:13 PM, Alan Camillo <al...@gmail.com>
>> wrote:
>> > It'll be nice. Imagine could use a template engine to create some
>> returns and mix this with some bindings.
>> >
>> > I will look the src and if I could help I can try.
>> > Thanks!
>> > Alan
>> >
>> >> Em 09/12/2014, às 14:01, Claus Ibsen <cl...@gmail.com> escreveu:
>> >>
>> >> Hi
>> >>
>> >> Ah yeah as it marshalled using JAXB for IN it defaults to do the
>> >> reverse on out. But as you have auto mode, we could likely detect that
>> >> if the message body does not have @Jaxb annotations it should use it
>> >> as-is. Also we could detect if the body is a String and use that
>> >> as-is, as its assume xml content to be returned as-is.
>> >>
>> >>> On Tue, Dec 9, 2014 at 4:27 PM, Alan Camillo <al...@gmail.com>
>> wrote:
>> >>> Hello!
>> >>>
>> >>> I've had some problems trying the new rest dsl from camel and I'd like
>> to
>> >>> know if there is a way to do this:
>> >>>
>> >>> restConfiguration()
>> >>>    .component("netty-http")
>> >>>    .host("0.0.0.0")
>> >>>    .bindingMode(*RestBindingMode.auto*)
>> >>>    .port("{{server.port}}");
>> >>>
>> >>> rest("/mail")
>> >>>    .post("/send")
>> >>>        .consumes("text/xml")
>> >>>        .produces("text/xml")
>> >>>        .type(A.class)
>> >>>        .to("direct:msg");
>> >>>
>> >>> Until here I received a A.class from the clients with no problem.
>> >>> But from "direct:msg" I'd like to return a (xml) String to the client.
>> Like
>> >>> this:
>> >>>
>> >>> from("direct:msg").routeId("direct:msg")
>> >>>    .log("message received: ${body}")
>> >>>    .setBody(new ConstantExpression("<?xml version=\"1.0\"
>> >>> encoding=\"UTF-8\"?><ok>ok</ok>"));
>> >>>
>> >>> And than, error:
>> >>> java.io.IOException: javax.xml.bind.MarshalException
>> >>> - with linked exception:
>> >>> [com.sun.istack.SAXException2: unable to marshal type
>> "java.lang.String" as
>> >>> an element because it is missing an @XmlRootElement annotation]
>> >>>
>> >>> Look obvious, but I'd like to know if there a way to do this.
>> >>> Thanks!
>> >>> Alan Camillo
>> >>
>> >>
>> >>
>> >> --
>> >> Claus Ibsen
>> >> -----------------
>> >> Red Hat, Inc.
>> >> Email: cibsen@redhat.com
>> >> Twitter: davsclaus
>> >> Blog: http://davsclaus.com
>> >> Author of Camel in Action: http://www.manning.com/ibsen
>> >> hawtio: http://hawt.io/
>> >> fabric8: http://fabric8.io/
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> Red Hat, Inc.
>> Email: cibsen@redhat.com
>> Twitter: davsclaus
>> Blog: http://davsclaus.com
>> Author of Camel in Action: http://www.manning.com/ibsen
>> hawtio: http://hawt.io/
>> fabric8: http://fabric8.io/
>>



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: Rest DSL IN/OUT types

Posted by Alan Camillo <al...@gmail.com>.
I see you are working on this.
I'll follow your fix.

Alan Camillo

On Tue, Dec 9, 2014 at 2:17 PM, Claus Ibsen <cl...@gmail.com> wrote:

> Hi
>
> Yeah sounds good.
>
> Its this guy
> org.apache.camel.processor.binding.RestBindingProcessor
>
> which we need to enhance to allow the RestBindingMarshalOnCompletion
> part not to do a jaxb in those situations
>
>
>
>
> On Tue, Dec 9, 2014 at 5:13 PM, Alan Camillo <al...@gmail.com>
> wrote:
> > It'll be nice. Imagine could use a template engine to create some
> returns and mix this with some bindings.
> >
> > I will look the src and if I could help I can try.
> > Thanks!
> > Alan
> >
> >> Em 09/12/2014, às 14:01, Claus Ibsen <cl...@gmail.com> escreveu:
> >>
> >> Hi
> >>
> >> Ah yeah as it marshalled using JAXB for IN it defaults to do the
> >> reverse on out. But as you have auto mode, we could likely detect that
> >> if the message body does not have @Jaxb annotations it should use it
> >> as-is. Also we could detect if the body is a String and use that
> >> as-is, as its assume xml content to be returned as-is.
> >>
> >>> On Tue, Dec 9, 2014 at 4:27 PM, Alan Camillo <al...@gmail.com>
> wrote:
> >>> Hello!
> >>>
> >>> I've had some problems trying the new rest dsl from camel and I'd like
> to
> >>> know if there is a way to do this:
> >>>
> >>> restConfiguration()
> >>>    .component("netty-http")
> >>>    .host("0.0.0.0")
> >>>    .bindingMode(*RestBindingMode.auto*)
> >>>    .port("{{server.port}}");
> >>>
> >>> rest("/mail")
> >>>    .post("/send")
> >>>        .consumes("text/xml")
> >>>        .produces("text/xml")
> >>>        .type(A.class)
> >>>        .to("direct:msg");
> >>>
> >>> Until here I received a A.class from the clients with no problem.
> >>> But from "direct:msg" I'd like to return a (xml) String to the client.
> Like
> >>> this:
> >>>
> >>> from("direct:msg").routeId("direct:msg")
> >>>    .log("message received: ${body}")
> >>>    .setBody(new ConstantExpression("<?xml version=\"1.0\"
> >>> encoding=\"UTF-8\"?><ok>ok</ok>"));
> >>>
> >>> And than, error:
> >>> java.io.IOException: javax.xml.bind.MarshalException
> >>> - with linked exception:
> >>> [com.sun.istack.SAXException2: unable to marshal type
> "java.lang.String" as
> >>> an element because it is missing an @XmlRootElement annotation]
> >>>
> >>> Look obvious, but I'd like to know if there a way to do this.
> >>> Thanks!
> >>> Alan Camillo
> >>
> >>
> >>
> >> --
> >> Claus Ibsen
> >> -----------------
> >> Red Hat, Inc.
> >> Email: cibsen@redhat.com
> >> Twitter: davsclaus
> >> Blog: http://davsclaus.com
> >> Author of Camel in Action: http://www.manning.com/ibsen
> >> hawtio: http://hawt.io/
> >> fabric8: http://fabric8.io/
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
> hawtio: http://hawt.io/
> fabric8: http://fabric8.io/
>

Re: Rest DSL IN/OUT types

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Yeah sounds good.

Its this guy
org.apache.camel.processor.binding.RestBindingProcessor

which we need to enhance to allow the RestBindingMarshalOnCompletion
part not to do a jaxb in those situations




On Tue, Dec 9, 2014 at 5:13 PM, Alan Camillo <al...@gmail.com> wrote:
> It'll be nice. Imagine could use a template engine to create some returns and mix this with some bindings.
>
> I will look the src and if I could help I can try.
> Thanks!
> Alan
>
>> Em 09/12/2014, às 14:01, Claus Ibsen <cl...@gmail.com> escreveu:
>>
>> Hi
>>
>> Ah yeah as it marshalled using JAXB for IN it defaults to do the
>> reverse on out. But as you have auto mode, we could likely detect that
>> if the message body does not have @Jaxb annotations it should use it
>> as-is. Also we could detect if the body is a String and use that
>> as-is, as its assume xml content to be returned as-is.
>>
>>> On Tue, Dec 9, 2014 at 4:27 PM, Alan Camillo <al...@gmail.com> wrote:
>>> Hello!
>>>
>>> I've had some problems trying the new rest dsl from camel and I'd like to
>>> know if there is a way to do this:
>>>
>>> restConfiguration()
>>>    .component("netty-http")
>>>    .host("0.0.0.0")
>>>    .bindingMode(*RestBindingMode.auto*)
>>>    .port("{{server.port}}");
>>>
>>> rest("/mail")
>>>    .post("/send")
>>>        .consumes("text/xml")
>>>        .produces("text/xml")
>>>        .type(A.class)
>>>        .to("direct:msg");
>>>
>>> Until here I received a A.class from the clients with no problem.
>>> But from "direct:msg" I'd like to return a (xml) String to the client. Like
>>> this:
>>>
>>> from("direct:msg").routeId("direct:msg")
>>>    .log("message received: ${body}")
>>>    .setBody(new ConstantExpression("<?xml version=\"1.0\"
>>> encoding=\"UTF-8\"?><ok>ok</ok>"));
>>>
>>> And than, error:
>>> java.io.IOException: javax.xml.bind.MarshalException
>>> - with linked exception:
>>> [com.sun.istack.SAXException2: unable to marshal type "java.lang.String" as
>>> an element because it is missing an @XmlRootElement annotation]
>>>
>>> Look obvious, but I'd like to know if there a way to do this.
>>> Thanks!
>>> Alan Camillo
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> Red Hat, Inc.
>> Email: cibsen@redhat.com
>> Twitter: davsclaus
>> Blog: http://davsclaus.com
>> Author of Camel in Action: http://www.manning.com/ibsen
>> hawtio: http://hawt.io/
>> fabric8: http://fabric8.io/



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: Rest DSL IN/OUT types

Posted by Alan Camillo <al...@gmail.com>.
It'll be nice. Imagine could use a template engine to create some returns and mix this with some bindings. 

I will look the src and if I could help I can try. 
Thanks!
Alan

> Em 09/12/2014, às 14:01, Claus Ibsen <cl...@gmail.com> escreveu:
> 
> Hi
> 
> Ah yeah as it marshalled using JAXB for IN it defaults to do the
> reverse on out. But as you have auto mode, we could likely detect that
> if the message body does not have @Jaxb annotations it should use it
> as-is. Also we could detect if the body is a String and use that
> as-is, as its assume xml content to be returned as-is.
> 
>> On Tue, Dec 9, 2014 at 4:27 PM, Alan Camillo <al...@gmail.com> wrote:
>> Hello!
>> 
>> I've had some problems trying the new rest dsl from camel and I'd like to
>> know if there is a way to do this:
>> 
>> restConfiguration()
>>    .component("netty-http")
>>    .host("0.0.0.0")
>>    .bindingMode(*RestBindingMode.auto*)
>>    .port("{{server.port}}");
>> 
>> rest("/mail")
>>    .post("/send")
>>        .consumes("text/xml")
>>        .produces("text/xml")
>>        .type(A.class)
>>        .to("direct:msg");
>> 
>> Until here I received a A.class from the clients with no problem.
>> But from "direct:msg" I'd like to return a (xml) String to the client. Like
>> this:
>> 
>> from("direct:msg").routeId("direct:msg")
>>    .log("message received: ${body}")
>>    .setBody(new ConstantExpression("<?xml version=\"1.0\"
>> encoding=\"UTF-8\"?><ok>ok</ok>"));
>> 
>> And than, error:
>> java.io.IOException: javax.xml.bind.MarshalException
>> - with linked exception:
>> [com.sun.istack.SAXException2: unable to marshal type "java.lang.String" as
>> an element because it is missing an @XmlRootElement annotation]
>> 
>> Look obvious, but I'd like to know if there a way to do this.
>> Thanks!
>> Alan Camillo
> 
> 
> 
> -- 
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
> hawtio: http://hawt.io/
> fabric8: http://fabric8.io/

Re: Rest DSL IN/OUT types

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Ah yeah as it marshalled using JAXB for IN it defaults to do the
reverse on out. But as you have auto mode, we could likely detect that
if the message body does not have @Jaxb annotations it should use it
as-is. Also we could detect if the body is a String and use that
as-is, as its assume xml content to be returned as-is.

On Tue, Dec 9, 2014 at 4:27 PM, Alan Camillo <al...@gmail.com> wrote:
> Hello!
>
> I've had some problems trying the new rest dsl from camel and I'd like to
> know if there is a way to do this:
>
> restConfiguration()
>     .component("netty-http")
>     .host("0.0.0.0")
>     .bindingMode(*RestBindingMode.auto*)
>     .port("{{server.port}}");
>
> rest("/mail")
>     .post("/send")
>         .consumes("text/xml")
>         .produces("text/xml")
>         .type(A.class)
>         .to("direct:msg");
>
> Until here I received a A.class from the clients with no problem.
> But from "direct:msg" I'd like to return a (xml) String to the client. Like
> this:
>
> from("direct:msg").routeId("direct:msg")
>     .log("message received: ${body}")
>     .setBody(new ConstantExpression("<?xml version=\"1.0\"
> encoding=\"UTF-8\"?><ok>ok</ok>"));
>
> And than, error:
> java.io.IOException: javax.xml.bind.MarshalException
>  - with linked exception:
> [com.sun.istack.SAXException2: unable to marshal type "java.lang.String" as
> an element because it is missing an @XmlRootElement annotation]
>
> Look obvious, but I'd like to know if there a way to do this.
> Thanks!
> Alan Camillo



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/