Using local session bean interface from web container using EJB 3.0

Hi,
How can you use a local session bean interface from Java (rather than data controls) in a web container using EJB 3.0?
I can use a remote interface by looking up InitialContext, but I can't find a local interface this way (even from another session EJB). I can use a local interface from an EJB using annotation "EJB", but as I understand, this is not available in the web container.
If I try to add an ejb-jar.xml file, these seems to mess up by project...
Hope you can help.
Roger

The portable way to retrieve an EJB reference in Java EE is to either inject it or look it up via the
component's private naming environment. The simplest way is :
@EJB
private DocumentManager dm;
The global JNDI name is only used as an implementation specific way to uniquely assign an
identifier to a specific Remote EJB. It's best for this not to appear directly in the source code.
There's more on global JNDI names in our EJB FAQ :
https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html
The alternative to annotations is to use an ejb-ref to declare the ejb dependency. The ejb-ref
is declared in the standard deployment descriptor corresponding to the component doing the
lookup. Each ejb-ref has an ejb-ref-name, e.g. <ejb-ref-name>DM_ref</ejb-ref-name>
The code looks up the ejb-ref-name relative to the java:comp/env namespace to retrieve the
EJB reference.
DocumentManager dm = (DocumentManager)
new InitialContext().lookup("java:comp/env/DM_ref");

