You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Jason Chaffee <ja...@phalula.com> on 2013/03/07 06:12:49 UTC
subresource issue
I would like to do something similar to the order/product example outlined here:
http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Subresourcelocators.
However, I would like to have my CustomerService.getOrder(String id) and the the Order.getProduct(String id) return Response objects so that I can customize the headers. However, when I do that, it doesn't seem to work. I have to return the raw entity objects.
I would think it could be smart enough to grab the entity object out of the Response object and still find the correct path.
Any thoughts?
Jason
Re: subresource issue
Posted by Sergey Beryozkin <sb...@gmail.com>.
On 07/03/13 10:35, Jason Chaffee wrote:
> I would want to return a Resource on CustomerService.getOrder(String orderId)
>
> So, in the example you have this:
>
> @Path("/customerservice/")
> public class CustomerService {
>
> @Path("/orders/{orderId}/")
> public Order getOrder(@PathParam("orderId") String orderId) {
> ......
> }
> }
>
>
> I would like to do it like this:
>
> @Path("/customerservice/")
> public class CustomerService {
>
> @Path("/orders/{orderId}/")
> public Response getOrder(@PathParam("orderId") String orderId) {
> ......
> }
> }
>
>
> That way a GET on /customerservice/orders/1234 would have custom headers, etc. However, I would still like to have a sub-resource defined on the Order object that is the entity in the Resource so that this call works
>
> GET http://localhost:9000/customerservice/orders/223/products/323
>
> So that it calls getOrder(223) first and that returns a Response object with an entity and that entity is the Order objet. So, next you call getProducts(323) on that object.
Either the following:
@Path("/customerservice/")
public class CustomerService {
@Path("/orders/{orderId}/")
public Order getOrder(@PathParam("orderId") String orderId) {
return doGetOrder(orderId);
}
@GET
@Path("/orders/{orderId}/")
public Response getOrder(@PathParam("orderId") String orderId) {
return Response.ok(doGetOrder(orderId)).header("a", "b").build();
}
private Order doGetOrder(String orderId) {
...
}
}
or
@Path("/customerservice/")
public class CustomerService {
@Path("/orders/{orderId}/")
public Order getOrder(@PathParam("orderId") String orderId) {
...
}
}
public class Order {
@GET
public Response get() {return this};
@GET @Path("product")
public Response getProduct() {...}
}
will work.
It is not possible to have a single method acting both as a subresource
locator and the final resource method,
HTH, Sergey
>
> Jason
>
>
> On Mar 7, 2013, at 2:13 AM, Sergey Beryozkin<sb...@gmail.com> wrote:
>
>> Hi
>> On 07/03/13 05:12, Jason Chaffee wrote:
>>> I would like to do something similar to the order/product example outlined here:
>>>
>>> http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Subresourcelocators.
>>>
>>>
>>> However, I would like to have my CustomerService.getOrder(String id) and the the Order.getProduct(String id) return Response objects so that I can customize the headers. However, when I do that, it doesn't seem to work. I have to return the raw entity objects.
>>>
>>>
>>> I would think it could be smart enough to grab the entity object out of the Response object and still find the correct path.
>>>
>> Do you mean you are actually returning Response from subresource locator ? For example,
>>
>> Path("/")
>> public class Root {
>> @Path("/sub")
>> public Response getSubResource() {
>> ...
>> }
>> }
>>
>> if not, can you please type an example here ?
>>
>> In the wiki example, returning Response from Order.getProduct really has to work but not if Response returned from CustomerService.getOrder,
>>
>> Sergey
>>
>>>
>>> Any thoughts?
>>>
>>> Jason
>>
>>
>
>
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com
Re: subresource issue
Posted by Jason Chaffee <ja...@phalula.com>.
I would want to return a Resource on CustomerService.getOrder(String orderId)
So, in the example you have this:
@Path("/customerservice/")
public class CustomerService {
@Path("/orders/{orderId}/")
public Order getOrder(@PathParam("orderId") String orderId) {
......
}
}
I would like to do it like this:
@Path("/customerservice/")
public class CustomerService {
@Path("/orders/{orderId}/")
public Response getOrder(@PathParam("orderId") String orderId) {
......
}
}
That way a GET on /customerservice/orders/1234 would have custom headers, etc. However, I would still like to have a sub-resource defined on the Order object that is the entity in the Resource so that this call works
GET http://localhost:9000/customerservice/orders/223/products/323
So that it calls getOrder(223) first and that returns a Response object with an entity and that entity is the Order objet. So, next you call getProducts(323) on that object.
Jason
On Mar 7, 2013, at 2:13 AM, Sergey Beryozkin <sb...@gmail.com> wrote:
> Hi
> On 07/03/13 05:12, Jason Chaffee wrote:
>> I would like to do something similar to the order/product example outlined here:
>>
>> http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Subresourcelocators.
>>
>>
>> However, I would like to have my CustomerService.getOrder(String id) and the the Order.getProduct(String id) return Response objects so that I can customize the headers. However, when I do that, it doesn't seem to work. I have to return the raw entity objects.
>>
>>
>> I would think it could be smart enough to grab the entity object out of the Response object and still find the correct path.
>>
> Do you mean you are actually returning Response from subresource locator ? For example,
>
> Path("/")
> public class Root {
> @Path("/sub")
> public Response getSubResource() {
> ...
> }
> }
>
> if not, can you please type an example here ?
>
> In the wiki example, returning Response from Order.getProduct really has to work but not if Response returned from CustomerService.getOrder,
>
> Sergey
>
>>
>> Any thoughts?
>>
>> Jason
>
>
Re: subresource issue
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 07/03/13 05:12, Jason Chaffee wrote:
> I would like to do something similar to the order/product example outlined here:
>
> http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Subresourcelocators.
>
>
> However, I would like to have my CustomerService.getOrder(String id) and the the Order.getProduct(String id) return Response objects so that I can customize the headers. However, when I do that, it doesn't seem to work. I have to return the raw entity objects.
>
>
> I would think it could be smart enough to grab the entity object out of the Response object and still find the correct path.
>
Do you mean you are actually returning Response from subresource locator
? For example,
Path("/")
public class Root {
@Path("/sub")
public Response getSubResource() {
...
}
}
if not, can you please type an example here ?
In the wiki example, returning Response from Order.getProduct really has
to work but not if Response returned from CustomerService.getOrder,
Sergey
>
> Any thoughts?
>
> Jason