You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Pavel Lechev <p....@gmail.com> on 2014/11/21 16:56:31 UTC

Impossible to configure HttpBinding for ServletComponent

Hi all, 
I think this is a genuine bug, but I thought to post it here in the first
instance. 
Camel v2.14.0
The call to endpoint.setBinding(new ServletRestHttpBinding()); on line 208
in org.apache.camel.component.servlet.ServletComponent overwrites the
binding previously configured during the endpoint creation at line 96. 
This makes it impossible to use externally configured HttpBinding instance,
in effect rendering the
org.apache.camel.component.http.HttpComponent#httpBinding property unusable. 
Thanks
Pav




--
View this message in context: http://camel.465427.n5.nabble.com/Impossible-to-configure-HttpBinding-for-ServletComponent-tp5759473.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Impossible to configure HttpBinding for ServletComponent

Posted by Pavel Lechev <p....@gmail.com>.
Apologies, perhaps it wasn't clear - the component is specifically defined
for REST: 

<bean id=&quot;&lt;b>restservlet*"
class="org.apache.camel...ServletComponent">

In fact, in my XML config and the DSL, the ServletComponent bean ID is not
"servlet". I just changed it in the email to avoid confusion, but I am
assuming if no other ServletComponent-s are defined the ID string is
irrelevant as long as properly referenced. 


Claus Ibsen-2 wrote
> Just define a new component for rest.
> <bean id="restservlet" class="org.apache.camel...ServletComponent">
> 
> On Mon, Nov 24, 2014 at 10:26 AM, Pavel Lechev &lt;

> p.lechev@

> &gt; wrote:
>> Hi Claus,
>> Thanks for your response.
>> Am I to understand that the REST DSL in combination with the `servlet`
>> consumer does not allow setting a custom HttpBinding? If so, I believe
>> this
>> is a huge limitation given that these two are very commonly used
>> together.
>> It is also not very clear from the documentation that Servlet component
>> will
>> not allow custom HttpBinding when used in REST DSL.
>> Here is my scenario:
>> 1. Servlet component explicitly defined in Spring context, where we set
>> the
>> http binding:
>>     &lt;bean id=&quot;servlet&quot;
>> class=&quot;org.apache.camel.component.servlet.ServletComponent&quot;&gt;
>> &lt;property name=&quot;httpBinding&quot;&gt;            &lt;bean
>> class=&quot;my.custom.HttpBinding&quot;/&gt;        &lt;/property&gt;
>> &lt;/bean&gt;
>> 2. DSL REST config:
>>         restConfiguration()                .component("servlet")  &lt;-
>> use
>> the `servlet` component we defined above
>> .bindingMode(RestBindingMode.auto);        rest("/my-path")
>> .consumes(MediaType.APPLICATION_XML)
>> .produces(MediaType.APPLICATION_XML)
>> .post().type(MyXMLMappedDataClass.class)                .route()
>> .routeId("My-Route")                            .to(....)                              
>> ....                            ....
>>         Then, on Spring/Camel startup, the following calls are executed
>> in this
>> order:
>> 1) component.createEndpoint(..) in DefaultCamelContext.java:525 results
>> in
>> endpoint.setBinding(binding) (on ServletComponent.java:96), which
>> *correctly* sets my custom binding instance, however the next step
>> 2) factory.createConsumer(..) RestEndpoint.java:167 results in
>> endpoint.setBinding(new ServletRestHttpBinding()) (on
>> ServletComponent.java:208), which overwrites the instance previously set
>> I can understand the rationale behind enforcing ServletRestHttpBinding,
>> however it will be good if the option to extend this class and configure
>> it
>> as a custom binding still exists.
>> Thanks
>> Pav
>>
>>
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/Impossible-to-configure-HttpBinding-for-ServletComponent-tp5759473p5759528.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
> 
> 
> 
> -- 
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: 

> cibsen@

> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
> hawtio: http://hawt.io/
> fabric8: http://fabric8.io/





--
View this message in context: http://camel.465427.n5.nabble.com/Impossible-to-configure-HttpBinding-for-ServletComponent-tp5759473p5759530.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Impossible to configure HttpBinding for ServletComponent

Posted by Claus Ibsen <cl...@gmail.com>.
Just define a new component for rest.

<bean id="restservlet" class="org.apache.camel...ServletComponent">


