I am using Weblogic 11g, EJB3.0.
I am trying to do simple look up from one deployment to another in the same machine. But no success.
This is the code:
In one deployment this is the target class:
#CallByReference
#Stateless (mappedName = "ejb/SyncOperatorsBean")
#Local ({SyncOperatorsBeanLocal.class})
#Remote ({SyncOperatorsBeanRemote.class})
#JNDIName("ejb/SyncOperatorsBean") //added
public class SyncOperatorsBean implements SyncOperatorsBeanLocal,SyncOperatorsBeanRemote
...
Now in the second deployment, this is how I do the lookup in order to reach the first deployment:
SyncOperatorsBeanRemote SyncOperatorsBean = (SyncOperatorsBeanRemote) context
.lookup("ejb/SyncOperatorsBean#com.mirs.sbngenerate.beans.SyncOperatorsBeanRemote");
SyncOperatorsBean.executeSyncOperation();
That's the exception:
javax.naming.NameNotFoundException: While trying to lookup 'ejb.SyncOperatorsBean#com.mirs.sbngenerate.beans.SyncOperatorsBeanRemote' didn't find subcontext 'SyncOperatorsBean#com'. Resolved 'ejb'; remaining name 'SyncOperatorsBean#com/mirs/sbngenerate/beans/SyncOperatorsBeanRemote'
at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1139)
Now I can see the bean SyncOperatorsBean in the console's JNDI TREE. But still have the above exception.
I can't use Injection since the calling class is out of the container (inside quartz job).
Any idea?
Take a look at the JNDI tree for the managed server(s) where the EJB is deployed and see if you can find it. Also, are you using the URL of the Admin Server or the managed server where the EJB is deployed?
I have fixed the problem by taking off the #JNDI annotation.
and adjust the lookup command like that:
SyncOperatorsBeanRemote SyncOperatorsBean =
(SyncOperatorsBeanRemote) context
.lookup("ejb/SyncOperatorsBean#com.mirs.sbnsync.beans.SyncOperatorsBeanRemote");
SyncOperatorsBean.executeSyncOperation();
more over I had to add the target class jar to the server lib dir.(weird but thats what I had to do)
Related
I trying inject a EJB into my class using a InitialContext (JNDI). For this i use a Netbeans insert code mechanism:
after that Netbeans know witch injection have to use. #EJB annotation or JNDI Lookup. In my Example i have a simple, not managed class and what i want to do is inject a EJB Bean using JNDI. So Netbeans generate code for me as bellow:
problem is that. When Netbeans generate code for me. He change a web.xml file and add there ejb-local-ref node:
and when i trying a turn on my web application. I run glasfish and i always get following error:
Exception while deploying the app [mavenproject1-ear] : Error: Unresolved <ejb-link>: mavenproject1-ejb-1.0-SNAPSHOT#LanguagesFacade
i really dont know what to do. Can someone help with this issue. I will greatful for help.
Just remove the <ejb-local-ref> all together. It's defined for dependency injection and this is not your case here since you use JNDI to lookup the bean and set it in langaugeFacade variable. Just remove it and things will be fine.
I have problem in configuring JNDI lookup for ejb3.1 and weblogic 12c, jdk1.6
#Remote
public interface Bank{
public String accounts();
}
#Stateless(name="BankSession")
public class BankSessionBean implements Bank{
#Override
public String accounts() {
//////// }
ejb-jar.xml:
<enterprise-beans>
<session>
<display-name>BankSession</display-name>
<ejb-name>BankSession</ejb-name>
<business-remote>com.examples.Bank</business-remote>
<ejb-class>com.examples.BankSessionBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
</session>
<enterprise-beans>
weblogic-ejb-jar.xml:
<weblogic-enterprise-bean>
<ejb-name>BankSession</ejb-name>
<jndi-name>BankSession</jndi-name>
</weblogic-enterprise-bean>
client code:
When i start using Jndi Look up using this syntax
java:comp/env/ejb/BankSession
Its giving following error.
javax.naming.NameNotFoundException: While trying to lookup 'java:comp/env/ejb/BankSession' didn't find subcontext.
Here ejbbean and client code runs on different jvm's.
Which Jndi look up should i use ?
java:comp/env/ejb/BankSession'
java:global/applicationName/moduleName/BankSession
java:module/BankSession
java:app/moduleName/BankSession
java:comp/env/ejb/BankSession is working fine with ejb 3.0 and oc4j server.
When i migrate to ejb3.1 and weblogic 12c, its not working.
I even tried without using weblogic deployment xml files. Same issue encountered.
How should i configure my Jndi here ? Please help as i am facing this issue since long time.
For a lookup in the form of java:comp/env/... you need an EJB ref in the deployment descriptor of the component that does the lookup!
java:comp/env/... is always relative to the component that does the lookup.
A lookup name that is independent of the actual component that does the lookup and works from anywhere inside your application is 4.: java:app/moduleName/...
java:global/appName/... will fail if you decide to rename your ear file one day.
java:module/... only works inside a component that is part of the same module.
So 4. is IMO the best alternative.
I just want to call a Ruleset with Local EJB3 Session.
I get the exception javax.naming.NameNotFoundException: Name "ilog.rules.res.session.impl.ejb3.IlrStatelessSessionLocal" not found in context "ejblocal:" in websphere. What are the possibilities that this can happen?
source codes:
// get a rulesession --- 001
IlrEJB3SessionFactory sessionFactory = new IlrEJB3SessionFactory();
sessionFactory.setStatelessLocalJndiName("ejblocal:ilog.rules.res.session.impl.ejb3.IlrStatelessSessionLocal");
sessionFactory.setRemote(false);
Regards
It appears that there is no such EJB bound to that location. I believe the "ejblocal" namespace is specific to WebSphere Application Server, so you should be able to find the actual location of the EJBs by looking for CNTR0167I messages in the SystemOut.log. Alternatively, you might find that the application containing the relevant EJB did not start properly.
in the application xml, click on project tab then click on a downer label such as "jar utility management", then you must add, checking the box, the bean involved in the error.
I'm going through the EJB 3.1 spec and am trying to grasp the different possible ways a JNDI call can be made.
You can do it using a SessionContext and an InitialContext (or a self-created context based on the Initial- or SessionContext).
Based on which you use the syntax differs, but I can't seem to find the logic behind it.
So my question is: when can I use what syntax to use JNDI calls within an EJB container environment?
The rest of this question just serves as illustration of my point.
For example, I believe this is always possible for a correctly injected sessioncontext or created initialcontext:
ctx.lookup(java:global[/<app-name>]/<module-name>/<bean-name>[!<fully-qualified-interface-name>])
ctx.lookup(java:comp/env ...)
// special ones like these
ctx.lookup("java:comp/UserTransaction");
ctx.lookup("java:comp/ORB");
Sometimes (only for session context?) this shorter version is possible:
ctx.lookup(<bean-name>);
What about in an embedded environment, can only global references be used?
I usually inject EJBs inside EJB container with #EJB annotation. So the JDNI look ups are done by the server at deploy time.
For example JBOSS deployment:
INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-2) JNDI bindings for session bean named TestBean in deployment unit subdeployment "MyEJB.jar" of deployment "MyProject.ear" are as follows:
java:global/MyProject/MyEJB/TestBean!my.project.TestBean
java:app/MyEJB/TestEJB!my.project.TestBean
java:module/TestEJB!my.project.TestBean
java:global/MyProject/MyEJB/TestEJB
java:app/MyEJB/TestBean
java:module/TestBean
Some are per EJB specification some are application server dependent.
If you have to make look ups from context I think the best way is to use java:global.
You can also find some additional info at: http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html#POJOLocalEJB
jndi is a bit like a file system. You can refer to things using a relative path based on where you are in the tree (where you "cd"-ed to).
The injected session context is by default "positioned" on java:comp, so there you reference things that are available in java:comp, without the need to provide the "full path".
Note that java:comp itself is relative to a single EJB bean, or because of historical reasons to the entire Web module.
I'm not 100% sure what you mean with embedded environment, but if the code from which you are doing the JNDI lookup is not part of any of the predefined scopes (like java:module, java:app, etc) only java:global can be portably used.
I've got a session bean, defined in an ejb-jar.xml and jboss.xml. It's defined with an ejb-name, remote and home interface and an implementation.
When I fire up JBoss and view the JNDI tree the home interface seems to be there under the JNDI name of the ejb-name (I've tried defining jndi-name and local-jndi-name in the ejb-jar.xml with no apparent effect). But the remote interface does not appear in the JNDI listing.
If I try and access the ejb-name with a JNDI lookup from a JUnit TestCase things get messy, presumably because I'm accessing a home interface.
Any ideas what I'm likely to be missing? Thanks in advance.
package the home and remote interfaces into a client jar and put it on the client classpath
put the jboss-client.jar on the client classpath
put a jndi.properties file with the following content on the client classpath
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=jnp://localhost:1099
perform a lookup on the JNDI name of the remote interface (something like this by default with JBoss)
Context c = new InitialContext();
return (Echo) c.lookup("EchoBean/remote"); // use myEarName/HelloWorldBean/remote in an ear