3

I've got an ear with the following structure:

  • app-ear
    • app-api
    • app-ejb
    • app-web

The app-web and app-ejb depends on the app-api module, but they are not depending on each other.

The interfaces (app-api) and the bean (app-ejb):

package sample.services;

@Remote
public interface SampleServiceRemote{
    ...
}


package sample.services;

@Local
public interface SampleService extends SampleServiceRemote{
    ...
}

package sample.services;

@Stateless
@Local(SampleService.class)
@Remote(SampleServiceRemote.class)
public class SampleServiceBean implements SampleService{
    ...
}

I want to lookup for the SampleServiceBean with Local and Remote interface from the app-api and app-web modules:

InitialContext ic = new InitialContext();

//Case #1: Works fine without any exception
SampleServiceRemote service = (SampleServiceRemote) ic.lookup("java:global/app-ear/app-ejb/SampleServiceBean!sample.services.SampleServiceRemote");

//Case #2: Throws ClassCastException
SampleService service = (SampleService) ic.lookup("java:global/app-ear/app-ejb/SampleServiceBean!sample.services.SampleService");

When I lookup with the local interface on a WildFly server (9.0.1.Final), it gives back a sample.services.SampleService$$$view4 object, which cannot be casted to SampleService.

I tried the same application on Glassfish 4.1, but there it is working pretty well. The returned objects:

  • Remote: javax.naming.Reference (castable to SampleServiceRemote)
  • Local: com.sun.ejb.containers.JavaGlobalJndiNamingObjectProxy (castable to SampleService)

Can somebody tell me, how can I achieve the same behavior on WildFly?

Update 1

I tried the solution recommended by user140547. It didn't work. It gives back the same classes :/.

Update 2

After several days of trying, and Googleing I decided to exclude the EJB from my project. They are not necessary, and I can do the without them. The problem was, when I tried to use the bean as Local, the Wildfly always gave me some Proxy class, which cannot be casted to the Local interface (neither to the Remote interface). I can get Local reference only with the @EJB annotation, but outside of the EJB module it gave back only a null :/.

Zolee
  • 31
  • 1
  • 5
  • if you try use interfaces like in the answer to http://stackoverflow.com/questions/1351431/can-i-use-inheritance-in-remote-local-interfaces-ejb3, does it work then? also, is it not redundant to use `@Local` and `@Remote` on both the interface and the bean? – user140547 Oct 29 '15 at 14:19
  • Independent of your specific problem - 1st) why do you use ear-deployment and 2nd) why do you use JNDI to lookup and not an injection mechanism? – Alexander Rühl Oct 30 '15 at 11:14
  • 1st) I'm using EAR, because I want to create a JMS Utility web application, and I don't want many file. The web will contains some REST services, and a basic HTML for test, etc. 2nd) I want to use the JNDI lookup only from the web tier, and not form the EJB. I tried the `@Inject` and `@EJB`, but the web is out of EJB containter. The `@Inject` version cannot be deployed, the `@EJB` gives NullPointerException. – Zolee Oct 30 '15 at 17:43
  • Possible duplicate of [WildFly JNDI lookup for local EJB deployed in a WAR](http://stackoverflow.com/questions/26018100/wildfly-jndi-lookup-for-local-ejb-deployed-in-a-war) – Gregor Nov 29 '16 at 10:49

1 Answers1

0

See this question: access a Local Session Bean from another EAR? it seems that accessing a local bean from another application is an optional feature of EJB, so it may work on Glassfish, but not on Wildfly.

on the other hand, your question is about with an EAR. But if this answer also applies to you, it has not anything to do with the @Remote interface also being provided.

Community
  • 1
  • 1
user140547
  • 7,750
  • 3
  • 28
  • 80