How to lookup a Bean?

i have successfully deployed an EJB by using J2EE deploytool.
my source code to lookup the Bean as following:
Context ctx = new InitialContext(System.getProperties());
java.lang.Object objref = ctx.lookup("skey");
home = (SessionKeyHome)PortableRemoteObject.narrow(objref, com.ibm.sessionkey.SessionKeyHome.class);
i have read serval books and articles,there are different codes for lookuping a bean.Why?and when should we use this or that?
But i get the error msg:
Warning: unable to read transaction.interoperability config property
java.io.FileNotFoundException: /export/home/ass/config/security.properties
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:103)
at com.sun.enterprise.util.Utility.getPropertiesFromFile(Utility.java:42)
at com.sun.enterprise.iiop.security.SecurityMechanismSelector.<clinit>(SecurityMechanismSelector.java:102)
at com.sun.enterprise.iiop.IIOPSSLSocketFactory.getEndPointInfo(IIOPSSLSocketFactory.java:211)
at com.sun.corba.ee.internal.iiop.ConnectionTable.getConnection(ConnectionTable.java:73)
at com.sun.corba.ee.internal.iiop.ConnectionTable.getConnection(ConnectionTable.java:68)
at com.sun.corba.ee.internal.iiop.GIOPImpl.getConnection(GIOPImpl.java:70)
at com.sun.corba.ee.internal.corba.InitialNamingClient.locateObject(InitialNamingClient.java:769)
at com.sun.corba.ee.internal.corba.InitialNamingClient.getIORUsingHostInfo(InitialNamingClient.java:597)
at com.sun.corba.ee.internal.corba.InitialNamingClient.resolveCorbaloc(InitialNamingClient.java:573)
at com.sun.corba.ee.internal.corba.InitialNamingClient.resolveUsingORBInitRef(InitialNamingClient.java:544)
at com.sun.corba.ee.internal.corba.InitialNamingClient.cachedInitialReferences(InitialNamingClient.java:1080)
at com.sun.corba.ee.internal.corba.InitialNamingClient.resolve_initial_references(InitialNamingClient.java:981)
at com.sun.corba.ee.internal.corba.ORB.resolve_initial_references(ORB.java:2425)
at com.sun.enterprise.naming.SerialContext.getProvider(SerialContext.java:52)
at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:120)
at javax.naming.InitialContext.lookup(InitialContext.java:347).java:23)
javax.naming.CommunicationException: Can't find SerialContextProvider
at com.sun.enterprise.naming.SerialContext.getProvider(SerialContext.java:63)
at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:120)
at javax.naming.InitialContext.lookup(InitialContext.java:347)

Hi,
There r two ways to lookup. One is that u specify the provider while running the client. E.g:
java -D java.naming.factory.initial=weblogic.jndi.WLInitialContextFactory
-Djava.naming.provider.url=t3://localhost:7001
or alternatively u can specify these two properties in the Properties object of your client. e.g:
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
props.put(Context.PROVIDER_URL,"t3://localhost:7001");
Context ctx = null;
Object obj = null;
try
ctx = new InitialContext(props);               
obj = ctx.lookup("HelloJNDI");
Which method to use is matter of convenience.
Values of provider url & initialContext will change depending on the app server u r using.
I hope this will help u.

