You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Tim Emrich <ti...@code-poets.net> on 2012/09/11 12:52:42 UTC

cxfrs: multiple resource howto?

hello,

i try to expose 2 or more resources using the cxfrs component (camel 2.10.1).
One is working fine, but i don't find a proper solution to expose more then one.

i tried several approaches but none of them worked as expected (at
least what i expect ;-)):

1) one rsServer with many serviceBeans
in the route i use something like
"cxfrs:bean:rsServer?resourceClass=net.code-poets.camel.endpoint.v01.ResourceEndpoint1";
-> all requests are routed to just one endpoint

2) many rsServer instances with one serviceClass each
- using the same address "/" attribute for all rsServer instances does
not work (the exposed resources have their own root @Path defined,
(e.g. Path("/resource1"))
- using the "/resource1" as address string in the rsServer and
removing it from the Resource definition does not work
+ using the "/resource1" as address string and leaving it in the
@Path("/resource1") public interface Resource1...
does work, but leads to an URL like .../resource1/resource1...

i'd like to know if i have a conceptional problem?
can someone pls provide me with a fragment how it should look like to
use many resources, where each of the resource have their own route
definition.

thx in advance,
tim

Re: cxfrs: multiple resource howto?

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 11/09/12 13:24, Tim Emrich wrote:
> Hi Sergey,
>
> thx for your help!
>
> if i understood you correctly, then something like:
>
> <camel-cxf:rsServer id="endpoint1"
> 	address="/resource1"
> 	loggingFeatureEnabled="true" loggingSizeLimit="20"
> 	serviceClass="net.code-poets.camel.endpoint.v01.ResourceEndpoint1">
> </camel-cxf:rsServer>
>
> <camel-cxf:rsServer id="endpoint2"
> 	address="/resource2"
> 	loggingFeatureEnabled="true" loggingSizeLimit="20"
> 	serviceClass="net.code-poets..camel.endpoint.v01.ResourceEndpoint2">
> </camel-cxf:rsServer>
>
> should work, but when i changed the resource definitions of each
> resource to Path("/"), i got following trace:
>
> [INFO] [talledLocalContainer] 11.09.2012 13:46:34
> org.apache.cxf.jaxrs.utils.JAXRSUtils findTargetMethod
> [INFO] [talledLocalContainer] 11/09/2012 11:46:34 WARN
> (CustomProvider.java:208) toResponse -
> javax.ws.rs.WebApplicationException
> [INFO] [talledLocalContainer] javax.ws.rs.WebApplicationException: null
> [INFO] [talledLocalContainer] 	at
> org.apache.cxf.jaxrs.utils.JAXRSUtils.findTargetMethod(JAXRSUtils.java:415)
> ~[cxf-bundle-jaxrs-2.5.1.jar:2.5.1]
> [INFO] [talledLocalContainer] 	at
> org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:212)
> ~[cxf-bundle-jaxrs-2.5.1.jar:2.5.1]
> [INFO] [talledLocalContainer] 	at
> org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:89)
> ~[cxf-bundle-jaxrs-2.5.1.jar:2.5.1]
> ...
>
> from an URI perspective it should be no problem to distingush between
> the different resource:
> GET ../rest/resource1/{id} ->  endpoint1/
> GET ../rest/resource2/{id} ->  endpoint2
>
> or do i miss something?
>
The error is happening at the CXF level so something (request URI or 
something else) does not match. If you can create a Maven-based project 
or zip the war and attach to JIRA then I can have a look. Try also 
enabling FINE/TRACE log level, that should help

Cheers, Sergey

