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.
Related
I am migrating one application from weblogic to jboss7.1 and ejb2.0 to ejb3.X. The application is using jndi name for ejb lookup.
Could someone help me to find out how can i configure my custom jndi name with ejb3.0 and jboss 7.1.
I have read on internet that in Jboss 7.1 there is no concept of jndi-name. if it is true. could someone let me know how can i lookup this jndi name, getting registered by jboss for ejbs present in ejb-jar.xml
java:global/pirptfe/RRMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.RRMSessionFacadeHome
java:app/pirptfe/RRMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.RRMSessionFacadeHome
java:module/RRMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.RRMSessionFacadeHome
java:jboss/exported/pirptfe/RRMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.RRMSessionFacadeHome
java:global/pirptfe/RRMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.RRMSessionFacadeRemote
java:app/pirptfe/RRMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.RRMSessionFacadeRemote
java:module/RRMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.RRMSessionFacadeRemote
java:jboss/exported/pirptfe/RRMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.RRMSessionFacadeRemote
i got the answer of my question. in ejb3.X on jboss7.1 and above there is no concept of custom jndi. you have to call your ejb as below
ctx.lookup("java:global/pirptfe/RRMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.RRMSessionFacadeHome");
I would like to have optionally supplied information available to my webapp when deployed to Websphere (we are using 8.5) via the application's JNDI context.
I know that I can put a resource-ref or resource-env-ref in my web.xml but when I do that WAS will require me to supply a binding for it and deployment time.
My application will look in JNDI for certain values and adjust its behavior if found, but will function fine with default behaviour if it does not find values in JNDI. How, in WAS, do I supply a binding (just for a string or a URL) for my webapp without declaring a dependency on it in a resource-ref or resource-env-ref in my web.xml.
I know how to do this in Tomcat, I just put a Environment entry in the context.xml, like this:
<Environment
name="com.myorg.config"
value="http://localhost:8081/suff"
type="java.lang.String"/>
You can use an #Resource String lookupName; to accomplish the same in a portable manner. You will be prompted for a value at deployment time, but you can specify nothing, which will cause no value to be injected.
I have a java web application that is deployed in two EARs - one for the UI tier (contains a WAR module) and one for the business tier (contains an EJB module). Both tiers are deployed to WebSphere Application Server 7. The tiers are connected via EJB 3.0 stateless session beans. The beans are looked up via JNDI.
The two applications are currently on the same WAS server, but in the future will be deployed onto different servers. When I attempt to lookup an EJB, I get an error.
Attempting to debug the lookup error, I ran a JNDI namespace dump on the WAS server:
./dumpNameSpace.bat -host localhost -port 10031 > namespace.log
Each of my EJBs was listed with the following error:
(top)/nodes/U4752879Node01/servers/server1/ejb/au/gov/immi/emed/ejb/CrtEJB
au.gov.immi.emed.ejb.CrtEJB
ERROR: Received the following naming exception: com.ibm.ws.naming.util.InvalidObjectException: The IOR associated with the binding "CrtEJB" relative to the context "U4752879Node01Cell/nodes/U4752879Node01/servers/server1/ejb/au/gov/immi/emed/ejb" could not be resolved. If the binding is for an application object, make sure the application has started successfully. IOR: IOR:<removed>
Here is the EJB remote interface:
#Remote
public interface CrtEJB extends EMedEJB, EMedCrtService
{
}
And the bean implementation:
#Stateless(name = "CrtEJB")
#Remote(value = CrtEJB.class)
public class CrtEJBBean extends AbstractEMedEJBBean implements CrtEJB
{
...
}
And the ibm-ejb-jar-bnd.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar-bnd xmlns="http://websphere.ibm.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ejb-jar-bnd_1_0.xsd">
<session name="CrtEJB" simple-binding-name="ejb/au/gov/immi/emed/ejb/CrtEJB" />
...
</ejb-jar-bnd>
What is causing the error to occur? The error is the same without the ibm-ejb-jar-bnd.xml file, which I shound't need. Is this error what's causing the UI lookup to fail, or should that be working anyway? (in which case I'll post the UI error).
Since:
the #EJB doesn't work on desktop apps, because there's no container,
Weblogic doesn't expose through JNDI the names of the EJB's (3.0),
I didn't find anything about it in the official documentation for a few days now,
does anyone know how I could consume an EJB from a desktop app?
I got hints that i have to modify web.xml... but then what web.xml, there's more of them and at least some of them break my app.
Clarification:
I have a WebLogic server running, NOT exposing some EJB's inside an EAR hosted on that server. Specifically, the server is not exposing the names of EJB3.0 Session beans, while it DOES expose the names of some other EJB2.1 names.
How do i get a reference to the EJB3.0 objects, hosted on my server, from my desktop app?
FURTHER Clarification:
Weblogic Specifically does not expose the names of EJB3.0 within the JNDI, because the specifications of EJB3.0 don't require it.
To answer my own question (got it after some effort), to expose an EJB3.0 object through a remote interface, in the Weblogic 11g server, these steps must be taken:
This is what my ejb-jar.xml says about the bean RolyBean:
<enterprise-beans>
<session id="Session_Roly">
<display-name>Roly</display-name>
<ejb-name>Roly</ejb-name>
<remote>com.medicon.server.RolyRemote</remote>
<ejb-class>com.medicon.server.RolyBean</ejb-class>
<session-type>Stateless</session-type>
</session>
</enterprise-beans>
This is what the weblogic-ejb-jar.xml (in the same dir) says:
<wls:weblogic-enterprise-bean>
<wls:ejb-name>Roly</wls:ejb-name>
<wls:jndi-name>Roly</wls:jndi-name>
</wls:weblogic-enterprise-bean>
These 2 deployment descriptors seem to be the only 2 places where it's required to specify exposure of the EJB through JNDI.
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)