Similar Messages

  • Local Session Bean calling another local Session Bean in EJB 3.0

    Hi,
    In EJB 3.0, I am trying to do JNDI lookup of a local sesion bean from another session bean's helper class.
    I am not using @EJB injection mechanism here, as call to the local session bean is made in a helper class. Helper classes do not support resource injection.
    Following are the EJB class definitions used in my project. Call to "EJB3Local" made from "EJB1" fails as the "EJB2" helper class is calling "EJB1Local"
    @Stateless
    @EJBs({@EJB(name="EJB2Local", beanInterface=EJB2Local.class),
    @EJB(name="EJB3Local", beanInterface=EJB3Local.class)})
    public class EJB1 implements EJB1Remote, EJB1Local{
    public void findEJB3Local(){
    //1. JNDI lookup for EJB3Local ----
    //2. EJB3Local.someFunction()
    @Stateless
    @EJB(name="EJB1Local", beanInterface=EJB1Local.class)
    public class EJB2 implements EJB2Remote, EJB2Local{
    public void findEJB1Local(){
    //1. JNDI lookup EJB1Local
    // 2. Call EJB1Local.findEJB1Local method
    @Stateless
    public class EJB3 implements EJB3Remote, EJB3Local{
    public void someFunction(){}
    A remote call to EJB2.findEJB1Local() will invoke EJb1Local.findEJB3Local method and the call fails with "java:comp/env/EJB3Local" not found in EJB1Local.
    Has anybody encountered an issue like this issue with local interface calling another local interface?
    Thanks,
    Mohan

    To refer a Ejb from another Ejb include <ejb-ref> element
    in ejb-jar.xml
    <session>
    <ejb-name>SessionBeanA</ejb-name>
    <ejb-ref>
    <ejb-ref-name>SessionBeanB</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <home>com.ejb.SessionBeanBHome</home>
    <remote>com.ejb.SessionBeanB</remote>
    </ejb-ref>
    </session>
    Include a <reference-descriptor> in weblogic-ejb-jar.xml
    <weblogic-enterprise-bean>
    <ejb-name>SessionBeanA</ejb-name>
    <reference-descriptor>
    <ejb-reference-description>
    <ejb-ref-name>SessionBeanB</ejb-ref-name>
    <jndi-name>com.ejb.SessionBeanBHome</jndi-name>
    </ejb-reference-description>
    </reference-descriptor>
    </weblogic-enterprise-bean>
    In SessionBeanA Bean class refer to SessionBeanB with
    a remote reference to SessionBeanB.
    InitialContext initialContext=new InitialContext();
    SessionBeanBHome sessionBeanBHome=(SessionBeanBHome)
    initialContext.lookup("com.ejb.SessionBeanBHome");
    SessionBeanB sessionBeanB=sessionBeanBHome.findByPrimaryKey(primarykey);
    sessionBeanB.update();
    sessionBeanB.getAll();
    thanks,
    Deepak

  • Local session bean lookup in another local session bean in EJB 3.0

    Hi,
    I am doing JNDI lookup of a local session bean in a session bean. ( I do not want to use EJB dependency injection).
    Lookup of local interface from session bean is successful. But, when the calling session bean is a local session in another session bean, the lookup fails.
    Here is an example:
    @Stateless
    @EJBs({@EJB(name="EJB2Local", beanInterface=EJB2Local.class),
    @EJB(name="EJB3Local", beanInterface=EJB3Local.class)})
    public class EJB1 implements EJB1Remote, EJB1Local{
    public void findEJB3Local(){
    //1. JNDI lookup for EJB3Local ----
    //2. EJB3Local.someFunction()
    @Stateless
    @EJB(name="EJB1Local", beanInterface=EJB1Local.class)
    public class EJB2 implements EJB2Remote, EJB2Local{
    public void findEJB1Local(){
    //1. JNDI lookup EJB1Local
    // 2. Call EJB1Local.findEJB1Local method
    //THIS METHOD CALL WILL FAIL.
    public void findEJB1Remote(){
    //1. JNDI lookup EJB1
    / 2. Call EJB1Local.findEJB1 method
    @Stateless
    public class EJB3 implements EJB3Remote, EJB3Local{
    public void someFunction(){}
    This setup was working in EJB 2.1, as we had clear ejb-local-ref definitions in our ejb-jar.xml file.
    I am suspecting that EJB 3.0 has special annotation to use when lookup is made from another local session bean.
    Any comments will be appreciated.
    Thanks,
    Mohan

    From a private component environment perspective, declaring @EJB in a bean class is equivalent
    to using ejb-ref or ejb-local-ref for that same bean in ejb-jar.xml. In each case, the EJB dependency
    is declared for that bean. Each EJB component has its own private component environment, so
    code running within invocations on different EJBs can not see the component environment of the
    components that made the invocations.
    What exact error are you getting? Please post the stack trace if possible.
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Local Session Bean Call Exception in App Server

    I have been having trouble calling a Local Session bean in Glassfish.
    I set up an example to show the exception I am having:
    MainBeanLocal
        package com.test;
        import javax.ejb.Local;
        @Local
        public interface MainBeanLocal {
             void testCall();
    MainBean:
        package com.test;
        import javax.ejb.Stateless;
         * Session Bean implementation class MainBean
        @Stateless(mappedName = "ejb/MainBean")
        public class MainBean implements MainBeanLocal {
             @Override
             public void testCall() {
                  System.out.println("Test Call Succeeded");
    RemoteBeanRemote:
        package com.test;
        import javax.ejb.Remote;
        @Remote
        public interface RemoteBeanRemote {
             public void callMainBean();
    RemoteBean:
        package com.test;
        import javax.ejb.Stateless;
        import javax.naming.InitialContext;
        import javax.naming.NamingException;
         * Session Bean implementation class RemoteBean
        @Stateless(mappedName = "ejb/RemoteBean")
        public class RemoteBean implements RemoteBeanRemote {
             @Override
             public void callMainBean() {
                  try {
                       InitialContext ctx = new InitialContext();
                       MainBeanLocal mb = (MainBeanLocal) ctx.lookup("ejb/MainBean");
                       mb.testCall();
                  } catch (NamingException e) {
                       // TODO Auto-generated catch block
                       e.printStackTrace();
    Test Code:
        package com.test;
        import javax.naming.InitialContext;
        import javax.naming.NamingException;
        public class BeanTester {
             public static void main(String[] args){
                  try {
                       InitialContext ctx = new InitialContext();
                       RemoteBeanRemote remote = (RemoteBeanRemote) ctx.lookup("ejb/RemoteBean");
                       remote.callMainBean();
                  } catch (NamingException e) {
                       // TODO Auto-generated catch block
                       e.printStackTrace();
    Output Trace:
        INFO: deployed with moduleid = TestEJB
        INFO: **RemoteBusinessJndiName: ejb/RemoteBean; remoteBusIntf: com.test.RemoteBeanRemote
        INFO: LDR5010: All ejb(s) of [TestEJB] loaded successfully!
        WARNING: javax.naming.NameNotFoundException: MainBean not found
             at com.sun.enterprise.naming.TransientContext.doLookup(TransientContext.java:216)
             at com.sun.enterprise.naming.TransientContext.lookup(TransientContext.java:188)
             at com.sun.enterprise.naming.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:74)
             at com.sun.enterprise.naming.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:111)
             at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:409)
             at javax.naming.InitialContext.lookup(InitialContext.java:392)
             at com.test.RemoteBean.callMainBean(RemoteBean.java:19)
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:597)
             at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1011)
             at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:175)
             at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2920)
             at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4011)
             at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:203)
             at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:117)
             at $Proxy71.callMainBean(Unknown Source)
    ...What am I doing wrong when calling **MainBeanLocal**? I would like to avoid dependency injection, as if the MainBeanLocal was being called from a POJO.
    Note: I have no trouble calling the RemoteBean.. I want to be able to call the local bean from the remote bean.

    Maik,
    If this is still a problem, could you please post the descriptors from the EAR?
    Are you using any annotations?
    - Tim

  • Create PDF from Web page using Acrobat X - Page Order

    I have a structured web site that is in fact Program Help The web pages are structured as follows:
    index.html - Main Topic Index page with links to all topic subject index pages
    topic/index.html - Topic Subject Index Page with links to all subject pages
    topic/subject.html - Subject page
    .....etc
    Using Acrobat 5 "Create PDF from Web Page" created a perfect logical PDF  page structure in the page order of of the web site. In Acrobat 5 page 1  was the Main Topic Index Page, page 2 was the 1st Topic Subject Index  Page, page 3 was the 1st Subject Page, then the 2nd subject of the 1st  Topic, etc. until the Topic Subjects were exhausted after which the 2nd  Topic Subject Index Page and so it went on. As a result the bookmark  structure was sensible. The page order was as follows:
    Main Topic Contents
    Topic 1 Contents
    Subject 1 of Topic 1
    Subject 2 of Topic 1
    Topic N Contents
    Subject 1 of Topic N
    Subject 2 of Topic N
    Acrobat X (just purchased) produces a differently structured PDF from the same HTML pages. The order is:
    Main Topic Contents
    Topic 1 Contents
    Topic 2 Contents
    Topic N Contents
    Main Topic Contents (a second time)
    Subject 1 of Topic 1
    Subject 2 of Topic 1
    Subject N of Topic 1
    Subject 1 of Topic 2
    Subject 2 of Topic 2
    Subject N of Topic N
    Question: Is there any way I can get back with Acrobat X the same page order I got with Acrobat 5?
    Any help appreciated. The website is www.caliach.com/caliach/vision/help/index.html
    Chris

    Acrobat is using the underlying mark up of the rendered HTML page.
    This may or may not provide an adequate input to Acrobat when it is noodling out how and what to tag.
    I suspect you may find that, to obtain an adequately tagged PDF, you may have to capture the web page content with the create bookmarks and create tags options off.
    Once you have the PDF make working copies.
    Try letting Acrobat tag this already created PDF to see what happens.
    You may have to manually tag the PDF.
    n.b., The default read order for western language can be altered by user selections in the accesibility setup or by selection in the PDF page(s) Page Properties.
    Be well...

  • May i use the session bean in the jsp

    <%@ page import="sms.EJB.*,sms.UserDetailEJB.*" %>
    <%
    if (request.getParameter("userid")!=null && request.getParameter("password") !=null && request.getParameter("userLevel")!=null)
    UserHome userHome look up...
    UserLocal userLocal;
    userLocal = userHome.create(userid,password,userlevel);
    %>
    <html>
         <head>
              <title>Insert One Page</title>
         </head>
         <body>
         <form action="/testing/insertOne.jsp">
              <h1 align="center">Insert into User Database !</h1>
              <table align="center">
                   <tr>
                        <td bgcolor ="#FFFCCC">User Name :</td>
                        <td bgcolor ="#FFFCCC"><input type="text" name="userName" size="12" maxlength="12"></td>
                   </tr>
                   <tr>
                        <td bgcolor ="#FFFCCC">Password :</td>
                        <td bgcolor ="#FFFCCC"><input type="password" name="password" size="12" maxlength="12"></td>
                   </tr>
                   <tr>
                        <td bgcolor ="#FFFCCC">User Level :</td>
                        <td bgcolor ="#FFFCCC"><input type="text" name="userLevel" size="12" maxlength="12"></td>
                   </tr>
              </table>
              <p align="center"><input type="submit" name="submit" value="add it"</p>
         </form>
         </body>
    </html>
    May i use the session bean like this, if i dont want to use the data access object
    may i use this...

    Hey it apperars to me like heero82 is using session facade and all he has to do is use session bean to make one business call on session bean. Now if u say it is not correct then i would like to know the better way to doing so.
    I can imagine one ways is use business delegate. Just make new of java class in jsp and let that java class do lookup and delegate the call to session facade.
    Let me know inpout on this
    pranav

  • Code using advisor session bean..returning of a list

    Hi,
    I am using Advisor Session Bean for classifying users instead of using pz:div
    tags. The steps are given in documentation. I wanted to know what advice.getResult()
    returns? It has been given in the API as an Object. Even in pz:div java file they
    have used this code to check if the getresult returns something ...
    Object nestedResult = advice.getResult();
    if((nestedResult instanceof List) && ((List)nestedResult).size() > 0)
    {  //belongs to segment
    My code works perfectly but I am curious to know about this code. Can anyone please
    tell me about the above given code?
    Thanx

    Assuming you are using v7.0
    This might help
    http://edocs.bea.com/wlp/docs70/dev/p13n.htm#1000231
    i dont know if this has changed in v8.1
    hth
    deepak
    "Madhu" <[email protected]> wrote:
    >
    Hi,
    I want to use the Advisor session bean directly in place of the tags
    to return
    content based on a static query and match the content to users based
    on rules
    that execute a content query. Where can I find more information on this?
    Thanx.
    Madhu

  • Why can't GB let me use 'electric guitar' option when using Nio 2/4 interface - I have to use real instrument and miss out on all the effects. Is this normal for all interfaces?

    Why can't GB let me use 'electric guitar' option when using Nio 2/4 interface - I have to use real instrument and miss out on all the effects. Is this normal for all interfaces? The Nio reads hte guitar but GB doesn't....

    Usually effects packages are AU plugins that would have no effect on track selection. Interfaces should have no control over what kind of track you can select. I really think something else is going on her maybe something you overlooked.
    Did you choose the input channel in the track info pane. Try both channel 1 mono or channel 2 mono. Make sure the track is record enabled.

  • Accessing Local Interface EJB from Web Container Oracle App Server 9.0.4

    Hi,
    I am developing a struts based small application, which calls a EJB which uses Local Interface from Struts ActionClass.
    I am getting NameNotFoundException. The exact exception is s mentioned below.
    05/03/29 16:15:49 javax.naming.NameNotFoundException: LoginRSL not found
    The deployment descriptors are as mentioned below.
    =============
    ejb-jar.xml
    <?xml version = '1.0' encoding = 'windows-1252'?>
    <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
    <ejb-jar>
    <enterprise-beans>
    <session>
    <description>Session Bean ( Stateless )</description>
    <display-name>LoginRSL</display-name>
    <ejb-name>LoginRSL</ejb-name>
    <local-home>loginApp.model.LoginRHome</local-home>
    <local>loginApp.model.LoginL</local>
    <ejb-class>loginApp.model.LoginRSL</ejb-class>
    <session-type>Stateless</session-type>
    <transaction-type>Container</transaction-type>
    </session>
    </enterprise-beans>
    <relationships/>
    <assembly-descriptor>
    <container-transaction>
    <method>
    <ejb-name>LoginRSL</ejb-name>
    <method-name>*</method-name>
    </method>
    <trans-attribute>Required</trans-attribute>
    </container-transaction>
    </assembly-descriptor>
    </ejb-jar>
    orion-ejb-jar.xml
    <?xml version = '1.0' encoding = 'windows-1252'?>
    <!DOCTYPE orion-ejb-jar PUBLIC "-//Evermind//DTD Enterprise JavaBeans 1.1 runtime//EN" "http://xmlns.oracle.com/ias/dtds/orion-ejb-jar.dtd">
    <orion-ejb-jar>
    <enterprise-beans>
    <session-deployment name="LoginRSL"/>
    </enterprise-beans>
    </orion-ejb-jar>
    I also tried adding following code to web.xml
    web.xml
    <ejb-local-ref>
    <ejb-ref-name>LoginRSL</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <local-home>LoginRHome</local-home>
    <local>LoginL</local>
    <ejb-link>LoginRSL</ejb-link>
    </ejb-local-ref>
    It is quite evident that it is not able to lookup the JNDI name.
    Can someone throw light on this? If someone has working sample of this, can you mail it to [email protected]?

    Nipun,
    WebLogic and OC4J are not the same thing. That's like saying Oracle and SQL Server are the same thing -- or C++ and Java are the same thing.
    I recall a posting to a forum (don't remember if it was this one), where the poster was complaining that some feature of the application server he had previously used, was not supported by OC4J. Turned out that the feature he was referring to, contradicted the J2EE specification -- which is why it wasn't available in OC4J. In other words, he didn't like the fact that OC4J was more compliant with the J2EE specification than his "other" application server. Go figure!
    So, if you haven't already done so, I suggest you verify that this feature of WebLogic is something that complies with the J2EE specifications -- before expecting OC4J to support the same feature.
    And if it's not clear, from the specifications, then every vendor is free to implement this feature (or not).
    So if it turns out that WebLogic is a more appropriate application server for you -- then why not just stick with it (and forget the others)?
    Good Luck,
    Avi.

  • Could not access Local Session Bean using JNDI lookup

    Hi EJB Guru,
    I am quite new to EJB 3.0 but have had a good deal of success including using JNDI to lookup Remote Stateless Session Bean in EJB 3.0. However, looking up local Stateless Session Bean prove more challenging with I had anticipated.
    Here is my code
    as follows:
    public interface Calculator {
        public int add(int x, int y);
        public int subtract(int x, int y);
    import javax.ejb.Remote;
    @Remote
    public interface CalculatorRemote extends Calculator {
    import javax.ejb.Local;
    @Local
    public interface CalculatorLocal extends Calculator {
    import javax.ejb.Local;
    import javax.ejb.Remote;
    import javax.ejb.Stateless;
    import bean.CalculatorLocal;
    import bean.CalculatorRemote;
    @Stateless
    public class CalculatorBean implements CalculatorRemote, CalculatorLocal {
        public int add(int x, int y) {
            return x + y;
        public int subtract(int x, int y) {
            return x - y;
    import bean.*;
    import bean.Calculator;
    import bean.CalculatorLocal;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    public class ClientAccessLocalCalculator {
        public static void main(String[] args) throws NamingException {
            InitialContext ctx = new InitialContext();
            CalculatorLocal calculator = (CalculatorLocal) ctx.lookup("CalculatorBean/local");
            System.out.println("1 + 1 = " + calculator.add(1, 1));
            System.out.println("1 - 1 = " + calculator.subtract(1, 1));    }
    import bean.Calculator;
    import bean.CalculatorRemote;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    public class ClientAccessRemoteCalculator {
        public static void main(String[] args) throws NamingException {
            InitialContext ctx = new InitialContext();
            CalculatorRemote calculator = (CalculatorRemote) ctx.lookup("CalculatorBean/remote");
            System.out.println("1 + 1 = " + calculator.add(1, 1));
            System.out.println("1 - 1 = " + calculator.subtract(1, 1));    }
    }Output when running ClientAccessRemoteCalculator gives
    1 + 1 = 2
    1 - 1 = 0
    Output when running ClientAccessLocalCalculator on JBoss AS 4.0.5 gives:
    Exception in thread "main" javax.ejb.EJBException: Invalid invocation of local interface (null container)
    at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:75)
    at $Proxy0.add(Unknown Source) at ClientAccessLocalCalculator.main(ClientAccessLocalCalculator.java:14)
    JNDIView in JMX-Console in JBoss:
    +- CalculatorBean (class: org.jnp.interfaces.NamingContext)
    | +- local (proxy: $Proxy84 implements interface bean.CalculatorLocal,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBLocalObject)
    | +- remote (proxy: $Proxy83 implements interface bean.CalculatorRemote,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBObject)
    Output when running ClientAccessLocalCalculator on SJSAS 9.0 gives:
    Exception in thread "main" javax.naming.NameNotFoundException: bean.CalculatorLocal not found
    C:\>asadmin
    Use "exit" to exit and "help" for online help.
    asadmin> list-jndi-entries
    Jndi Entries for server within root context:
    bean.CalculatorRemote: javax.naming.Reference
    jbi: com.sun.enterprise.naming.TransientContext
    jdbc: com.sun.enterprise.naming.TransientContext
    UserTransaction: com.sun.enterprise.distributedtx.UserTransactionImpl
    bean.CalculatorRemote__3_x_Internal_RemoteBusinessHome__: javax.naming.Reference
    bean.CalculatorRemote#bean.CalculatorRemote: javax.naming.Reference
    ejb: com.sun.enterprise.naming.TransientContext
    Command list-jndi-entries executed successfully.
    asadmin>I am using Application Client to lookup these Session Beans on Netbeans 5.5, JBoss AS 4.0.5 (EJB3 installer)/SJSAS
    9.0, SDK 1.5.0_11 on Windows XP platform.
    Any assistance would be much appreciated.
    Many thanks,
    Henry

    Hi Henry,
    Any direct global JNDI lookup is not portable. It works in some cases but not in others, which
    is why we recommend using the portable Java EE approach of declaring an ejb dependency
    and looking up that dependency via the bean's component environment (java:comp/env).
    This is true whether you're dealing with Remote or Local ejb dependencies.
    Local ejbs are not supported in the Application Client tier at all. In the server tier, there is no
    guarantee that a Local EJB even is assigned a global JNDI name since there's no requirement
    that it be available outside of the application in which the ejb is defined.
    You can find more information on these ejb access topics in our EJB FAQ :
    https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html

  • Using only one method in session bean to create web service

    Hi all,
    I hhave a scenario where i am inserting and retrieving data from dict table using web service.
    For this i have created a session bean and a wrapper class.
    The session bean has two methods: insertRecords(), and viewRec().
    so while creating a web service i need to include two methods.
    I want to have only one method where i can pass a parameter as operation and if it is "I", then i can call the insert method and if it is "S" i can call view method.
    I tried doing that bt i am stuck up with the return type.
    Insert method has return type as array of wrapper class and
    view method has wrapper class as return type ...
    Is this scenario possible..??
    or is there any other way to do this???
    Plz let me knw..
    Thankls n regards,
    Ankita

    Hi Siddharth,
    Im really sorry..
    i cudnt  get u ..
    Actually these r methods:
    public DemoDicModel[] viewRecords()
    and
    public DemoDicModel insertRecords(
              String title,
              String desc,
              String status)
    and im trying this:
    public DemoDicModel[] getMethods(String operation,String title,String desc, String st)
    DemoDicModel[] demoModel =null;
    DemoDicModel model = new DemoDicModel();
    if(operation == "show")
          demoModel = viewRecords();
    if(operation == "ins")
          model = insertRecords(title,desc,st);
          model.setMsg("RECORDS GENERATED");
          demoModel=
    return demoModel;
    im stuck up with insert operation.
    can  u plz explain me in detail.
    thanks,
    ankita

  • Create a entity using a session bean in web dynpro

    Hi.
    I want to create an entity bean object trough an EJB session bean in web dynpro, e.g using a form in a WD application filled in by a user.
    I understand how to display a list of entity beans through a session bean and a table, but I don't understand how to create (or edit or remove) such information.
    My session beans look like this:
    @Stateless
    public class MyObjectBean implements MyObjectLocal {
         @PersistenceContext(name = "MyObject", unitName="ProjectPU")
         public EntityManager em;
         public void create(MyObject myObject) {
              em.persist(myObject);
         public void edit(MyObject myObject) {
              em.merge(myObject);
         public void remove(MyObject myObject) {
              em.remove(em.merge(myObject));
         public MyObject find(Integer id) {
              return em.find(MyObject.class, id);
         @SuppressWarnings("unchecked")
         public List<MyObject> findAll() {
              return em.createNamedQuery("MyObject.findAll").getResultList();
    So the model class would be called Request_MyObjectLocal_create.
    I attempted to use [this|http://help.sap.com/saphelp_nwce10/helpdata/en/45/dd45e4bc295595e10000000a1553f7/frameset.htm] help file but I find the answer (step 17) quite unclear.
    Help is greatly appreciated!
    Vincent.

    I've just found the solution from Steve Muench weblog, always useful by the way!
    You can find the solution at this link http://radio.weblogs.com/0118231/stories/2004/05/07/handcodingDynamicDiscoveryOfEjbdeployedAppmodule.html
    In summary, we need to use the class com.evermind.server.rmi.RMIInitialContextFactory, which supports dynamic lookup, and implement the lookup ourselves.
    The code I've written to lookup the service is listed below:
    public static ApplicationModule getAppModuleManutencao() {
    try {
    Context ctx = getContext();
    ManutencaoFacadeHome home = (ManutencaoFacadeHome) ctx.lookup(EJB_MANUTENCAO_BEAN_NAME);
    ApplicationModule am = ApplicationModuleProxy.create(home, null);
    return am;
    } catch (NamingException nex) {     
    nex.printStackTrace();
    return null;
    private static InitialContext getContext() {   
    try {     
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory");
    env.put(Context.SECURITY_PRINCIPAL, "admin");
    env.put(Context.SECURITY_CREDENTIALS, "welcome");
    env.put(Context.PROVIDER_URL, "opmn:ormi://dsv008:OC4J_dvt20/mct");
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    return new InitialContext(env);
    }catch (NamingException e) {     
    e.printStackTrace();
    return null;
    I hope this helps someone!!!
    Cheers!

  • NoSuchMethodException calling a session bean method from a web service

    I am running on NetWeaver 6.40 SP10 on Windows.
    I have a Java class (not a SessionBean) exposed as a web service where I invoke a session bean method with an argument that is another Java class (basically, just a JavaBean with some getters and setters).  I am getting a strange reflection-related error when I invoke a session bean method.  The exception I see is a 'java.lang.reflect.UndeclaredThrowableException', and if I unwrap it with 'ex.getCause()', I see 'java.lang.NoSuchMethodException: com.xx.ejb.PersistentObjectSBObjectImpl0.createR3Config(com.xx.common.R3Config)'
    I have spent several days trying to come up with a testcase for this, but to no avail.  The calling class is:
    --- snip R3UpdateTest.java ---
    package com.xx.server.webse;
    import com.xx.ejb.*;
    import com.xx.common.*;
    import java.util.*;
    import javax.ejb.*;
    import java.rmi.*;
    import javax.naming.*;
    * @author william_woodward
    * To change the template for this generated type comment go to
    * Window>Preferences>Java>Code Generation>Code and Comments
    public class R3UpdateTest {
         public String createR3Config(String a, String b, String c,
                   String d, String e, String f) {
              String retval = "success!";
              try {
                   PersistentObjectSB poSB = getPersistentObjectSB();
                   R3Config r3cfg = new R3Config();
                   r3cfg.setR3HostName(a);
                   r3cfg.setR3SystemNumber(b);
                   r3cfg.setRfcUserName(c);
                   r3cfg.setRfcPassword(d);
                   r3cfg.setRfcClient(e);
                   r3cfg.setRfcLanguage(f);
                   poSB.createR3Config(r3cfg);
              } catch (Exception ex) {
                   retval = "Exception: " + ex + ", Causing Exception : " + ex.getCause();
              return retval;
          * Private methods
         private PersistentObjectSB getPersistentObjectSB() throws RemoteException, CreateException, NamingException {
              Properties props = new Properties();
              props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl");
              props.put(Context.PROVIDER_URL, "localhost:50004");
              InitialContext ctx;
              ctx = new InitialContext(props);
              PersistentObjectSBHome poSBHome =
                   (PersistentObjectSBHome) javax.rmi.PortableRemoteObject.narrow(
                        ctx.lookup("xx.com/CMPOBEAR/PersistentObjectSBBean"),
                        PersistentObjectSBHome.class);
              return poSBHome.create();
    --- end R3UpdateTest.java ---
    If I change the createR3Config() method to take an argument of class 'Object' instead of an argument of class 'R3Config', and then cast the object back into an R3Config in the method body, it all works fine.
    Any clues, anyone?
    Thanks,
    - Bill
    Message was edited by: Bill Woodward - Fixed some funky formatting

    Sure, I can show them to you.  They are very similar to a couple of non-DC classes/projects I put together to try and duplicate the problem.
    First, the interface, PersistentObjectSB.java:
    package com.xx.ejb;
    import javax.ejb.EJBObject;
    import com.xx.common.R3Config;
    import java.rmi.RemoteException;
    public interface PersistentObjectSB extends EJBObject {
          * Business Method.
         public void updateR3Config(R3Config r3Config) throws RemoteException;
          * Business Method.
         public void createR3Config(R3Config r3Config) throws RemoteException;
    And the implementation, PersistentObjectSBBean.java:
    package com.xx.ejb;
    import java.util.*;
    import javax.ejb.*;
    import javax.naming.*;
    import com.xx.common.*;
    import com.xx.interfaces.*;
    * @ejbHome <{com.xx.ejb.PersistentObjectSBHome}>
    * @ejbLocal <{com.xx.ejb.PersistentObjectSBLocal}>
    * @ejbLocalHome <{com.xx.ejb.PersistentObjectSBLocalHome}>
    * @ejbRemote <{com.xx.ejb.PersistentObjectSB}>
    * @stateless
    public class PersistentObjectSBBean implements SessionBean {
         private R3ConfigEJBLocalHome _r3ConfigEJBLocalHomeIf = null;
         public void ejbRemove() {
         public void ejbActivate() {
              try {
                   setEJBLocalHome();
              } catch (NamingException e) {
                   throw new EJBException(e);
         public void ejbPassivate() {
         public void setSessionContext(SessionContext context) {
              myContext = context;
         private SessionContext myContext;
          * Create Method.
         public void ejbCreate() throws CreateException {
              try {
                   setEJBLocalHome();
              } catch (NamingException e) {
                   throw new CreateException();
          * Business Method.
         public void updateR3Config(R3Config r3Config) {
              try {
                   R3ConfigPrimaryKey primKey = new R3ConfigPrimaryKey();
                   primKey.r3HostName = r3Config.getR3HostName();
                   primKey.r3SystemNumber = r3Config.getR3SystemNumber();
                   R3ConfigEJBLocal r3ConfigEJBLocal =
                        _r3ConfigEJBLocalHomeIf.findByPrimaryKey(primKey);
                   if (r3ConfigEJBLocal != null) {
                        r3ConfigEJBLocal.updateR3Config(r3Config);
              } catch (Exception e) {
                   // What to do here?
          * Business Method.
         public void createR3Config(R3Config r3Config) {
              try {
                   R3ConfigEJBLocal r3ConfigEJBLocal =
                        _r3ConfigEJBLocalHomeIf.create(r3Config);
              } catch (Exception e) {
                   // What to do here?
         private void setEJBLocalHome() throws NamingException {
              Properties props = new Properties();
              props.put(
                   Context.INITIAL_CONTEXT_FACTORY,
                   "com.sap.engine.services.jndi.InitialContextFactoryImpl");
              InitialContext ctx = new InitialContext(props);
              Object obj = ctx.lookup("localejbs/R3ConfigEJB");
              _r3ConfigEJBLocalHomeIf = (R3ConfigEJBLocalHome) (obj);
    Thanks,
    - Bill

  • Configure webapp to use local or remote interface based on environment

    Hi,
    I have the following problem I am trying to solve (app server is Weblogic 10g by the way).
    I have a webapp (war-project) and an ear project containing stateless session beans.
    In our development environment I would like to deploy the war and ear separately, because that is easier for development (war-project can then be deployed as a directory, so changes to jsp's and such have immediate effect).
    Deploying the war and ear separately means that the war-project can only call the session beans through their remote interfaces. For development this is not a problem.
    In a production environment however we would like to package the war INSIDE the ear, so that the webapp can use the local interfaces to call the session beans, as this will improve performance.
    So I am looking for a solution where I can configure the way beans are called. Local if the war is inside the ear, remote if the war is separate from the ear. I was thinking along the lines of packaging a properties file with the war that determines the mode (local or remote). Or maybe packaging a different deployment descriptor, if that is a possibility.
    This is what I have so far:
    Business Interface_
    package be.cegeka.test.ejb3.service;
    public interface TestService {
         public void doSomething();
    Remote Interface_
    package be.cegeka.test.ejb3.service;
    public interface TestServiceRemote extends TestService {
    Local Interface_
    package be.cegeka.test.ejb3.service;
    public interface TestServiceLocal extends TestService {
    Bean implementation_
    package be.cegeka.test.ejb3.service;
    import javax.ejb.Local;
    import javax.ejb.Remote;
    import javax.ejb.Stateless;
    @Stateless(mappedName="ejb/TestService")
    @Local(TestServiceLocal.class)
    @Remote(TestServiceRemote.class)
    public class TestServiceBean implements TestService {
         @Override
         public void doSomething() {
              System.out.println("I'm doing something");
         @Override
         public void doSomethingLocal() {
              System.out.println("I'm doing something local");
    JSF backing bean_
    package be.cegeka.test.ui;
    public class MyWebAppBackingBean {
         @EJB(mappedName="ejb/TestService", beanInterface=TestServiceRemote.class)
         private TestService testService;
         public String doSmth() {
              testService.doSomething();
              return "success";
    }The part that I would like to be configurable is the "+beanInterface=TestServiceRemote.class+" part in the JSF backing bean. Depending on the environment (development vs. production), this should be "+beanInterface=TestServiceRemote.class+" for development and "+beanInterface=TestServiceLocal.class+" for production.
    Is something like this possible?
    I would like to avoid having to fill my web.xml with ejb-refs and having to do the JNDI-lookups myself if at all possible, to keep things as easy and clean as possible.
    Any ideas are welcome!
    Steven

    Hey Manish,
    comments inline.
    "manish kumar" <[email protected]> wrote in message
    news:1794338.1102557677925.JavaMail.root@jserv5...
    So If they are supposed to be in the same JVM -
    then
    1. the cluster of 3 weblogic servers are three JVMs. So does that meanLOCAL INTERFACES CAN'T BE USED IN CLUSTERED ENVIORONMENT ?
    Sure they can, but the calling component in an enterprise app will not call
    an intance of the local bean on another node in the cluster. It will make a
    by-reference call to the local component in the same EAR. Local interfaces
    are not Remote, so they cannot be used with by-value RMI semantics.
    >
    2. ARE YOU SURE ABOUT THIS FACT THAT THAT LOCAL INTERFACES CAN BE USEDONLY INSIDE THE SAME APPLICATION, I THOUGHT IT CAN BE USED AS LONG AS CLINET
    IS IN THE SAME JVM?
    PLEASE CONFIRM.........!!!!!!!!!!!!!Dead sure:
    http://e-docs.bea.com/wls/docs81/programming/classloading.html#1073506
    http://e-docs.bea.com/wls/docs81/ejb/understanding.html#1126831
    http://e-docs.bea.com/wls/docs61/ejb/cmp.html#1085452
    http://www.theserverside.com/discussions/thread.tss?thread_id=14628
    Also, search the ejb newsgroups. I know Rob Woollen has addressed this in
    here somewhere. And, if Rob says it's so, trust me, it's so.
    Bill

  • How to use a session bean in another session bean (or an EJB in a session)

    JDev 11.1.1.4, WLS 10.3.4, Windows 7 x64
    I have a login controller with a session-scoped bean that manages logins.
    I have another session-scoped bean that manages menu security.
    both modules compile and work fine now I need to share the data from one to another.
    I need to reference the login controller in the menu security bean. How do I reference (include) the login bean in the security bean?
    I tried an EJB - what a farce - these are supposed to be universal and easy ( basis of the oop in Java).
    the bean is defined:
    @Stateless(name = "SecurityEJB", mappedName = "ZITASApplication-ZITASModel-SecurityEJB")
    I have tried :
    ic = new InitialContext();
    session = (SecurityEJBLocal)ic.lookup("ZITASApplication-ZITASModel-SecurityEJB#model.security.logic.SecurityEJB");
    session = (SecurityEJBLocal)ic.lookup("ZITASApplication-ZITASModel-SecurityEJB#model.security.logic.SecurityEJBLocal");
    session = (SecurityEJBLocal)ic.lookup("java:ejb/model.security.logic.SecurityEJB");
    session = (SecurityEJBLocal)ic.lookup("java:ejb/SecurityEJB");
    session = (SecurityEJBLocal)ic.lookup("java:app/SecurityEJB");
    session = (SecurityEJBLocal)ic.lookup("java:module/SecurityEJB");
    All return null pointers and claim the name cannot be resolved.
    As you can see - I have found various claims to how to do this.
    One way says create a sevlet, generate a listener and use the sevlet. Basically one for every EJB - a lot of work to use the EJBs
    I would assume that this would be one of the easiest parts of java - as it is the foundation of re-usability and oop.
    I can do either in the application - the added complexity of the EJB is less desirable - but better programming?

    Hi,
    ic.lookup("ZITASApplication-ZITASModel-SecurityEJB#model.security.logic.SecurityEJB");This should work with remote interface. If you want to lookup local interface, you need to register it in web.xml. Quote:
    To access the business local interface you need to define ejb local references for your component environment (i.e. from your servlet environment). You can do this by defining references in your web.xml. For example:
    <ejb-local-ref>
    <ejb-ref-name>ejb/BusinessLogicBean</ejb-ref-name>
    <local>packagename.BusinessLogicBean</local>
    </ejb-local-ref>
    To lookup your local reference from your servlet you need to use the following JNDI reference:
    java:comp/env/ejb/BusinessLogicBean Another one
    First, declare a local ejb reference in your web.xml file (This will add it to JNDI):
    <ejb-local-ref>
    <ejb-ref-name>ejb/Foo</ejb-ref-name>
    <local>simple.ejb.FooLocal</local>
    </ejb-local-ref>
    Then it can be looked up from JNDI:
    InitialContext ctx = new InitialContext();
    FooLocal foo = ctx.lookup("java:comp/env/ejb/Foo");Hope this helps.
    Pedja
    Helpful links (judging from your first post, you are probably sick of these :) )
    How to lookup local EJB in Oracle Weblogic 10.3
    http://m-button.blogspot.com/2008/07/reminder-on-how-to-use-ejb3-with.html
    http://www.coderanch.com/t/451012/EJB-JEE/java/EJB-Local-Lookup-not-working

Maybe you are looking for

  • How do I select one version from multiple stacks and export?

    I have a color copy and B&W copy of 800 images. I want to export the B&W versions only. How do I select just the B&W versions in the stack at one time without having to click on 800 images?

  • How do you change print quality for eprinting?

    HP Photosmart 5515 OS installed XP The driver does not give this option. I like to do Fast Draft sometimes.

  • Can not login to console from N1

    Hi Guys: I installed N1 in an x4200. In the same local network, there is a T2000 which can be discovered by N1. When clicking "open serial console", I can only login console in read-only mode. You know, when I connect the T2000 ALOM from a terminal,

  • SharedObject

    I did so: AS3::ui::flash::net::SharedObject so = AS3::ui::flash::net::SharedObject::getLocal("someLSO"); TypeError: Error #1006: value is not a function. and inline_as3(           "import com.adobe.flascc.CModule;\n"           "import flash.net.Share

  • Forgot password didn`t recognise my email

    I `ve installed new windows. I didn`t remember my skype password. I tried "forgot password" and entered my email. My email wasn`t recognised. After trying a few times i registered a new account with the same email. I then searched by email and my old