> TIA,
> tim
>
>
> 2012/9/11 Sergey Beryozkin<sb...@gmail.com>:
>> Hi
>>
>> Perhaps the following can help
>> On 11/09/12 11:52, Tim Emrich wrote:
>>>
>>> hello,
>>>
>>> i try to expose 2 or more resources using the cxfrs component (camel
>>> 2.10.1).
>>> One is working fine, but i don't find a proper solution to expose more
>>> then one.
>>>
>>> i tried several approaches but none of them worked as expected (at
>>> least what i expect ;-)):
>>>
>>> 1) one rsServer with many serviceBeans
>>> in the route i use something like
>>>
>>> "cxfrs:bean:rsServer?resourceClass=net.code-poets.camel.endpoint.v01.ResourceEndpoint1";
>>> ->   all requests are routed to just one endpoint
>>>
>>> 2) many rsServer instances with one serviceClass each
>>> - using the same address "/" attribute for all rsServer instances does
>>> not work (the exposed resources have their own root @Path defined,
>>> (e.g. Path("/resource1"))
>>> - using the "/resource1" as address string in the rsServer and
>>> removing it from the Resource definition does not work
>>> + using the "/resource1" as address string and leaving it in the
>>> @Path("/resource1") public interface Resource1...
>>> does work, but leads to an URL like .../resource1/resource1...
>>>
>>> i'd like to know if i have a conceptional problem?
>>> can someone pls provide me with a fragment how it should look like to
>>> use many resources, where each of the resource have their own route
>>> definition.
>>
>>
>> I believe the 2nd approach works, according to
>> http://camel.465427.n5.nabble.com/Apache-Camel-CXFRS-Server-Need-advice-for-Routing-td5699287.html
>>
>> Every endpoint or individual service beans within a single endpoint should
>> have unique Path values, otherwise, as in JAX-RS 1.1, the first matching
>> resource gets selected. The case of multiple resources having the same
>> top-level Path is handled better in JAX-RS 2.0 but in meantime top level
>> Path values have to be unique.
>>
>> The other possible workarounds:
>> - use a single root resource but introduce and delegate to subresource
>> locators
>> - use CXF specific comparator to resolve the ambiguous cases:
>> http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Customselectionbetweenmultipleresources
>> - consider using CXF jaxrs:endpoint directly, and using Camel transport to
>> delegate to it
>>
>> HTH, Sergey
>>
>>>
>>> thx in advance,
>>> tim
>>
>>
>>
>> --
>> Sergey Beryozkin
>>
>> Talend Community Coders
>> http://coders.talend.com/
>>
>> Blog: http://sberyozkin.blogspot.com

Re: cxfrs: multiple resource howto?

Posted by Tim Emrich <ti...@code-poets.net>.
Hi Sergey,

thx for your help!

if i understood you correctly, then something like:

<camel-cxf:rsServer id="endpoint1"
	address="/resource1"
	loggingFeatureEnabled="true" loggingSizeLimit="20"
	serviceClass="net.code-poets.camel.endpoint.v01.ResourceEndpoint1">
</camel-cxf:rsServer>

<camel-cxf:rsServer id="endpoint2"
	address="/resource2"
	loggingFeatureEnabled="true" loggingSizeLimit="20"
	serviceClass="net.code-poets..camel.endpoint.v01.ResourceEndpoint2">
</camel-cxf:rsServer>

should work, but when i changed the resource definitions of each
resource to Path("/"), i got following trace:

[INFO] [talledLocalContainer] 11.09.2012 13:46:34
org.apache.cxf.jaxrs.utils.JAXRSUtils findTargetMethod
[INFO] [talledLocalContainer] 11/09/2012 11:46:34 WARN
(CustomProvider.java:208) toResponse -
javax.ws.rs.WebApplicationException
[INFO] [talledLocalContainer] javax.ws.rs.WebApplicationException: null
[INFO] [talledLocalContainer] 	at
org.apache.cxf.jaxrs.utils.JAXRSUtils.findTargetMethod(JAXRSUtils.java:415)
~[cxf-bundle-jaxrs-2.5.1.jar:2.5.1]
[INFO] [talledLocalContainer] 	at
org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:212)
~[cxf-bundle-jaxrs-2.5.1.jar:2.5.1]
[INFO] [talledLocalContainer] 	at
org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:89)
~[cxf-bundle-jaxrs-2.5.1.jar:2.5.1]
...

from an URI perspective it should be no problem to distingush between
the different resource:
GET ../rest/resource1/{id} -> endpoint1/
GET ../rest/resource2/{id} -> endpoint2

or do i miss something?

TIA,
tim


