Skip to main content

Problem with accessing EJB Components in a Remote GlassFish Server

4 replies [Last post]
Grauzone
Offline
Joined: 2014-01-22
Points: 0

Hello,

i've got 2 GF 4 ....

on one(Service-GF) is the EJB deployed as an EAR Package!

And on the other one (Client-GF) we deployed an WAR Package.

The goal is to get access from the Client-GF (Business Activity Classes) to the Remote (Business Activity Classes) on the Service-GF.

Service-GF Interface Code:

public interface IBackendConfigurationBA {

public void createConfig(ConfigurationModel configurationModel);

[...]

Service-GF Bean Code:

@Singleton(name="BackendConfigurationBA", mappedName="BackendConfigurationBA")
@Startup
@Remote(IBackendConfigurationBA.class)
public class BackendConfigurationBA implements IBackendConfigurationBA {

private final Logger logger = LoggerFactory.getLogger(CirrusConfig.class);

private CirrusConfig cirrusConfig = CirrusConfig.getInstance();

private BackendConfigurationMapper configurationMapper = new BackendConfigurationMapper();

@EJB(beanName = "BackendConfigurationDAO")
private IBackendConfigurationDAO backendConfigDAO;

[...]

Client-GF Interface Code:

public interface IFrontendConfigurationBA {

public void reloadConfigs();

[...]

Client-GF Bean Code:

@Singleton
@Remote(IFrontendConfigurationBA.class)
public class FrontendConfigurationBA implements IFrontendConfigurationBA{

private final Logger logger = LoggerFactory.getLogger(CirrusConfig.class);

@EJB(name ="BackendConfigurationBA")
private IBackendConfigurationBA backendConfigurationBA;

[...]

What strategy should I use in order to connect both with each other.

I read here: http://docs.oracle.com/cd/E26576_01/doc.312/e24930/jndi.htm

The ejb-ref element in glassfish-web.xml looks like this:


ejb/Foo
corbaname:iiop:host:port#a/b/Foo

in my case...i did this:


BackendConfigurationBA
corbaname:iiop::3700#path/to/BackendConfigurationBA

But this doesn't help. I get the Error:

[2014-01-22T13:54:22.516+0100] [glassfish 4.0] [SEVERE] [] [global] [tid: _ThreadID=37 _ThreadName=admin-listener(3)] [timeMillis: 1390395262516] [levelValue: 1000] [[
Class [ Lde/br/wtr/be/activity/configuration/IBackendConfigurationBA; ] not found. Error while loading [ class de.br.wtr.fe.configuration.FrontendConfigurationBA ]]]

[...]

[2014-01-22T13:54:22.657+0100] [glassfish 4.0] [SEVERE] [NCLS-CORE-00026] [javax.enterprise.system.core] [tid: _ThreadID=37 _ThreadName=admin-listener(3)] [timeMillis: 1390395262657] [levelValue: 1000] [[
Exception during lifecycle processing
java.lang.IllegalArgumentException: Invalid ejb jar wtr-web-0.0.1-SNAPSHOT: it contains zero ejb. A valid ejb jar requires at least one session/entity/message driven bean.
at org.glassfish.ejb.deployment.util.EjbBundleValidator.accept(EjbBundleValidator.java:147)
at org.glassfish.ejb.deployment.util.EjbBundleValidator.accept(EjbBundleValidator.java:112)
at com.sun.enterprise.deployment.BundleDescriptor.visit(BundleDescriptor.java:621)
at org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl.visit(EjbBundleDescriptorImpl.java:757)
at com.sun.enterprise.deployment.util.ApplicationValidator.accept(ApplicationValidator.java:116)
at com.sun.enterprise.deployment.BundleDescriptor.visit(BundleDescriptor.java:621)
at com.sun.enterprise.deployment.archivist.ApplicationFactory.openArchive(ApplicationFactory.java:190)
at org.glassfish.javaee.core.deployment.DolProvider.processDOL(DolProvider.java:198)
at org.glassfish.javaee.core.deployment.DolProvider.load(DolProvider.java:222)
at org.glassfish.javaee.core.deployment.DolProvider.load(DolProvider.java:96)
at com.sun.enterprise.v3.server.ApplicationLifecycle.loadDeployer(ApplicationLifecycle.java:878)
at com.sun.enterprise.v3.server.ApplicationLifecycle.setupContainerInfos(ApplicationLifecycle.java:818)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:374)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:527)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:523)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:356)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:522)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:546)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1423)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1500(CommandRunnerImpl.java:108)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1762)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1674)
at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:534)
at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:224)
at org.glassfish.grizzly.http.server.StaticHttpHandler.service(StaticHttpHandler.java:297)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:246)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:722)
]]

