On 09.03.2011, at 16:41, Bill Burke wrote:
> The problem is that he wants to inject information about the sub resource into the creation of the EJB.
And this is a huge problem. It happens in every non-trivial application.
> You can't use a pojo or entity because you may want to do transactions within the subresource (or other functions that EJB provides).
And injection. If you are using a POJO it cannot be even a CDI managed bean.
>
> Adam, are you sure the new EJB singleton beans wouldn't allow for this?
Singleton would work - but then you will get concurrency issues (=bottlenecks). If you make them BeanManagedConcurrency you will get consistencies issue. @Stateful would not work as well.
The simplest possible solution would be something like:
@Stateless
public SubResource{
@PathParam
long id;
}
or the injection of a more generic "JAX-RS" context into EJB / CDI bean.
>
>
> On 3/9/11 10:05 AM, Marek Potociar wrote:
>> Hi Adam,
>> I am still not sure I fully follow the problem being described. Could you please provide a code snippet(s) that demonstrate:
>> 1. what is the current problem
>> 2. example of a desired solution that solves 1.
>>
>> Many thanks,
>> Marek
>>
>> On 03/08/2011 09:02 PM, Adam Bien wrote:
>>> 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
>>>>>
>>>>
>>>>
>>>
>>>
>
> --
> Bill Burke
> JBoss, a division of Red Hat
> http://bill.burkecentral.com
>