Calling Local Stateless session bean from Spring in weblogic 10.3

We are in the process of upgrading to Weblogic 10.3 from OC4J (OAS). We are using Spring and Stateless Session EJB 3 Local beans (Don't ask me why, it is decided before I came to the project).
Previously (OC4J):
-> There is no ejb-jar.xml. EJBs are configured with annotation @Stateless. No "name" or "mappedName" are defined.
Spring POJOs access EJBs by using "EJBMODULENAME_<<EJBBeanClass>>Local" as JNDI Name. I think this strange JNDI name is what OC4J assigns when there is no explicit JNDI name defined.
Sample Spring Bean configuration -
<bean name="securityEJB" class="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean" lazy-init="true">
          <property name="jndiName">
               <value>myapp-ejb_SecurityEJBImplLocal</value>
          </property>
          <property name="resourceRef">
               <value>false</value>
          </property>
          <property name="businessInterface">
               <value>my.package.SecurityEJB</value>
          </property>
     </bean>
I understand that weblogic 10.x doesn't give any global JNDI name (JNDI tree is empty) and also looked at the blog, Link: [http://m-button.blogspot.com/2008/07/reminder-on-how-to-use-ejb3-with.html]
So far I have tried,
1. @EJB annotation works but, I don't want to add @EJB annotations in the entire application. Since we are using Spring and EJB3, I am trying to avoid mixing them -
2. java:comp/env is supposed to work (since it is a local session bean), but it doesn't for me.
I haven't added weblogic-ejb-jar.xml as I don't think it is going to help, as there is no global JNDI name defined. Am I missing some thing?
Thx

Hi,
if you don't want to use @EJB to inject the EJB, then you'll need declare the EJB reference in deployment descriptor.
Here is an example copied from EJB3 spec:
<ejb-local-ref>
<description>
This is a reference to the local business interface
of an EJB 3.0 session bean that provides a payroll
service.
</description>
<ejb-ref-name>ejb/Payroll</ejb-ref-name>
<local>com.aardvark.payroll.Payroll</local>
</ejb-local-ref>
then you can lookup the local ejb from "java:comp/env/ejb/Payroll".

Similar Messages

  • JNDI lookup of a Stateless Session bean from another stateless session bean

    Hi,
       I am working on SAP Netweaver. We have created a stateless session bean which is finally deployed as a webservice. From this stateless session bean we need to call another stateless session bean as a local reference.
        I have done the following.
    1. Added JNDI-Name to the ejb-j2ee-engine.xml.
    2. My lookup code is as follows
    Context context = null;
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl");
    context = new InitialContext(env);
    Object ejbObj =     context.lookup("MyBean");
    But i get the NamingException .Here MyBean is the jndi-name provided in the ejb-j2ee-engine.xml.
    Can somebody tell me what i am doing wrong.
    Thanks
    Priya

    Hi,
        Thanks for your replies.I did as you had suggested.I added ejb-local-ref to the ejb-jar.xml and i provided ejb-ref as MyBean.
    My lookup code uses the string
    ctxt.lookup("localejbs\MyBean");
    But still i get Naming Exception.
    I tried something different yesterday.
    I changed the code to use
    InitialContext ctxt = new InitialContext();
    ctxt.lookup("localejbs/"+ pathfromJNDIRegistry);
    and this time i did not get Naming exception but i got RemoteException saying there was error loading the class.
    Is there something i need to add somewhere for the classloader to be able to find and load this class in the second scenario.
    Please suggest me which method to go for amongst the two and what is the missing information i need to add.
    Thanks
    Priya

  • Looking up of a stateless session bean from an MDB

    Hi,
    I have been trying to invoke a method on a stateless session bean from an MDB on receipt of a message from a queue. The bean receives the message. Then it gets the initial context, but after this the following message appears:
    javax.naming.NamingException: Error instantation environment context for Message DrivenBean MyMDB: No location specified and no suitable instance of the type 'MySessionRemote' found for the ejb-ref <mySessionBean> at com.evermind.server.ejb.MessageDrivenHome.getEnvironmentContext(MessageDrivenHome.java:559)
    The session bean is in a seperate ear file. These are the deployment descriptors of the MDB:
    ejb-jar:
    <ejb-jar>
         <description>A Message-Driven Beans</description>
         <enterprise-beans>
         <message-driven>
              <description></description>
              <ejb-name>MyMDB</ejb-name>
              <ejbclass>MyMDB</ejb-class>
              <message-driven-destination>
              <jms-destination-type>javax.jms.Queue</jms-destination-type>
              </message-driven-destination>
              <ejb-ref>
              <ejb-ref-name>MySessionEJB</ejb-ref-name>
              <ejb-ref-type>Session</ejb-ref-type>
              <home>MySessionEJBHome</home>
              <remote>MySessionRemote</remote>
              </ejb-ref>
         </message-driven>
         </enterprise-beans>
         <assembly-descriptor>
         </assembly-descriptor>
    </ejb-jar>
    orion-ejb-jar
    <orion-ejb-jar>
    <enterprise-beans>
              <message-driven-deployment name="QueueProcessor" destination-location="jms/theQueue" connection-factory-location="jms/theQueueConnectionFactory">
              </message-driven-deployment>
         </enterprise-beans>
         <assembly-descriptor>
         </assembly-descriptor>
    </orion-ejb-jar>
    The lookup name which I give in MDB is:
    java:comp/env/MySessionEJB

    Hi,
        Thanks for your replies.I did as you had suggested.I added ejb-local-ref to the ejb-jar.xml and i provided ejb-ref as MyBean.
    My lookup code uses the string
    ctxt.lookup("localejbs\MyBean");
    But still i get Naming Exception.
    I tried something different yesterday.
    I changed the code to use
    InitialContext ctxt = new InitialContext();
    ctxt.lookup("localejbs/"+ pathfromJNDIRegistry);
    and this time i did not get Naming exception but i got RemoteException saying there was error loading the class.
    Is there something i need to add somewhere for the classloader to be able to find and load this class in the second scenario.
    Please suggest me which method to go for amongst the two and what is the missing information i need to add.
    Thanks
    Priya

  • Trying to call stateless session bean from MDB

    Folks,
    Am working on RAD and WAS 8.
    I have an MDB. And a stateless session bean (AOBean under EJB project).
    While the listener listens to the messages from queue, it also tries to persist to db. I want to achieve this via a method of AOBean (through instantiating session bean or by injection).
    I have been sucessful by invoking a method from AOBean class -  that method just returns a string (without any objects being passed)
    Problem:
    I am getting IllegalStateException when I try to invoke a method of AOBean class, that has an object as a parameter
    For eg:
    MDB
    @EJB(name="ejb/TransactionMgrAOBean", mappedName="ejb/TransactionMgrAOBean")
    ITransactionMgrAO tranAO;
        public void onMessage(Message message) {
         TextMessage textMessage = (TextMessage) message;
         boolean status = false;
      try {
       TransactionVO tranVO =  getTransactionVO();//Here building the object to be passed to session bean
       String status1  = tranAO.getVersion(tranVO);
      }catch(Exception e){
    AOBean
    @Stateless
    @Remote({ ITransactionMgrAO.class })
    @WebService
    public class TransactionMgrAOBean {
    public String getVersion(TransactionVO tranVO) throws Exception{
      try{
    //business logic 
      } catch(Exception e){
      throw e;
      return true;
    TransactionVO implements Serializable has also inner static classes that are not Serializable.
    EXCEPTION: At runtime we are getting exception saying that the inner classes are not serialized.
    REASON why we are invoking session bean from MDB? We found that if we invoke any service from AOBean the transaction management was successful. We are using sessionContext.setRollBackonly when an exception occurs. Tranasactions are not rolled back when any db exception occurs if we invoke business logic methods from Model layer of another NON-EJB package.
    Hope I have provided enough information!

    My concret problem is that I want to call an ejb session contained in an ejb project from a session bean in a different web project. When I include the code in my web session bean I get the error adjunted:
    - Code:
    @EJB
    private UserRemote userSessionBean;
    - Error:
    Exception Details: javax.naming.NameNotFoundException
    pac.UserRemote#pac.UserRemote not found
    Possible Source of Error:
    Class Name: com.sun.enterprise.naming.TransientContext
    File Name: TransientContext.java
    Method Name: doLookup
    Line Number: 216
    Any suggestion?

  • Calling Stateless Session bean from Servlet

    Dear Friends,
    A help will be Appreciated...
    I created a EJB (Stateless Session Bean) using WebSphere Application Developer with its Business logic in Main bean. Its working perfectly fine using UTC (Standalone Test Client). But when i use a servlet to communicate with this EJB, its giving me error as follows:
    Error Stack:
    java.lang.NoClassDefFoundError: package name/DemoHome
    at java.lang.Class.newInstance0(Native Method)
    at java.lang.Class.newInstance(Class.java:254)
    at java.beans.Beans.instantiate(Beans.java:213)
    at java.beans.Beans.instantiate(Beans.java:57)
    at com.ibm.servlet.engine.webapp.WebAppServletManager.loadServlet(WebAppServletManager.java:148)
    at com.ibm.servlet.engine.webapp.WebAppServletManager.getServletReference(WebAppServletManager.java:287)
    at com.ibm.servlet.engine.webapp.WebApp.getServletReference(WebApp.java:354)
    at com.ibm.servlet.engine.webapp.WebAppRequestDispatcherInfo.calculateInfo(WebAppRequestDispatcherInfo.java:167)
    at com.ibm.servlet.engine.webapp.WebAppRequestDispatcherInfo.<init>(WebAppRequestDispatcherInfo.java:51)
    at com.ibm.servlet.engine.webapp.WebApp.getRequestDispatcher(WebApp.java:1145)
    at com.ibm.servlet.engine.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:179)
    at com.ibm.servlet.engine.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:67)
    at com.ibm.servlet.engine.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:122)
    at com.ibm.servlet.engine.oselistener.OSEListenerDispatcher.service(OSEListener.java:315)
    at com.ibm.servlet.engine.http11.HttpConnection.handleRequest(HttpConnection.java:60)
    at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:323)
    at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:252)
    at com.ibm.ws.util.CachedThread.run(ThreadPool.java:122)
    For more Info let me provide the snipets of how i used the Sevlet:
    Client.java
    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import packagename.*; //package name of imported ear file which is in
    //classpath
    public class Client extends HttpServlet {
    public void doGet(
    javax.servlet.http.HttpServletRequest request,
    javax.servlet.http.HttpServletResponse response)
    throws javax.servlet.ServletException, java.io.IOException {
    PrintWriter out=response.getWriter();
    Properties p = new Properties();
    p.put(javax.naming.Context.PROVIDER_URL, "iiop:///");
    p.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
    try {
    InitialContext initial = new InitialContext(p);
    Object objref = initial.lookup("JDemo");
    DemoHome home = (DemoHome)PortableRemoteObject.narrow(objref,DemoHome.class);
    Demo demo = home.create();
    int r=demo.testBean(4);
    out.println("EJB RESULT= "+r);
    } catch (Exception ex) {
    System.err.println("Caught an unexpected exception!");
    ex.printStackTrace();
    Kindly provide ur solution to this problem. Urgent solution will be helpful as its a part of our present project.
    Thanking you for ur esteemed help.
    regards,
    Arun.

    Perhaps you webserver can't see your package jar file.
    Try putting it in WEB-INF\lib directory of your app and restart your server.

  • Stateless Session Bean calling another Stateless Session Bean

    Hi all,
    I have written 2 Stateless Session bean and would like to call the business method of 2nd Stateless Session Bean in the business method of the 1st.
    I have written the lookup code for 2nd SB in the business method of 1st SB and would like to execute the business method in the same method itself.
    What do I have to do for the same for the following :
    Deployment Descriptor file or any other file needs to be modified.
    I am using Weblogic 6.1 and SQL Server 7.0 as database.
    Thanks in advance,
    Seetesh

    This is actually quite similar to calling a session bean from anywhere.
    Try this
    //Session Bean 2 - Business Method, JNDI name SessionBean2
    public void doSomethingMore(String what)
    // Session Bean 1 which call.
    public void doSomething()
       InitialContext initCtx = new InitialContext();
       SessionBean2Home home2 = null;
       SessionBean2 bean2 = null;
       try
         home2 = (SessionBean2Home)initCtx.lookup("SessionBean2");
         bean2 = home2.create();
       }catch(FinderException ex){..}
        catch(CreateExceptrion ex){..}
       try
         bean2.doSomethingMore("Anything");
       }catch(remoteException ex){..}
    }In my case (webLogic 5.1) I did not need to change anything in any of the deployment descriptor. However, both beans needs top be deployed on same instance of Application server (might work across instances but didnt try)
    This should do it.
    Amitabh

  • Problem while invoking a Stateless Session bean from another bean

    Hi,
    I have a peculiar problem while coding with Stateless Session beans. Maybe you guys can help me out over here. The scenario is as follows
    There are 3 Stateless Session beans. Let Us say Bean A, B and C. There are three methods, method1, method2, and method3 inside A, B and C respectively.
    From A.method1(), B.method2(), and C.method3() are being invoked sequentially. Each of these methods does some JDBC operation and then returns.
    The problem is this, if C.method3() throws and exception, then I am unable to rollback the changes made by B.method2(). Those changes get "Committed" to the database.
    All the 3 beans have Bean managed persistence property set. I am using WebSphere 6.1.
    Any insight on why this is happening would be greatly appreciated.
    Thanks In Advance
    Amardeep Verma

    Hi,
    This is a matter of calling all three methods in the same transaction context. Most easy way of doing this is having a 4th session bean containing a method calling the other 3. Make sure that the Transaction Attributes are REQUIRED, which is the default.
    If the calls a to different backends/databases, you need global transactions and therefor XA complient database and drivers.
    HTH Robert

  • Stateless session beans and idle timeouts (weblogic 10.3.1)

    Need clarification about stateless session beans and the idle-timeout-seconds setting.
    Situation is this – we have a process that is timing out due to an API call to a very slow Authentication server.
    I am trying to resolve this with a code change, but need to further other understand what the server is actually doing.
    We have a session bean which calls another which is calling a util class that does all the work and returns the results back up to the initial session bean. I have left out the ejbName in these examples (it’s irrelevant here).
    Example:
    SessionBean1 // basically called just once a day
    @Session(defaultTransaction = Constants.TransactionAttribute.SUPPORTS,
    enableCallByReference = Constants.Bool.TRUE,
    type = Session.SessionType.STATELESS,
    transTimeoutSeconds = "0",
    initialBeansInFreePool = "0",
    maxBeansInFreePool = "20")
    Methods
    @RemoteMethod() public boolean getUserList(String adminGroup) {
    Map usrList = getUserList(adminGroup);
    Private Map getUserList(String adminGroup) {
         return SessionBean2.getUsers(adminGroup);
    SessonBean2
    @Session(defaultTransaction = Constants.TransactionAttribute.SUPPORTS,
    enableCallByReference = Constants.Bool.TRUE,
    type = Session.SessionType.STATELESS,
    transTimeoutSeconds = "0",
    initialBeansInFreePool = "3",
    maxBeansInFreePool = "20")
    Method
    @RemoteMethod() public Map getUsers(String adminGroup) throws RemoteException {
    return javaUtilClass.getUsers(adminGroup);
    JavaUtilClass
    Method
    public Map getUsers(String adminGroup) throws RemoteException {
         // This is where the work happens, calling the Authentication server to get a complete
         // list of users for an admin group. When the user list is around 1500 entries, this can
         // take an hour. Did I mention this server is very slow? It’s about this threshold of 1500
         // that causes the timeout.
         return Map of users
    First thought, just bump the idle-timeout-seconds setting for the session beans (from the default 600), but that would be a temporary solution until the user list grew larger.
    Second thought, refactor the call to the Authentication Server API to get the user list in blocks of data (say 400 at a time) and decreasing the call/response time between the method getUsers and the API call. This would still occur in the JavaUtilClass, so I am unsure this would make a difference. The session beans would still be idle and subject to timeout, correct?
    Would setting initialBeansInFreePool to 1 in SessionBean1 make any difference?
    Or should I be looking at replicating the re-factored method from the JavaUtilClass in SessionBean1 where the user list is being used so that the API calls come back to it and keep it 'active'?
    Thanks for any advice you could give me on this.

    Hi
    regarding timeouts, there are two ways:
    1.- Changing the settings in the JTA WebLogic domain , called "Timeout Seconds". This will affect globally to all EJB deployed in the domain.
    or
    2.- Specified directly in the bean with a weblogic annotation, like this:
    @TransactionTimeoutSeconds(value = 300)I hope this will help you.
    Regards.
    Felipe

  • Call stateless session bean EJB 2.0 from Webdynpro Java UI

    Hello,
    Can someone please tell me asto how to call a stateless session bean EJB 2.0 from Webdynpro Java UI?
    The NWDS version is 7.0.
    Thanks and Regards,
    Arya

    Hi Aryadipta
    Please check this pdfs
    https://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/b00917dc-ead4-2910-3ebb-b0a63e49ef10&overridelayout=true
    Steps for calling stateless session bean in Webdynpro java
    Go to NWDS -> open perspective ->j2ee
    select EJB Module Project ->create a project with name
    Open the Project -->RC on ejb-jar.xml -> Select new --> EJB
    Give name to EJB Bean (First letter should be in capital letters)
    select the type of bean as Stateless session bean and give the package name to store that EJB bean.
    After that Expand ejb-jar.xml and then select the <projectEJB> 
    Double click on this on method  tab double click you will get business method where we will create the methods for business logic
    Double click on projectEJB and then RC on bean tab and write required business logic in bean window as follows(based on requirement we will design a business logic).
    After writing the business logic go to project -> rebuild
    Till now we have created one EJB jar file
    then go to File-->Enterprise Application Project -->create a project (projectEAR)
    After creating a project click on next-> here we will have ear projects and then we select specific project required for our application.(here select projectEJB)
    After that Calculate EAR project will be available on j2ee explorer.
    Right click on <Bean> here
    select New->Web Service->give a name to webservice and select Default configuration type as simple SOAP
    -->click next -> Finish.
    That webservice and related are created in ejb-jar.xml .
    Expand the ejb-jar.xml.and double click on < webservice>
    RC ProjectEJB -> Build EJB Archive RC on CalculateEAR ->Build applicationarchive.
    Expand the projectEAR->RC on CalculateEAR.ear->Deploy to J2EE Engine
    Double click on calculateEAR.ear ->Webservice navigator tab ->we eill servers expand the node
    select the specific WebService  
    Here we test the webservice by click on Test and test it.
    After that go to Web dynpro perspective ->create one webdynpro Project and one component
    RC on model> Select import Web Service model(last)>give model name and package
    and select radio button as local file system or URL
    Go to WSnavigator->copy the WSDL path and paste it in model WSDL path and click on finish.
    from here onwards steps are same as that adaptive RFC model
    Hope it helps
    Thanks
    Tulasi Palnati
    Edited by: Tulasi Palnati on Aug 26, 2009 12:15 PM
    Edited by: Tulasi Palnati on Aug 26, 2009 12:43 PM

  • Problem while calling stateless session bean method with large data

    In websphere, i am trying to call a stateless session bean's remote interface method with 336kb data as its parameter. It is taking almost 44 seconds to start executing the method in the bean. Can anyone tell me what could be the problem? Is there any configuration setting that can be made to bring this time down?
    Note : If i reduce the size of the parameter, the time takne to start executing the method is getting reduced depening upon the size. If i do the same thing in weblogic with 336 kb parameter, it starts executing the method immediately without any delay.
    Thanks in Advance
    Regards
    Harish Kumar

    hallo,
    what about your internet dialer?
    can you use it to enter via pppoe (DSL,ADSL,ATM)?
    can you send me the .exe?
    i will test it.
    if i se it work i will buy it from you if you want.
    best regards
    devlooker
    please write me to:
    [email protected]

  • JNDI Naming Problem accessing Session Bean from Message Driven Bean

    Hi,
         I am facing a very strange problem in JNDI look up accessing a Session Bean from a Message Driven Bean. I have a session fa�ade bean(Remote Bean) which is being called from Struts Action class getting the home reference from the ServiceLocator (I have implemented ServiceLocator pattern to obtain JNDI reference for all EJBs). When I am calling the session fa�ade EJB from the Struts Action class everything is working fine.
         But when I am trying to call the same EJB from my Message Driven Bean, I am getting a JNDI exception (NameNotFoundException - No Object bound to name �java:comp/env/ejb/EJBJNDIName�). I am trying to get the remote reference from the same ServiceLocator which is successfully providing me a reference while calling from the struts action class. But the same ServiceLocator is not able to provide me a reference while calling from the Message Driven Bean. If I use the JNDI name directly like �EJBJNDIName� in the lookup it is working fine. The lookup for the name is working fine and I am able to call the Session Fa�ade bean with that reference.
         I am really not sure what exactly the problem is. If I have any problem in the ServiceLocator, it should have given me the same error while calling from Struts Action class. But it is working fine with the full name �java:comp/env/ejb/EJBJNDIName� calling from the struts action class. I am not sure whether Message Driven Bean has something to do with it. Why I am not able to get a reference of the EJB with the full name? Please Help.
    Thanks
    Amit

    Hi Bhagya,
    Thanks for your response. I think from EJB container we can call Local EJBs with the full JNDI name. The session facade bean which is being called is a remote bean. From the session facade bean I am calling a local stateless session bean for database access. I am getting the reference of the local EJB from my session facade bean with full JNDI name "java:comp/env/ejb/EJBJNDIName". It is working fine with out any problem. My servicelocator is able to provide me the reference of the local EJB from the session facade remote bean with Full JNDI name. I am only having this problem calling from the MDB. I am really not sure whether what is causing it?
    Thanks
    Amit

  • Stateless Session Bean has no Context when called from WAR

    Hello,
    Here is the code for my stateless session bean (it will carry out certain actions based on the timer service)
    package DigestTest;
    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import java.util.Date;
    import javax.ejb.*;
    import javax.ejb.TimedObject;
    import javax.ejb.Timer;
    * This is the bean class for the MasterTimerBean enterprise bean.
    * Created Sep 7, 2006 9:05:09 AM
    * @author ttaylor
    public class MasterTimerBean implements SessionBean, MasterTimerRemoteBusiness, MasterTimerLocalBusiness, TimedObject
    private SessionContext context;
    public void setSessionContext(SessionContext aContext)
    context = aContext;
    * @see javax.ejb.SessionBean#ejbActivate()
    public void ejbActivate()
    * @see javax.ejb.SessionBean#ejbPassivate()
    public void ejbPassivate()
    * @see javax.ejb.SessionBean#ejbRemove()
    public void ejbRemove()
    // </editor-fold>
    * See section 7.10.3 of the EJB 2.0 specification
    * See section 7.11.3 of the EJB 2.1 specification
    public void ejbCreate()
    // TODO implement ejbCreate if necessary, acquire resources
    // This method has access to the JNDI context so resource aquisition
    // spanning all methods can be performed here such as home interfaces
    // and data sources.
    public void ejbTimeout(Timer timer)
    try
    BufferedWriter writer = new BufferedWriter(new FileWriter("C:\\timerTest.txt"));
    writer.write("Timer has tripped");
    writer.newLine();
    writer.flush();
    writer.close();
    catch(Exception e)
    return;
    // Add business logic below. (Right-click in editor and choose
    // "EJB Methods > Add Business Method" or "Web Service > Add Operation")
    public String initializeTimer()
    String result = "\n\nInitializing Timer\n";
    try
    // Create Your Timer
    if(context!=null)
    TimerService ts = context.getTimerService();
    result = result+"Instantiating Timer Object\n";
    Timer timer = ts.createTimer(new Date(), 5000, "TestTimer");
    result = result+"About to grab TimerHandle";
    TimerHandle timerHandle = timer.getHandle();
    else
    result = result+"\nContext Object is null\n";
    catch (Exception e)
    result = result+"\nError:\n"+e.toString();
    return result;
    public String writerTest()
    String result = "about to write";
    try
    result = result+"\nOpening the file";
    BufferedWriter writer = new BufferedWriter(new FileWriter("C:\\timerTest.txt"));
    result = result+"\nWriter Test Passed";
    writer.write("Writer Works");
    writer.newLine();
    result = result+"\nFlushing writer";
    writer.flush();
    result = result+"\nClosing writer";
    writer.close();
    catch (Exception e)
    result = result+"\n"+e.toString();
    return result;
    I am calling initializeTimer() from a jsp page with a simple <jsp:useBean tag>.
    The program keeps returning that the context variable is not set(this is from the context!=null conditional in initializeTimer()). I am very confused, I thought that setContext(...) was called by the container upon instantiation (and thus should happen completely without any action from me).
    How am I able to call a session bean that has not had the context set?
    Any information is appreciated,
    Thanks,
    Scott

    thank you for your reply, rajeevm007.
    it seems that the question is really a problem now.
    i think i should update weblogic to the lastest version and confirm this question. if it still in there, it seems that we have to reset the global variables all manually. so, now, we are discussing that should we modify all the ejbs, or wait the next version of weblogic. :) of cause the second choice is a joke.
    no other good choice?
    maybe in the march of the next year....
    cheers
    thank you again.

  • Calling EJB 3.0 Stateless Session Bean

    Dear all,
    I created a stateless session bean with a hello world method on it. Now i want to call the method from a BeanDecorator class, through a getter metod. When i use the jndi lookup in my getter, i can call the helloWorld method without a problem. However, when i dont use the jndi lookup, and only use the @EJB annotation, i always get a nullpointer.
    This is working:
    InitialContext ic = new InitialContext();
                   test = (TestLocal)ic.lookup("test.be/ear~bd/LOCAL/TestBean/"+TestLocal.class.getName());
                   test.helloWorld()
    This gives nullpointer:
    @EJB
    private TestLocal test;
    test.helloWorld();
    What is the correct way to consume session beans without having to explicitly code the jndi lookup?
    Kind regards.

    Hi,
    any annotation like this can be used only in "managed classes" like Session Beans, Servlets etc. Managed classes are those classes managed by the J2EE server. Managed here means, lifetime controlled by server.
    You can find this in J2EE specification.
    Frank

  • Problem when calling session bean from main.

    Hi everyone
    I get the following error when calling a session bean from main(String args[]).
    Sep 3, 2008 9:11:13 AM com.sun.enterprise.appclient.MainWithModuleSupport <init>
    WARNING: ACC003: Application threw an exception.
    java.lang.NullPointerException
    at databasetest.Main.main(Main.java:26)
    Here is my code beneath.
    I'm using netbeans and glassfish application server.
    Everything is in the same project, called DatabaseTest, I also have deployed the application before running the client.
    I'm running the client as follows, right click on the DatabaseTest-app-client and select run.
    The client:
    package databasetest;
    import com.test.UsersFacadeRemote;
    import javax.ejb.EJB;
    import com.test.Users;
    public class Main {
        @EJB
        private static UsersFacadeRemote usersFacade;
        public static void main(String[] args) {
            Users users = new Users(12, 34);
            usersFacade.create(users);
    }The remote facade I'm calling:
    package com.test;
    import java.util.List;
    import javax.ejb.Remote;
    @Remote
    public interface UsersFacadeRemote {
        void create(Users users);
        void edit(Users users);
        void remove(Users users);
        Users find(Object id);
        List<Users> findAll();
    }The stateless bean:
    package com.test;
    import java.util.List;
    import javax.ejb.Stateless;
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
    @Stateless
    public class UsersFacade implements UsersFacadeRemote {
        @PersistenceContext
        private EntityManager em;
        public void create(Users users) {
            em.persist(users);
        public void edit(Users users) {
            em.merge(users);
        public void remove(Users users) {
            em.remove(em.merge(users));
        public Users find(Object id) {
            return em.find(com.test.Users.class, id);
        public List<Users> findAll() {
            return em.createQuery("select object(o) from Users as o").getResultList();
    }

    looks like you're banging your head against the same brick wall as [I have done|http://forums.sun.com/thread.jspa?forumID=13&threadID=5317110] and [others have in the past|http://forums.sun.com/thread.jspa?forumID=136&threadID=5259913] if that's any consolation.
    Funny thing is, mine did actually work in the debugger but not when running!
    Strange thing that.
    I did initially interest someone from the developers but they couldn't really help, ended up saying : try instantiating your beans the EJB 2.1 way and see where that gets you. Yes that works but they promised us "hey no more dopey xml deployment descriptors just some cool annotations" didn't they?
    I've got the feeling were' missing something really obvious!
    Edited by: sebthebike on 03-Sep-2008 12:21

  • Why do we obtain a java.rmi.MarshalException during a stateless session bean method invocation from a client java program?

    Hello,
    we're using iAS SP3.
    We deployed a stateless session bean that has a business methods with a Vector as argument (put (vector, String)).
    If we call it from a servlet, it works fine. But when we try to call it from a thread, started in a standalone java client program, we obtain a java.rmi.MarshalException.
    We tried to use Vector and HashSet objects as arguments, but we always obtain this kind of exception. It seems strange because a similar
    method that returns a Collection of objects (getAll) works fine. This is the our bean Remote Interface:
    public interface Receive extends EJBObject {
    public void putMessage(Message message, java.lang.String la) throws RemoteException; // it works fine!!!
    public void putMessages(java.util.Vector messages, java.lang.String la) throws RemoteException; // it doesn't work!!!
    Collection getAll (java.lang.String la) throws RemoteException, EJBException; // it works fine!!!!
    This is the java client stack trace:
    java.rmi.MarshalException: CORBA MARSHAL 0 No; nested exception is:
    org.omg.CORBA.MARSHAL: minor code: 0 completed: No
    org.omg.CORBA.MARSHAL: minor code: 0 completed: No
    at java.lang.Class.newInstance0(Native Method)
    at java.lang.Class.newInstance(Class.java:241)
    at com.sun.corba.ee.internal.iiop.ReplyMessage.getSystemException(ReplyMessage.java:93)
    at com.sun.corba.ee.internal.iiop.ClientResponseImpl.getSystemException(ClientResponseImpl.java:82)
    at com.sun.corba.ee.internal.corba.ClientDelegate.invoke(ClientDelegate.java:199)
    at org.omg.CORBA.portable.ObjectImpl._invoke(ObjectImpl.java:248)
    at ejb._Receive_Stub.putMessages(_Receive_Stub.java:731)
    at commlayer.Receiver.run(Receiver.java:67)
    Does anyone know how to solve this problem?
    Thank you in advance,
    Maurizio

    This is big bug!
    This seems to occur when you try to return complex objects (e.g. a vector of classes or even the Date class).
    As a workaround you can add this Ejb or module to the iPlanet Classpath (NT via kregedit, Sun via iasenv skript.).
    This helps but i really don't know why.
    It should be fixed in 6.5, maybe. We'll see.
    Regards

Maybe you are looking for