Similar Messages

  • How to lookup a bean from a standalone app.

    I've got the following question..
    I've created a stateless sessionbean and deployed it in the J2EE Server 1.3.1. (That one you get from Sun when you download the J2EE SDK) I've created a client for my bean, and when i execute it with the 'runclient -client my.ear -name myclientclass' command, it works just fine.
    But, i now want to run it as a standalone application, without the 'runclient' command. I am able to create an initialcontext (without any properties), but my bean can not be found in 'java:comp/env/ejb/bean' (the same name i use with the 'runclient' command, so the bean should be there). My guess is that i should add some initial context properties, but which ones? All the examples i can find are with ldap context factories. Can anyone give me any advice on how to connect to the J2EE server and lookup my bean?
    Thanks in advance.
    Nick

    Hi,
    You could write something as below
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
    env.put(Context.PROVIDER_URL, "jnp:localhost:1099");
    env.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
    try {
    Context ctx = new InitialContext(env);
    Session_LocalHome session_lh = (Session_LocalHome) ctx.lookup("Session_Home");
    Session_ session_ = session_lh.create();
    OR
    Use a jndi.properties file which would have the same entries as above, please search over internet and find out what to include in it.
    One more thing to note is, in above example i said
    env.put(Context.PROVIDER_URL, "jnp:localhost:1099");
    meaning the lookup is on port 1099, this is not same for all the servers. Check your server documentation and find out " What is the port number on which your server listens ? "
    Regards
    Meka Toka

  • How to lookup EJB3 beans using JNDI names without defining ejb-ref in DD?

    Hi Kenneth,
    I am just continuing the topic:
    How Lookup SLSB from other SLSB? <HELP>
    http://forum.java.sun.com/thread.jspa?threadID=5117484&tstart=0
    (my original forums account failed, so I am using new one)
    if I am not seeking portability I should be able to lookup a bean directly through JNDI without using the ejb-ref. (I just want to see how it can be done)
    http://forum.java.sun.com/thread.jspa?forumID=13&threadID=751907
    http://www.theserverside.com/discussions/thread.tss?thread_id=16402
    I am using SJSAS PE 9.0 I am failing to lookup my beans from other beans directly without ejb-ref.
    Is there some sample code to look at?
    Thanks!

    Global JNDI names are vendor-specific and not known until deployment time. That is one
    of the main reasons the Java EE component environment model defines a level of
    indirection for accessing component dependencies. It is best to use either an ejb-ref
    or @EJB annotation when accessing EJBs from a Java EE component.
    If you choose not to, you just have to make sure the global JNDI name you use matches
    the one assigned to the target EJB. We have a lot of information on how this works
    in our EJB FAQ.
    https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html
    If you're still encountering an error, please provide more specifics about your application,
    the code you're using for the lookup, and the error message you're receiving. Just
    saying "my looking fails" doesn't help us diagnose the problem :-)
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • LOOKUP OF beans between two jar files

    How to lookup beans between two jar file
    I have two jar files named as ejb1.jar , ejb2.jar .
    both the <ejb-name> are same..
    InitialContext ctx = new InitialContext();
    Object te = ctx.lookup("test");
    if i want to lookup for 2nd jar (ejb2.jar)which has the same <ejb-name> how to do..
    helpp !!!!!!!
    prakash

    Hi,
    No it would not be possible to differentiate the data just by using the dump files. You need to import these dump files in the database and then you can compare it for any difference.
    Regards
    Anurag

  • Lookup (2 Beans on diffrent applications)

    Hi
    Programs: J-Developer902, Oracle9i AS
    The Proplem : I have 2 beans on 2 different .ear applications, one bean on each .ear .
    I'm trying to do Lookup from Bean 1 on the first application, to Bean 2
    on the second application, without any success!!! What am I doing wrong?
    The intialcontext I'm using is com.evermind.server.rmi.RMIInitialContextFactory
    wich is the one to use when having 2 different applications (.EAR), which is my case.
    Deployment : Bean 1 : myFirst.deploy, myFirst.jar, myFirst.ear
    Bean 2 : mySecond.deploy, mySecond.jar, mySecond.ear
    Here is how my Lookup looks like in my code.
    _________ Clinet doing Lookup on Bean 1 ___________(It works without any problem)
    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, "admin");
    env.put(Context.PROVIDER_URL, "ormi://IS002/myFirst");
    Context ctx = new InitialContext(env);
    MyFirstEJBHome myFirstEJBHome = (MyFirstEJBHome)ctx.lookup("MyFirstEJB");
    MyFirstEJB myFirstEJB;
    __________ Bean 1 doning Lookup on Bean 2 _______________
    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, "admin");
    env.put(Context.PROVIDER_URL, "ormi://IS002/mySecond");
    Context ctx = new InitialContext(env);
    Object boundObject = ctx.lookup("MySecondEJB");
    MySecondEJBHome mySecondEJBHome =
    (MySecondEJBHome) PortableRemoteObject.narrow( boundObject, MySecondEJBHome.class);
    ________ ERROR _________
    java.lang.ClassCastException
    at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(Unknown Source)
    at javax.rmi.PortableRemoteObject.narrow(Unknown Source)
    at mypackage1.MyFirstEJBBean.callSecond(MyFirstEJBBean.java:47)
    at MyFirstEJB_StatelessSessionBeanWrapper10.callSecond
    (MyFirstEJB_StatelessSessionBeanWrapper10.java:79)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.evermind.server.rmi.RMICallHandler.run(RMICallHandler.java:118)
    at com.evermind.util.ThreadPoolThread.run(ThreadPoolThread.java:64)
    What am I doing wrong??? Why can't my first Bean find the second Bean ?
    I'll be thankful if somebody could help me!!
    /Azam Roomi
    Integration Strategies & Solutions

    Azam,
    You are hitting a classloader problem. I suggest you upgrade to
    the latest JDeveloper version (9.0.3 -- available for download
    from Oracle's "Technet" website). Then read the following:
    http://otn.oracle.com/products/ias/tech_tips/oc4jTech_tip_0218.html
    http://otn.oracle.com/docs/products/ias/doc_library/903doc_otn/generic.903/a97677/advanced.htm#1004903
    http://kb.atlassian.com/content/atlassian/howto/classloaders.jsp
    http://kb.atlassian.com/content/orion/docs/remote-access/remote-access.html
    http://www2.theserverside.com/resources/article.jsp?l=AdvancedClassLoading
    http://www2.theserverside.com/resources/article.jsp?l=ClassLoading
    (Of-course, I'm assuming you haven't already read the above.)
    Hope this helps you.
    Good Luck,
    Avi.

  • How do you create beans using NetBeans 5.5?

    I am referring to http://java.sun.com/docs/books/tutorial/javabeans/nb/index.html and I'm sorry but I can't follow any of this!
    I have NetBeans IDE 5.5 and I am trying to learn how to write beans using NetBeans, and the lessons involve things I can't find or understand, for example:
    re: http://java.sun.com/docs/books/tutorial/javabeans/writingbean/index.html
    <blockquote>
    Load the JAR file. Use the NetBeans IDE GUI Builder to load the jar file as follows:
    1. Start NetBeans.
    2. From the File menu select "New Project" to create a new application for your bean. You can use "Open Project" to add your bean to an existing application.
    3. Create a new application using the New Project Wizard.
    4. Select a newly created project in the List of Projects, expand the Source Packages node, and select the Default Package element.
    5. Click the right mouse button and select New|JFrameForm from the pop-up menu.
    6. Select the newly created Form node in the Project Tree. A blank form opens in the GUI Builder view of an Editor tab.
    7. Open the Palette Manager for Swing/AWT components by selecting Palette Manager in the Tools menu.
    8. In the Palette Manager window select the beans components in the Palette tree and press the "Add from JAR" button.
    9. Specify a location for your SimpleBean JAR file and follow the Add from JAR Wizard instructions.
    10. Select the Palette and Properties options from the Windows menu.
    11. Expand the beans group in the Palette window. The SimpleBean object appears. Drag the SimpleBean object to the GUI Builder panel.
    </blockquote>
    Sorry, you lost me literally after "Start NetBeans", the rest is Hungarian. I can't find "New Project Wizard"; I can't find "List of Projects", I can't find anything they are talking about nor do I know if any of this is relevant toward my learning how to write beans.
    Re: http://java.sun.com/docs/books/tutorial/javabeans/properties/properties.html
    "Inspecting Properties" seems impossible to do because the Inspector Window only shows a closed folder and nothing else ever. I can't figure out this part of the tutorial either.
    Can someone please explain this 3rd-grade-level to me: How to create a bean using NetBeans?
    Thanx
    Phil

    Phil,
    Before you embark on another very frustrating advanture using NetBeans, please go t hrough the NetBeans tutorial. The "New Project Wizard" is just select from the menu options -- "New Project". The "Hungarian" as you put it will not get better until you spend some time learning NetBeans. Learning something new, like beans, is frustrating enough, but to try to do it and use a tool that is not familiar may be beyond many individuals frustration level.
    Les

  • How to call a bean method from javascript event

    Hi,
    I could not find material on how to call a bean method from javascript, any help would be appreciated.
    Ralph

    Hi,
    Basically, I would like to call a method that I have written in the page java bean, or in the session bean, or application bean, or an external bean, from the javascript events (mouseover, on click, etc...) of a ui jsf component. I.e., I would like to take an action when a user clicks in a column in a datatable.
    Cheers,
    Ralph

  • How to debug a bean in JSP page with JBX???

    How to debug a bean in JSP page with JBX???
    i have a bean within a JSP page. i wanna find out how do they varibles work and changes of them values.
    are there some ways or tools to get the situations of them in visual way? just like when i debug VB program,i can get the situations in immediately window.

    help me !!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • How to call the bean in jspdyn component?

    Hi,
    i created  jspdyn component in that bean and bussiness logic class in NWDS.i created a method() in that businesslogic class.i called that method in bean class.i created both in same package,there is no error occur while creating the object of that class.but the bean class not recognize the business class method which i created. What is the cause? and also tell me how to call the bean in jsppage also.and also give me textfields,button and syntax of event handling in HTMLB,iam new to this area.so,give me one example step by step.

    Hi,
         Please check on these links for a good start.
    Java development methodologies (Part II)
    Bean usage in JSPDynPage
    jspDynPage portalapp.xml
    Regards,
    Harini S
    Please avoid giving personal mail id(s). That may prevent others from getting the same information when needed.

  • How to use Java Beans In JSTL?

    Hi
    I want to know how to use Java bean in JSTL
    please explain this with giving any one example.
    Thanks-
    Swapneel

    A bean is obtain by <jsp:useBean> tag nd once bean is obtained we can get its property by using getProperty tag.

  • Prob in IR :Internal error during bean lookup for bean RepObjectAccessBean

    Hi,
        I am facing the problem in IR .
    <b>Internal error during bean lookup for bean RepObjectAccessBean</b>
    is the Error window I am getting frequently, After getting this error, It is no allowing to open any of the IR Objects.
    Thanks in advance,
    Dhanabal T

    Hi Dhanabal,
    i got the same error. But it is clear.
    Please chek once ur configuration part. The error is in configuration part only.
    once check all the steps in ur configuration part.
    REgards,
    chandra.

  • How to Serialize/Deserialize Beans with Web Services using DII client

    Dear All;
    I had developed a web serivce by Oracle JDeveloper [J2EE 1.4 (JAX-RPC)] and trying to invoke methods within through DII client using Apache Axis 1.
    The Beans I am using are structured as follows:
    public class InBean {
    public InBean() {
    private int x;
    private float y;
    public setters/getters for x
    public setters/getters for y
    public class OutBean {
    public OutBean() {
    private String inString;
    private String outString;
    public setters/getters for inString
    public setters/getters for outString
    The (InBean) is used as method input and the (OutBean) is used as method output.
    The problems I am facing are as follows:
    [1] How to serialize/desrialize the Beans as they are not registered with Apache Axis 1?
    [2] How to invoke the Beans using Dynamic client DII and not classic proxy and Stubs?
    [3] How to create the Beans using WSD2Java of the Apache Axis 1 ?
    In case you have any helping URL's, Book names or sample code, please attach as they will be very helpful.
    Thanks alot for the help.-----
    Best Regards,
    Ahmed M. Abbas

    You will find some working code at :
    http://ksoap.objectweb.org/software/downloads/index.html
    It's code that use kSOAP and kXML implementations ....
    If you will also find some useful information here :
    http://developers.sun.com/techtopics/mobility/apis/articles/wsa/
    http://www-106.ibm.com/developerworks/wireless/library/wi-jsr/
    http://www-106.ibm.com/developerworks/wireless/library/wi-xmlparse/
    Regards.

  • Cannot lookup the bean in JBoss

    I had a entity bean called AddressBean and bind the JNDI name as ejb/entity/AddressBean, but I cannot lookup this bean. The NameNotFoundException is thrown, the exception message is "ejb not bound". Did anyone know what happen with it?
    Hashtable props = new Hashtable();
    props.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
    props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099");
    InitialContext initialContext = new InitialContext(props);
    Object obj = initialContext.lookup("ejb/entity/AddressBean");But I can lookup this bean by using the default JNDI name "AddressBean".

    I've been trying to make a lookup from a remote client.
    I've tried this code
    props.put(InitialContext.PROVIDER_URL, "jnp://10.10.10.10:1099");
    I get the error unknown protocol
    Ofcourse 10.10.10.10 was not the acutal ip address of the machine on which JBoss was running. While running the code i did have the correct ip address.
    Then I tired the approach discussed here
    http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=63&t=000150
    Now i get a "no protocol" error.
    I have included the jboss-client.jar and the jnp-client.jar in the classpath of the client.
    Can someone help me out with this?

  • Can't lookup session bean in MBean and ApplicationLifeCyleListener

    Hi,
    i am migrating an application with mbean from OC4J to weblogic 10.3.2.
    as my application don't have a web module. i try to use the ApplicationLifeCycleListener
    to register the mbean (instruction from this oracle document page:
    http://download.oracle.com/docs/cd/E12839_01/web.1111/e13729
    /instmbeans.htm#i1099957).
    i register the mbean in the ApplicationLifeCycleListener.postStart method, but in the
    mbean's method (which is called by a javax.management.timer.Timer, created in the
    MBeanRegistration.postRegister method), i can't lookup the session bean.
    (i try to lookup the session bean in the ApplicationLifeCycleListener.postStart method, it fails too)
    if i register the mbean in a ServletContextListener, there is NO problem that i can
    lookup session bean in the mbean's method.
    why there is inconsistence in registrating mbean by servlet context listerer and by
    applicationlifecyclelistener???
    can anybody tell me the solution???
    is it impossible to call session bean in the MBean's method if the mbean is registered
    in the ApplicationLifeCycleListener ???
    *** i want to call a session bean's method periodically through the timer ***
    thank you very much.

    gimbal2 wrote:
    r035198x wrote:
    I put the interfaces in a separate XX-si-jar file always.
    The implementation jar then depends on that service interface jar which gets deployed on both the client and the server.
    This way I can distribute my si without including implementation which I can change without needing to affect the clients.Yeah, that seems like the only real solution to me. Using Maven it shouldn't be that hard to manage either now that I think about it. Did you ever get into trouble with a client being based on an outdated interface jar? I can imagine that it can be a bit of a release management drama to keep these things synced.Interface changes when they did happen resulted in full redeployments because the client usually has to change anyway to use the changed functionality. Most interactions are through static interfaces so this doesn't arise too much.
    In volatile interactions, a common approach is to define a generic interface EJB whose implementation can delegate the calls to other (potentially future) services. The problem with this is that return types have to be simple.
    >
    It's one of the reasons why I'm not a fan of optional interfaces in 3.1.Well the optional part is optional ;) To me it is a very useful addition since I usually only deal with local interfaces when I use EJB technology. I always found it a bit of a bother to HAVE to create an interface also, I welcome the change.It is handy to be able to roll out an app with a few classes all bundled in one deployment file if there is no requirement for multiple implementations of an interface or for remote invocation support.
    I just feel that it's a lot of flexibility to sacrifice when doing the interfaces is not really a lot of effort with today's development tools.

  • [Seeking help] How to create a bean with annotations @ runtime?

    I would like 2 create a bean, @ runtime, as below:
    public class A {
      @MyAnnotation(id = "ID")
      private String id = "";
      public String getId() { ... }
      public void setId(String id) { ... }
    }Can anyone tell me how 2 achieve this? I know how 2 create a bean dynamically, however with annotations it is a bit tricky ..
    Cheers!
    Edited by: olove66 on Aug 7, 2009 2:00 AM

    @_@ I guess anyone interested in this topic can turn 2 ASM. Maybe BCEL has not got anything 2 support annotation creation yet.

Maybe you are looking for