jbossjax-rsresteasyejb-3.1session-bean

JAX-RS on EJB 3.1 Session Bean which only has Remote Interface


Can I use JAX-RS annotations like @Path on an EJB 3.1 session bean which only has a remote interface?

This works:

@Path("/service")
@Stateless
public class ServiceOne {
    @POST
    @Path("/foo")
    public Response foo() {
        return Response.ok().build();
    }
}

However, if I add a remote interface...

@Remote
public interface ServiceOneRemote {
    Response foo();
}

@Path("/service")
@Stateless
public class ServiceOne implements ServiceOneRemote {
    @POST
    @Path("/foo")
    public Response foo() {
        return Response.ok().build();
    }
}

... I get a NotSerializableException

java.io.NotSerializableException: org.jboss.resteasy.core.ServerResponse
    org.jboss.marshalling.cloner.SerializingCloner.clone(SerializingCloner.java:253)
    org.jboss.marshalling.cloner.SerializingCloner.clone(SerializingCloner.java:128)
    org.jboss.as.ejb3.remote.LocalEjbReceiver.clone(LocalEjbReceiver.java:295)
    org.jboss.as.ejb3.remote.LocalEjbReceiver.clone(LocalEjbReceiver.java:286)
    org.jboss.as.ejb3.remote.LocalEjbReceiver.processInvocation(LocalEjbReceiver.java:258)
    org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:184)
    org.jboss.ejb.client.EJBObjectInterceptor.handleInvocation(EJBObjectInterceptor.java:58)
    org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)
    org.jboss.ejb.client.EJBHomeInterceptor.handleInvocation(EJBHomeInterceptor.java:83)
    org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)
    org.jboss.ejb.client.TransactionInterceptor.handleInvocation(TransactionInterceptor.java:42)
    org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)
    org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:125)
    org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)
    org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:255)
    org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:200)
    org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:183)
    org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146)
    com.sun.proxy.$Proxy88.foo(Unknown Source)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:483)
    org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:168)
    org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:269)
    org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:227)
    org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:216)
    org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:541)
    org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:523)
    org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:125)
    org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)
    org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
    org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

From articles like Implementing RESTful views of an EJB with local interfaces I get the impression that JAX-RS only works with session beans that have a local interface. But I could not find any resource that explicitly states that it is not possible.

Am I doing something wrong? Or is this just not possible?

Btw: I am running a JBoss EAP 6.4 application server.


Solution

  • It is not possible. In JSR-339 (The JavaTM API for RESTful Web Services) specification this is stated as follows:

    JAX-RS annotations can be applied to methods in an EJB’s local interface or directly to methods in a no-interface EJB.