Skip to main content

Problem with JAXRS+JAXWS+Stateless EJB together on GFV3 Preview

7 replies [Last post]
Anonymous

Hi,

I¹ve tried to put on same class a stateless ejb with jaxrs and jaxws.
Example:

@Stateless
@Path(³root²)
@WebService
public class RootResource {
@GET
@WebMethod
public String get() { return ³lol²; }
}

With this configuration GF says that webservice must have an interface, ok I
did that:
...
public class RootResource implements NullInterface {
...
}

So the app could be deployed. When tryin¹ to access the resource by REST,
jersey threw exception sayin¹:

³the object is not instance of declaring class²

So I realize that whether I take off the interface (and also the @webservice
annotation) everythin¹ works. I also tried the Resource without EJB (and
without jaxws) annotation implementing an interface and everythin¹ works.
Then, I realize the problem is within EJB+Rest+interface, its seems that
jersey cannot handle it, eg:

@Stateless
@Path(³root²)
Public class RootResource implements NullInterface {
@GET
public String get( ) { return ³no you don¹t!²; }
}

Anyone can give me a hint about this problem? It¹s look like a bug to me.

Thanks.
[att1.html]

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Paulo Cesar Reis

Thanks Paul, the first workaround sounds better for me, I'm goin' to try
that, would be nice if jersey could threat that for me though.

Thanks.

On 10/21/09 9:05 AM, "Paul Sandoz" wrote:

> Hi,
>
> Felipe, this is not about injecting EJBs into resource classes [*]. It
> is about a resource class *being* an EJB, in this case a stateless
> session bean POJO.
>
> When looking up the reference to the SSB using JNDI a reference to the
> interface is returned instead of a reference to the POJO. Ken can
> confirm but that i think that is a spec requirement.
>
>
> You need to do the following:
>
> 1) declare the annotated methods on the interface; and
>
> 2) remove the annotations on the implementing methods.
>
> @Stateless
> @Path(³root²)
> public class RootResource implements IFace {
> public String get() { return ³lol²; }
> }
>
> public interface IFace {
> @GET
> public String get() { return ³lol²; }
> }
>
>
> Jersey uses the annotations on the Java method to determine what
> Method instance should be utilized for invocation. The returned
> reference, a proxy, from JNDI is not an instance of RootResource.
> Hence the error.
>
> I think Jersey can be modified in two ways:
>
> 1) Always use the Method instance from an interface (if present) for
> invocation; and
>
> 2) Log an error if the SSB class implements annotated methods that are
> not declared on an interface (if present).
>
> Paul.
>
> [*] If you are using the latest GF v3 and you annotate your resource
> class with @ManagedBean you will no longer require the custom EJB
> provider.
>
>
> On Oct 21, 2009, at 12:12 PM, glassfish@javadesktop.org wrote:
>
>> Yes, Jersey cannot inject EJBs.. you should use an EJB Provider...
>>
>> in my project I have an example:
>>
>> http://kenai.com/projects/puj/sources/arena/show/arena-http/src/main/jav...
>> /kenai/puj/arena/http
>> [Message sent by forum member 'felipegaucho' (fgaucho@gmail.com)]
>>
>> http://forums.java.net/jive/thread.jspa?messageID=368770
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
>> For additional commands, e-mail: users-help@glassfish.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

felipegaucho
Offline
Joined: 2003-06-13

Yes, Jersey cannot inject EJBs.. you should use an EJB Provider...

in my project I have an example:

http://kenai.com/projects/puj/sources/arena/show/arena-http/src/main/jav...

Paul Sandoz

Hi,

Felipe, this is not about injecting EJBs into resource classes [*]. It
is about a resource class *being* an EJB, in this case a stateless
session bean POJO.

When looking up the reference to the SSB using JNDI a reference to the
interface is returned instead of a reference to the POJO. Ken can
confirm but that i think that is a spec requirement.

You need to do the following:

1) declare the annotated methods on the interface; and

2) remove the annotations on the implementing methods.

@Stateless
@Path(“root”)
public class RootResource implements IFace {
public String get() { return “lol”; }
}

public interface IFace {
@GET
public String get() { return “lol”; }
}

Jersey uses the annotations on the Java method to determine what
Method instance should be utilized for invocation. The returned
reference, a proxy, from JNDI is not an instance of RootResource.
Hence the error.

I think Jersey can be modified in two ways:

1) Always use the Method instance from an interface (if present) for
invocation; and

2) Log an error if the SSB class implements annotated methods that are
not declared on an interface (if present).

Paul.

[*] If you are using the latest GF v3 and you annotate your resource
class with @ManagedBean you will no longer require the custom EJB
provider.

On Oct 21, 2009, at 12:12 PM, glassfish@javadesktop.org wrote:

> Yes, Jersey cannot inject EJBs.. you should use an EJB Provider...
>
> in my project I have an example:
>
> http://kenai.com/projects/puj/sources/arena/show/arena-http/src/main/jav...
> [Message sent by forum member 'felipegaucho' (fgaucho@gmail.com)]
>
> http://forums.java.net/jive/thread.jspa?messageID=368770
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

felipegaucho
Offline
Joined: 2003-06-13

[*] If you are using the latest GF v3 and you annotate your resource
class with @ManagedBean you will no longer require the custom EJB
provider.

much better.. but then I get back to my original problem in the other thread, I am trying without success to inject the EJB in the ManagedBean :)

I have in the same EAR a war file with the Jersey Service and other war file with a JSF2 application.. the jersey Service always worked with the EjbProvider, I will try on the evening to use the trick with the managedbean.. let's see.. once I cross this issue I will finally unveil the full powers of my EAR application :)

Paul Sandoz

On Oct 21, 2009, at 1:42 PM, glassfish@javadesktop.org wrote:

> [*] If you are using the latest GF v3 and you annotate your resource
> class with @ManagedBean you will no longer require the custom EJB
> provider.
>
>
> much better.. but then I get back to my original problem in the
> other thread, I am trying without success to inject the EJB in the
> ManagedBean :)
>
> I have in the same EAR a war file with the Jersey Service and other
> war file with a JSF2 application.. the jersey Service always worked
> with the EjbProvider, I will try on the evening to use the trick
> with the managedbean.. let's see.. once I cross this issue I will
> finally unveil the full powers of my EAR application :)
> [Message sent by forum member 'felipegaucho' (fgaucho@gmail.com)]

You might want to try placing you @ManagedBean annotated root resource
classes in the war.

@ManagedBean
@Path("/root")
public class MyResourceClass {
}

Paul.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

Felipe Gaucho

Yes, they are in the war... It is some problem with naming...

On 21.10.2009, at 13:51, Paul Sandoz wrote:

>
> On Oct 21, 2009, at 1:42 PM, glassfish@javadesktop.org wrote:
>
>> [*] If you are using the latest GF v3 and you annotate your resource
>> class with @ManagedBean you will no longer require the custom EJB
>> provider.
>>
>>
>> much better.. but then I get back to my original problem in the
>> other thread, I am trying without success to inject the EJB in the
>> ManagedBean :)
>>
>> I have in the same EAR a war file with the Jersey Service and other
>> war file with a JSF2 application.. the jersey Service always worked
>> with the EjbProvider, I will try on the evening to use the trick
>> with the managedbean.. let's see.. once I cross this issue I will
>> finally unveil the full powers of my EAR application :)
>> [Message sent by forum member 'felipegaucho' (fgaucho@gmail.com)]
>
>
> You might want to try placing you @ManagedBean annotated root
> resource classes in the war.
>
> @ManagedBean
> @Path("/root")
> public class MyResourceClass {
> }
>
> Paul.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

felipegaucho
Offline
Joined: 2003-06-13