2012/9/11 Sergey Beryozkin <sb...@gmail.com>:
> Hi
>
> Perhaps the following can help
> On 11/09/12 11:52, Tim Emrich wrote:
>>
>> hello,
>>
>> i try to expose 2 or more resources using the cxfrs component (camel
>> 2.10.1).
>> One is working fine, but i don't find a proper solution to expose more
>> then one.
>>
>> i tried several approaches but none of them worked as expected (at
>> least what i expect ;-)):
>>
>> 1) one rsServer with many serviceBeans
>> in the route i use something like
>>
>> "cxfrs:bean:rsServer?resourceClass=net.code-poets.camel.endpoint.v01.ResourceEndpoint1";
>> ->  all requests are routed to just one endpoint
>>
>> 2) many rsServer instances with one serviceClass each
>> - using the same address "/" attribute for all rsServer instances does
>> not work (the exposed resources have their own root @Path defined,
>> (e.g. Path("/resource1"))
>> - using the "/resource1" as address string in the rsServer and
>> removing it from the Resource definition does not work
>> + using the "/resource1" as address string and leaving it in the
>> @Path("/resource1") public interface Resource1...
>> does work, but leads to an URL like .../resource1/resource1...
>>
>> i'd like to know if i have a conceptional problem?
>> can someone pls provide me with a fragment how it should look like to
>> use many resources, where each of the resource have their own route
>> definition.
>
>
> I believe the 2nd approach works, according to
> http://camel.465427.n5.nabble.com/Apache-Camel-CXFRS-Server-Need-advice-for-Routing-td5699287.html
>
> Every endpoint or individual service beans within a single endpoint should
> have unique Path values, otherwise, as in JAX-RS 1.1, the first matching
> resource gets selected. The case of multiple resources having the same
> top-level Path is handled better in JAX-RS 2.0 but in meantime top level
> Path values have to be unique.
>
> The other possible workarounds:
> - use a single root resource but introduce and delegate to subresource
> locators
> - use CXF specific comparator to resolve the ambiguous cases:
> http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Customselectionbetweenmultipleresources
> - consider using CXF jaxrs:endpoint directly, and using Camel transport to
> delegate to it
>
> HTH, Sergey
>
>>
>> thx in advance,
>> tim
>
>
>
> --
> Sergey Beryozkin
>
> Talend Community Coders
> http://coders.talend.com/
>
> Blog: http://sberyozkin.blogspot.com

Re: cxfrs: multiple resource howto?

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

Perhaps the following can help
On 11/09/12 11:52, Tim Emrich wrote:
> hello,
>
> i try to expose 2 or more resources using the cxfrs component (camel 2.10.1).
> One is working fine, but i don't find a proper solution to expose more then one.
>
> i tried several approaches but none of them worked as expected (at
> least what i expect ;-)):
>
> 1) one rsServer with many serviceBeans
> in the route i use something like
> "cxfrs:bean:rsServer?resourceClass=net.code-poets.camel.endpoint.v01.ResourceEndpoint1";
> ->  all requests are routed to just one endpoint
>
> 2) many rsServer instances with one serviceClass each
> - using the same address "/" attribute for all rsServer instances does
> not work (the exposed resources have their own root @Path defined,
> (e.g. Path("/resource1"))
> - using the "/resource1" as address string in the rsServer and
> removing it from the Resource definition does not work
> + using the "/resource1" as address string and leaving it in the
> @Path("/resource1") public interface Resource1...
> does work, but leads to an URL like .../resource1/resource1...
>
> i'd like to know if i have a conceptional problem?
> can someone pls provide me with a fragment how it should look like to
> use many resources, where each of the resource have their own route
> definition.

I believe the 2nd approach works, according to
http://camel.465427.n5.nabble.com/Apache-Camel-CXFRS-Server-Need-advice-for-Routing-td5699287.html

Every endpoint or individual service beans within a single endpoint 
should have unique Path values, otherwise, as in JAX-RS 1.1, the first 
matching resource gets selected. The case of multiple resources having 
the same top-level Path is handled better in JAX-RS 2.0 but in meantime 
top level Path values have to be unique.

The other possible workarounds:
- use a single root resource but introduce and delegate to subresource 
locators
- use CXF specific comparator to resolve the ambiguous cases:
http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Customselectionbetweenmultipleresources
- consider using CXF jaxrs:endpoint directly, and using Camel transport 
to delegate to it

HTH, Sergey

>
> thx in advance,
> tim


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com