How do I lookup an EJB 3.0 Session bean from servlet or JSP?
Does anyone knows how can I invoke an EJB from a servlet or JSP ?
I deployed a simple EJB on a Oracle Application Server 10g release 10.1.3 and I'm working with JDeveloper 10.1.3. I deployed the files via JDeveloper, and I didn´t specify any orion-ejb-jar.xml or ejb-jar.xml file
After deployment, the orion-ejb-jar.xml look like this in the server:
<?xml version="1.0" encoding="utf-8"?>
<orion-ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://xmlns.oracle.com/oracleas/schema/orion-ejb-jar-10_0.xsd" deployment-version="10.1.3.0.0" deployment-time="10b49516c8f" schema-major-version="10" schema-minor-version="0" >
<enterprise-beans>
<session-deployment name="HolaMundoEJB" location="HolaMundoEJB" local-location="HolaMundoEJB_HolaMundoEJBLocal" local-wrapper-name="HolaMundoEJBLocal_StatelessSessionBeanWrapper6" remote-wrapper-name="HolaMundoEJB_StatelessSessionBeanWrapper7" persistence-filename="HolaMundoEJB.home_default_group_1">
</session-deployment>
</enterprise-beans>
<assembly-descriptor>
<default-method-access>
<security-role-mapping name="<default-ejb-caller-role>" impliesAll="true" />
</default-method-access>
</assembly-descriptor>
</orion-ejb-jar>
I'm trying to invoke the ejb in a servlet by doing the following:
public void doGet(HttpServletRequest request, ....
Context context = new InitialContext();
HolaMundoEJB helloWorld =
(HolaMundoEJB)context.lookup("java:com/env/ejb/HolaMundoEJB");
String respuesta = helloWorld.sayHello("David");
When i invoke the servlet I catch a NamingException whose message says something
like this ....java:com/env/ejb/HolaMundoEJB not found in webLlamaEJB
I tried different paths for the lookup but nothing....
Can anyone help me with this topic? Thank you.
Please try the following code:
HelloEJBBean.java:
@Stateless(name="Hello")
@Remote(value={Hello.class})
public class HelloEJBBean implements Hello { ... }
hello.jsp:
Context ctx = new InitialContext();
Hello h = (Hello)ctx.lookup("ejb/Hello");
web.xml:
<ejb-ref>
<ejb-ref-name>ejb/Hello</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<remote>fi.kronodoc.test.model.Hello</remote>
</ejb-ref>
i think you should also define jndi mappings for the references in orion-ejb-jar.xml and orion-web.xml but for some reason it seems to be working also without these.
Similar Messages
-
How to lookup a EJB 3.0 session bean which is deployed in WebLogic 10.3
Now Jdeveloper 11.1.1, is giving WebLogic server 10.3.
With internal WebLogic server, when I created a Sample client, it generated code as:
private static Context getInitialContext() throws NamingException {
Hashtable env = new Hashtable();
// WebLogic Server 10.x connection details
env.put( Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory" );
env.put(Context.PROVIDER_URL, "t3://127.0.0.1:7101");
return new InitialContext( env );
public static void main(String [] args) {
try {
final Context context = getInitialContext();
DefaultSession defaultSession = (DefaultSession)context.lookup("property-DefaultSession#com.vs.property.model.session.DefaultSession");
} catch (Exception ex) {
}How to update the above code to lookup the EJB 3.0 session beans with an external WebLogic server 10.3?
Is there any documentation available on how to install weblogic, troubleshoot, debug, WebLogic server 10.3?
regds
-rajuRaju,
Hi, to start, here is a tutorial on a quickstart web application using an EJB 3.0 stateless session bean that fronts a container managed EclipseLink JPA entity manager on WebLogic 10.3, you will find references there to other general WebLogic documentation.
[http://wiki.eclipse.org/EclipseLink/Examples/JPA/WebLogic_Web_Tutorial]
using @EJB injection on the client instead of a JNDI lookup as below
[http://edocs.bea.com/wls/docs103/ejb30/annotations.html#wp1417411]
1) in your second env.put I noticed that your t3 port is 7101, I usually use the default 7001 - but It looks like this port is valid for the JDeveloper embedded version of WebLogic server runs - just verify that it matches the port of your server.
2) your name#qualified-name lookup looks ok. Verify that the jndi-name element is set in your weblogic-ejb-jar.xml for non injection clients like the following
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>ApplicationService</ejb-name>
<jndi-name>ApplicationService</jndi-name>
3) as a test outside of your application - launch the WebLogic admin console and goto the testing tab of your bean in [Home > Summary of Deployments > "application" > "session bean name"
thank you
/michael : http://www.eclipselink.org -
How can I set the value to a session bean from backing bean
Hi Experts,
How can I set the value to a session bean from backing bean where I have created getter and setter
methods for that variable.
Basically I am using ADFUtils class where I am able to get the value from session bean
using following expression
String claimType =
(String)ADFUtil.invokeEL("#{ClaimValueObj.getClaimType}");
Thanks
GayazGayaz,
Wrong Post !!
Post in JDeveloper and ADF
Thanks
--Anil -
How can i design a EJB application using session Beans?
Hello,
I am designing a Find application using EJB. Here a user is prompted a search page, where he can enter the search criteria's. Then on click of submit, the query is formed at the server side depending on what criteria's were selected. Then a jdbc query is performed and the results are returned back to the user. Here no session is maintained for the users. Can anyone suggest me how to design this application using EJB. Should i use entity beans for this or session beans will suffice? Should the jdbc query be performed in the bean itself or should it be outside in a helper class? Please kindlu suggest me the design for this application...
Regards,
SubbuHi,
First of all, I'm unable to figure out why you need to use EJB for this scenario. You can write a helper class to frame and execute the query.
If you really want to use EJB, then I suggest you use a stateless Session Bean with transaction attribute as TX_NOT_SUPPORTED. From the session bean, you can call the helper class. But, by avoiding the session bean, you can eliminate remote calls, thus improving your performance. Also, check if the database & the db driver you are using supports sql caching.
Regards,
Raj. -
How to pass Bean from servlet to jsp
I had fetched record from my database to my servlet and passed it to bean.
how should i pass that bean to my jsp to display the record values in their corresponding textboxes??leozeo write: I had fetched record from my database to my servlet and passed it to bean.
how should i pass that bean to my jsp to display the record values in their corresponding textboxes?? Post the code -
How can i lookup a session bean from the client side
how can i lookup a session bean from the client side...........i am using sun appserver..............
this is my code.................[B]
private final static String JNDI_NAME="ejb/LmsBean";
private static String url="ldap://localhost:4848";
Hashtable h=new Hashtable();
h.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
h.put(Context.PROVIDER_URL,url);
System.out.println("Before Loading Context in Delegate");
Context ctx=new InitialContext(h);
System.out.println("Loaded Context in Delegate");
Object obj=ctx.lookup(JNDI_NAME);
System.out.println("Loaded Object in Delegate");
System.out.println("Before Loading Home in Delegate");
LmsHome home = (LmsHome )PortableRemoteObject.narrow(obj,com.parx.lms.controller.LmsHome.class);
System.out.println("Loaded Home in Delegate");
lms = home.create();
System.out.println("Loaded remote in Delegate");
[B]and i got the exception........
Inside Client before calling delegate
Before Loading Context in Delegate
javax.naming.CommunicationException: Request: 1 cancelled
javax.naming.CommunicationException: Request: 1 cancelled
at com.sun.jndi.ldap.LdapRequest.getReplyBer(LdapRequest.java:60)
at com.sun.jndi.ldap.Connection.readReply(Connection.java:405)
at com.sun.jndi.ldap.LdapClient.ldapBind(LdapClient.java:340)
at com.sun.jndi.ldap.LdapClient.authenticate(LdapClient.java:171)
at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2640)
at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:290)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:175)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:193
at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.ja
va:136)
at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.jav
a:66)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
62)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243
at javax.naming.InitialContext.init(InitialContext.java:219)
at javax.naming.InitialContext.<init>(InitialContext.java:195)
at com.parx.lms.lmsdelegate.LmsDelegate.getController(LmsDelegate.java:3
0)
at com.parx.lms.lmsdelegate.LmsDelegate.addUserDelegate(LmsDelegate.java
:50)
at com.parx.lms.client.consoleClient.Client.main(Unknown Source)
pls go tru the exception and pls help.........That url string should be having the server name or ip instead of localhost.
-
How create EJB 2.1 Stateful Session Bean in a EJB 3.0 Session Bean
Hi All,
We have been developing on EJB 2.1. We are now adding a module on EJB 3.0.
How can we "create" a stateful session bean with create method signature similar to create(String id)?
We have tried
// this is the remote interface
@EJB AddressBean abean;
But not working
Any help will be appreciated.There is no explicit create() call for EJB 3.0 session beans. It doesn't really matter though
since you can accomplish the same thing by defining your own business method to act
as an initializer for whatever state you'd like. E.g.
@Remote
public interface FooInterface {
public void initialize(String id);
// ... other business methods
@EJB FooInterface fooRef;
fooRef.initialize("foo");
--ken -
How to get the UserTransaction object in stateless session bean
Hi, I am using jboss server and jdk5 version and using EJB.
My Application flow :
JSP à Action(Struts) à Service Locator à Session bean à Entity Bean(cmp) à DB.
I tried to get the UserTransaction object in my Action. Its my code.
InitialContext ctx = new InitialContext();
UserTransaction uTrans = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
After used uTrans.begin(),uTrans.commit() and uTrans. rollback () also.
Its working fine .
But, I used the the same code inside in my session bean its not working.
Stateless Session Manager Bean code :
public class SampleManagerBean implements SessionBean {
public void ejbCreate() throws CreateException { }
public void ejbRemove() { }
public void ejbActivate() { }
public void ejbPassivate() { }
public void setSessionContext(SessionContext sessionContext) {
this.sessionContext = sessionContext;
public void createSample() throws EJBException
try{
InitialContext ctx = new InitialContext();
UserTransaction ut = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
}catch(Exception e) {
System.out.println( Exception === > +e)
Its throws the error ie: javax.naming.NameNotFoundException: UserTransaction not bound
How to get the UserTransaction object in my session bean. Kindly give solution the above errors.
- Thendralfirst of all, you could just use sessionContext.getUserTransaction(). however, that would only work if your bean is using bean-managed transactions. the default is container-managed transaction, in which case you cannot get a UserTransaction object. if you want to manage transactions, you need to add the TransactionManagementType.BEAN annotation to your ejb.
-
EJB 3.0 Session Bean question
Hi there,
How'd I expose a method of Stateless Session Bean in EJB 3.0? I don't seem to find any annotation for that.
Thanks in advance.
SaeedIf you need to expose method implemented in Session bean, you can invoke the method call from within another method called in Client.
This method has to be defined in the remote interface . The method you are trying to invoke can be defined somewhere else but called in your bean class from within the method definedin the remote interface. -
How to cast back and use a retrieved Session Bean reference in a servlet?
Please help!
1. I invoke a Session Bean from a servlet :
travelagent = home.create();
2. I store the travelagent reference in the HTTP Session :
session.setAttribute( "travelagent" , travelagent );------------------------------------------------------------------------------------------------------------------
Now, in another servlet, I have to retrieve the reference to the EJB from the HTTPSession.
I then have to use this reference to call a business method in the EJB Session Bean.
I have tried two ways to retrieve the reference and cast it before calling the business method. I get errors in both forms of casting.
The Values you will see below in the code:
EJB Remote Interface : TravelAgent (TravelAgent.java)
Business Method : listItineraries( )
Servlet which calls the above method : ListItinerary.java
Line 46 of ListItinerary.java : ArrayList itineraries = traveler.listItineraries();------------------------------------------------------------------------------------------------------------------
The two ways along with the error I get on the servlet page in the browser are :
(A)
TravelAgent traveler = (TravelAgent)session.getAttribute("travelagent");The error I get is :
java.rmi.NoSuchObjectException: CORBA OBJECT_NOT_EXIST 9998 Maybe; nested exception is:
org.omg.CORBA.OBJECT_NOT_EXIST: vmcid: 0x2000 minor code: 1806 completed: Maybe
com.sun.corba.ee.impl.javax.rmi.CORBA.Util.mapSystemException(Util.java:208)
com.sun.corba.ee.impl.javax.rmi.CORBA.Util.wrapException(Util.java:591)
javax.rmi.CORBA.Util.wrapException(Util.java:277)
source.traveler.ejb._TravelAgent_Stub.listItineraries(Unknown Source)
source.traveler.servlet.ListItinerary.processRequest(ListItinerary.java:46)
(B)
TravelAgent traveler =
(TravelAgent)PortableRemoteObject.narrow(session.getAttribute("travelagent"), TravelAgent.class);The error I get is :
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.RemoteException
com.sun.corba.ee.impl.javax.rmi.CORBA.Util.wrapException(Util.java:597)
javax.rmi.CORBA.Util.wrapException(Util.java:277)
source.traveler.ejb._TravelAgent_Stub.listItineraries(Unknown Source)
source.traveler.servlet.ListItinerary.processRequest(ListItinerary.java:46)
Could someone advice on how to retrieve and cast the EJBObject's reference from the servlet so that I may use it to call the business method?
Thanks!Thanks guys! It worked.
1.. I should have used the handle. Got to coding without going deep in the concepts.
2.. I dont know if I could have used the EJB Reference directly (instead of the handle).
3.. The error was due to me not mapping the servlets with the EJBs that they could use. I continued to get the same error even after using the handle. Once I put the mapping to the EJBs correctly, everything fell in place.
Thanks a lot!
Henry -
How does session bean contain in the JSP page
May i know how session bean contains in the JSP page
If the situation is like the following ...
if i dont want to put the session bean in the session
like this :
session.setAttribute("UserBean",userBean);
the way i get the session bean is only
session.getAttribute("UserBean");
Does have the other way to get the Session bean during the JSP
if i dont want to use this kind of way,
what else i can do for?
may i know the solution with detailed
and please attach the solution of code to me if you know...
thanks...Hi,
I am not clear with ur query..
What I understood from ur query is that, u are trying to put the session ejb in the HttpSession Object for some use ahead in future?
If this is the case, then I think are approach is not correct.
StatefulSession beans are meant for this purpose, i.e they will be maintaining the client session. So use the same using the JndiLookup of the HomeInterface and the getting the Home reference and calling the businessmethods
sameer -
How call session bean from Client side
Hi
calling session bean from client side it gives Lookup erroe, it gives JNDI error
how we know session bean is working. in Admin tree bean statis is reb Flaf, and ID is "Down" how we activate it..
nullIf you can make a connection using sess_sh, then you know that you have configured your database and listener properly. If it is not working, read the manuals that you can download from technet. They are pretty good, and if you follow the directions, you should see success.
Good Luck!
Brad -
Cannot deploy a EJB 3.0 Session bean to the OAS 10.1.3.4
Hi All,
I am unable to deploy a EJB 3.0 Session bean with no deployment descriptors to OAS 10.1.3.4 App server.This Session bean is also exposed as a web service using annotations. I am able to deploy this bean to a standalone oc4j 10.1.3.x containers and test it successfully.
i have written a simple stateless session bean ( exposed as webservice) and every bean is having issues with deployment having the same exception stated below
Can some one please help as i need to deploy this urgently.
below is the session bean code:
import javax.ejb.Stateless;
@Stateless(name="SiebelQuoteEJB")
public class SiebelQuoteEJBBean implements SiebelQuoteEJBLocal,
SiebelQuoteEJBWebService {
public SiebelQuoteEJBBean() {
public String publishMessage(String message,String type) throws java.rmi.RemoteException {
client.publishMessage(message,type);
return "SUCCESS";
Below is the error while deploying:
11/01/06 15:03:49 WARNING: Application.setConfig Application: javasso is in failed state as initialization failed.
java.lang.NullPointerException
11/01/06 15:03:50 WARNING: Application.setConfig Application: SiebelQuoteEJB is in failed state as initialization failed.
java.lang.InstantiationException: Error initializing ejb-modules: null Error parsing application-server config file: null
11/01/06 15:03:50 java.lang.NullPointerException
at com.evermind.server.ObjectReferenceCleaner.cleanupApplicationLogLevels(ObjectReferenceCleaner.java:166)
at com.evermind.server.ObjectReferenceCleaner.loaderDestroyed(ObjectReferenceCleaner.java:88)
at oracle.classloader.EventDispatcher.loaderDestroyed(EventDispatcher.java:248)
at oracle.classloader.PolicyClassLoader.close(PolicyClassLoader.java:1113)
at oracle.classloader.PolicyClassLoader.close(PolicyClassLoader.java:1041)
at com.evermind.server.ApplicationStateRunning.destroyClassLoaders(ApplicationStateRunning.java:1171)
at com.evermind.server.Application.stateCleanUp(Application.java:3635)
at com.evermind.server.Application.setConfig(Application.java:506)
at com.evermind.server.Application.setConfig(Application.java:355)
at com.evermind.server.ApplicationServer.addApplication(ApplicationServer.java:1895)
at com.evermind.server.ApplicationServer.initializeDeployedApplications(ApplicationServer.java:1651)
at com.evermind.server.ApplicationServer.setConfig(ApplicationServer.java:1034)
at com.evermind.server.ApplicationServerLauncher.run(ApplicationServerLauncher.java:131)
at java.lang.Thread.run(Thread.java:736)which jdk version? Had this with 1.6 and had to install an up-to-date jdbc.
-
EJB 2.1 session bean calling EJB 3 session bean?
I have a WL 10 (JDK 1.5/EE 5) server that has several EJB 3 stateless session beans deployed and working well. But now I need to allow a JBoss 3.2.3 (JDK 1.4) EJB 2.1 session bean make remote calls into these EJB 3 EJBs. Can this even work?
It seems to me that EJB 3 calling EJB 2 would be fine, but not in the reverse?I have a WL 10 (JDK 1.5/EE 5) server that has several EJB 3 stateless session beans deployed and working well. But now I need to allow a JBoss 3.2.3 (JDK 1.4) EJB 2.1 session bean make remote calls into these EJB 3 EJBs. Can this even work?
It seems to me that EJB 3 calling EJB 2 would be fine, but not in the reverse? -
How to instantiate a database control in a session bean (Weblogic 8.1)
Is it possible to instantiate a database control in a session bean?
in a jsp i invoke "WlwProxy.create" method with an HttpServletRequest Object,
ther's another "WlwProxy.create" which take an URL object instead of an HttpServletRequest one, i've tried to use it with the URL of my database Control class,
I've tried two ways :
1- URL url = new URL(C:\bea\user_projects\.....\MydatabaseControlclass")
2- URL url = new URL("http","localhost",7001,"nameOfPackege/MydatabaseControlclass");
But it failed
Does anybody here know how to use "WlwProxy.create" with an URL object ?
Thanks.
Edited by concerto at 04/19/2007 6:29 AM
Edited by concerto at 04/19/2007 6:36 AM
Edited by concerto at 04/19/2007 6:43 AMHi Gautam
I don't think Database control has any attribute on Role.
The database control takes the connection from the datasource that is specified in the jcx. I am not sure if there is any attribute at the connection pool level that will allow you to set a role.
Or you can call a method in the dbcontrol that executes a set role.. statement and then run other methods.
Thanks
Vimala
Maybe you are looking for
-
Installing Windows 7 - New Mac Mini no Optical Drive
Hello, I would like to install a Windows 7 on a new 2011 no optical disk mini. I am aware of how to do that, and what do I need to prepare, becouse there is not a optical disk in a mini. Any ideas on if I can buy (download) a Windows 7 from www.micro
-
My Norton tool bar No longer is visable and does not work, how can I fix this
My Norton 360 that saves all my passwords for me does not work on fire fox 4.0. How can I go back to the previous version? I was not given a warning that Norton 360 wouldn't work until after I had already down loaded 4.0, or I would not have download
-
How can I copy or print the contents of a folder I created in the the folder section of the inbox
Selecting the contents of the folder and hitting Ctrl C doesn't do it
-
How do I get delete button back on inbox, it disapeared.
My delete button has disappeared from my inbox. I have to open email to delete it now. How do I get it back?
-
Iphoto slideshow exported for iweb viewed by windows
I have been trying to publish an iphoto slideshow that I had exported as a movie for weeks. My mac people can see it, my PC family members cannot! I tried to make it small for the web, changed the filename to mp4 from mpv4, but PC people still could