jsr339-experts@jax-rs-spec.java.net

[jsr339-experts] Re: First steps

From: Adam Bien <abien_at_adam-bien.com>
Date: Tue, 8 Mar 2011 21:02:20 +0100

Hi Markus

please see inline comments:

On 08.03.2011, at 18:38, Markus KARG wrote:

> Seems like I'm a bit slow on the uptake today... ;-) Can you post a short
> snippet of what you try to achieve and what the exact problem is? I mean,
> you can just create a new object inside the sub-resource locator and pass a
> path param as the PK into the constructor manually (or use it as a JPA query
> criteria), which both is rather short and simple.
>
> @GET @Path("{pk}")
> public Pojo getPojo(@PathParam("pk") T pk) {
> return new Pojo (pk);
> }
Works and is o.k.
>
> @EJB SB sb;
> @GET @Path("{pk}")
> public SB getSb(@PathParam("pk") T pk) {
> sb.setPk(pk);
> return sb;
> }
It doesn't work - you cannot maintain client-specific state in a Stateless Session bean. You will need to pass the context in different way.
One possibility would be to inject a JAX-RS context into an EJB and fetch the current id from that.

>
> @GET @Path("{pk}")
> public Entity getEntity(@PathParam("pk") T pk) {
> return em.find(Entity.class, pk);
> }
Works of course.
>
> How would you like the solution to look like in terms of Java syntax? Maybe
> we then see more clear the elegance you expect.

Passing parameters from JAX-RS to stateless session beans as sub-resource locators is the problem. It happens in all non-trivial applications.
You could use POJOs, but then you will need another transactional layer or implement transactions buy yourself..

thanks for the code! :-),

adam
>
> Regards
> Markus
>
>> -----Original Message-----
>> From: Adam Bien [mailto:abien_at_adam-bien.com]
>> Sent: Montag, 7. März 2011 20:36
>> To: jsr339-experts_at_jax-rs-spec.java.net
>> Subject: [jsr339-experts] Re: First steps
>>
>> In sub-resource locator you are usually passing an URI (from
>> @PathParam).
>> There is no elegant way right now to implement that with EJB 3.1.
>>
>> With POJOs it is not a big problem - you can pass the URI (usually a
>> PK) in a constructor...
>>
>> Constructor injection of the current context would be nice...
>>
>> thanks!,
>>
>> adam
>>
>>
>> On 07.03.2011, at 14:57, Bill Burke wrote:
>>
>>>
>>>
>>> On 3/6/11 4:00 AM, Adam Bien wrote:
>>>> Hi Roberto,
>>>>
>>>> better intergration with EJB 3.2 would be also nice. E.g. it is hard
>> right now to use EJB 3.2 as a sub-resource.
>>>>
>>>
>>>
>>> @EJB Sub sub;
>>>
>>> @Path("sub")
>>> public Sub getSub() { return sub; }
>>>
>>> ?
>>>
>>> --
>>> Bill Burke
>>> JBoss, a division of Red Hat
>>> http://bill.burkecentral.com
>>
>
>