On Mon, Nov 24, 2014 at 10:26 AM, Pavel Lechev <p....@gmail.com> wrote:
> Hi Claus,
> Thanks for your response.
> Am I to understand that the REST DSL in combination with the `servlet`
> consumer does not allow setting a custom HttpBinding? If so, I believe this
> is a huge limitation given that these two are very commonly used together.
> It is also not very clear from the documentation that Servlet component will
> not allow custom HttpBinding when used in REST DSL.
> Here is my scenario:
> 1. Servlet component explicitly defined in Spring context, where we set the
> http binding:
>     &lt;bean id=&quot;servlet&quot;
> class=&quot;org.apache.camel.component.servlet.ServletComponent&quot;&gt;
> &lt;property name=&quot;httpBinding&quot;&gt;            &lt;bean
> class=&quot;my.custom.HttpBinding&quot;/&gt;        &lt;/property&gt;
> &lt;/bean&gt;
> 2. DSL REST config:
>         restConfiguration()                .component("servlet")  &lt;- use
> the `servlet` component we defined above
> .bindingMode(RestBindingMode.auto);        rest("/my-path")
> .consumes(MediaType.APPLICATION_XML)
> .produces(MediaType.APPLICATION_XML)
> .post().type(MyXMLMappedDataClass.class)                .route()
> .routeId("My-Route")                            .to(....)                               ....                            ....
>         Then, on Spring/Camel startup, the following calls are executed in this
> order:
> 1) component.createEndpoint(..) in DefaultCamelContext.java:525 results in
> endpoint.setBinding(binding) (on ServletComponent.java:96), which
> *correctly* sets my custom binding instance, however the next step
> 2) factory.createConsumer(..) RestEndpoint.java:167 results in
> endpoint.setBinding(new ServletRestHttpBinding()) (on
> ServletComponent.java:208), which overwrites the instance previously set
> I can understand the rationale behind enforcing ServletRestHttpBinding,
> however it will be good if the option to extend this class and configure it
> as a custom binding still exists.
> Thanks
> Pav
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Impossible-to-configure-HttpBinding-for-ServletComponent-tp5759473p5759528.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
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: Impossible to configure HttpBinding for ServletComponent

Posted by Pavel Lechev <p....@gmail.com>.
Hi Claus,
Thanks for your response. 
Am I to understand that the REST DSL in combination with the `servlet`
consumer does not allow setting a custom HttpBinding? If so, I believe this
is a huge limitation given that these two are very commonly used together.
It is also not very clear from the documentation that Servlet component will
not allow custom HttpBinding when used in REST DSL. 
Here is my scenario:
1. Servlet component explicitly defined in Spring context, where we set the
http binding: 
    &lt;bean id=&quot;servlet&quot;
class=&quot;org.apache.camel.component.servlet.ServletComponent&quot;&gt;       
&lt;property name=&quot;httpBinding&quot;&gt;            &lt;bean
class=&quot;my.custom.HttpBinding&quot;/&gt;        &lt;/property&gt;   
&lt;/bean&gt; 
2. DSL REST config: 
        restConfiguration()                .component("servlet")  &lt;- use
the `servlet` component we defined above               
.bindingMode(RestBindingMode.auto);        rest("/my-path")               
.consumes(MediaType.APPLICATION_XML)               
.produces(MediaType.APPLICATION_XML)               
.post().type(MyXMLMappedDataClass.class)                .route()               
.routeId("My-Route")				.to(....)				....				.... 
	Then, on Spring/Camel startup, the following calls are executed in this
order: 
1) component.createEndpoint(..) in DefaultCamelContext.java:525 results in
endpoint.setBinding(binding) (on ServletComponent.java:96), which
*correctly* sets my custom binding instance, however the next step 
2) factory.createConsumer(..) RestEndpoint.java:167 results in
endpoint.setBinding(new ServletRestHttpBinding()) (on
ServletComponent.java:208), which overwrites the instance previously set
I can understand the rationale behind enforcing ServletRestHttpBinding,
however it will be good if the option to extend this class and configure it
as a custom binding still exists. 
Thanks
Pav



--
View this message in context: http://camel.465427.n5.nabble.com/Impossible-to-configure-HttpBinding-for-ServletComponent-tp5759473p5759528.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Impossible to configure HttpBinding for ServletComponent

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

Not its correct. That code is when you use the Rest DSL which requires
that binding. The regular servlet component does not use that code and
works as before.

On Fri, Nov 21, 2014 at 4:56 PM, Pavel Lechev <p....@gmail.com> wrote:
> Hi all,
> I think this is a genuine bug, but I thought to post it here in the first
> instance.
> Camel v2.14.0
> The call to endpoint.setBinding(new ServletRestHttpBinding()); on line 208
> in org.apache.camel.component.servlet.ServletComponent overwrites the
> binding previously configured during the endpoint creation at line 96.
> This makes it impossible to use externally configured HttpBinding instance,
> in effect rendering the
> org.apache.camel.component.http.HttpComponent#httpBinding property unusable.
> Thanks
> Pav
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Impossible-to-configure-HttpBinding-for-ServletComponent-tp5759473.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
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/