[2014-01-22T13:54:22.664+0100] [glassfish 4.0] [SEVERE] [] [javax.enterprise.system.core] [tid: _ThreadID=37 _ThreadName=admin-listener(3)] [timeMillis: 1390395262664] [levelValue: 1000] [[
Exception while deploying the app [wtr-web-0.0.1-SNAPSHOT] : Invalid ejb jar wtr-web-0.0.1-SNAPSHOT: it contains zero ejb. A valid ejb jar requires at least one session/entity/message driven bean.]]

Thank you in advance

Grau

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Grauzone
Offline
Joined: 2014-01-22
Points: 0

Hello again :)

no one an idea? Sorry, probably too much text.

It would really help, if somone has or know an example how to access a EJB that is packed in a EAR file from an WAR with 2 !seperate! Glashfish 4 servers (javaee7).

Its really exhausting to find something useful in the web. Where i have to register the access? ...in the ejb-jar.xml or glassfish-ejb-jar.xml or in the admin console of the Glassfish or in the glassfish-web.xml ...and so on....

And how ... there a so many variants how to reference an remote EJB ?

corbaname:iiop:ip:3700#java:global[/app-name]/module-name/bean-name

I need to adjust something in the server (admin console)? Or can i put the settings in the admin console of the server an refer the access over a different way?

There are sooooooo much possible locations : ( I would bet, a lot of users are confused about this topic.

Thank you in advance for your time!

A goodie .... that ive found somewhere in the web... LOL:

>> Quote: "I solved my problem, I migrate to JBoss 7.1.1, read the tutorial https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote... and in my first test all worked fine, in the way that I desired but using JBoss instead Glassfish."

f3riyanto
Offline
Joined: 2013-10-23
Points: 0

Dear Grauzone,

to access an EJB from remote you have the points below

1. Make sure your EJB is set as @Remote EJB, so the ejb can be accessed from different JVM.
You can use @Local when client and EJB is in the same JVM

for example

@Remote
public interface CustomerBeanRemote {

//your code here
}

2. Implements the interface into the EJB class, in this case i'am use Singleton EJB
you can also use the same thing for stateless and statefull.

@Singleton(name="CustomerBeanRemote", mappedName="CustomerBeanRemote), description="CustomerBeanRemote")
public class CustomerBean implements CustomerBeanRemote {
//your code here
}

3. To accessing your EJB then create some synchronize method and add this properties to be used for each time you create initialcontext object

Properties props = new Properties();
props.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
props.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");

// optional. Defaults to localhost. Only needed if web server is running
// on a different host than the appserver
props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");

// optional. Defaults to 3700. Only needed if target orb port is not 3700.
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");

InitialContext ic = new InitialContext(props);
CustomerBeanRemote cbr = (CustomerBeanRemote)ic.lookup("CustomerBean");
cbr.someMethod();

4. Glassfish has been provide some client container called ACC --> Application client provider
When you create an EJB client application. then the configuration in point 3 is no need to create manually.
Glassfish will create it for you.

Hope this answer will help you to solve the problem.
Just give me some feedback if you have some problem.

Thanks
Ferry

Grauzone
Offline
Joined: 2014-01-22
Points: 0

Hey Ferry,

thanks a lot for your replay!!!

I made Points 1. and 2. this is clear.

But Points 3. and 4. are my Problems.

1. The Ejb (EAR File) is NOT on the same maschine as my Webapplication (WAR File). I think i must add the properties to my Webapplication, because how could my WAR know where to find the remote ejb

2. Then i have another Problem.
Can I access the EJBwith the annotation @EJB?
Is this Initial Context bla in this case necessary? Don't get me wrong, but if you have this annotation already, then I have a feeling that this procedure (Initial Context) is in some cases perhaps very laborious.
I thought, that Java will make some voodoo (concerning on the annotation) and lookup for my Remote EJB, assuming I've set the correct properties.

3. An once another question.
Can I set the properties in the admin backend of the Glassfish (http://localhost:4848). I found the topic:
Configurations > server-config > ORB > IIOP Listeners
Is this the right place to refere the remote maschine and do I have something to consider?

Thanks a lot (and for your time!)
Vladimir

f3riyanto
Offline
Joined: 2013-10-23
Points: 0

Hi Vladimir,

1. yes, i agreed with you

2. Off course, you can use @EJB to access an EJB but you need to define @LocalBean in the session bean class and
this annotation only can be used for accesing local EJB. Please refer to EJB 3.1 for further information.

Commonly initialContext properties will need to be define, if you want to access an EJB from remote/another server.
You can try this properties as in my replied email before (point 3).
I usually use this way rather than use container configuration.

you can refer to this answer : http://stackoverflow.com/questions/3636507/access-to-remote-ejb-running-...

3. Yes, that configuration is used to configure IIOP port listener that your remote server will listen for IIOP Request. default 3700

Hope this will help you

Thanks
Ferry