how to look up a class in weblogic

Discussions

EJB design: how to look up a class in weblogic

  1. how to look up a class in weblogic (4 messages)

    hi all!

      i have create a class in ejb and i want to give a jndi name for that class,and i want to access from the client.can any one let me know how to do this.

    with regards

    praveen

    Threaded Messages (4)

  2. Home Interface[ Go to top ]

    You must have created an home interface so attach that interface using JNDI to Weblogic server. Please look into manual of weblogic , how to deploy an EJB. You can get it at e-docs.bea.com
  3. Of course, the jndi-name is what you have defined in the deployment descriptor.


    Context ctx = getInitialContext();

        try {
          Object home = (ExampleHome) ctx.lookup("jndi-name");
          return (ExampleHome) PortableRemoteObject.narrow(home, ExampleHome.class);

        } catch (NamingException ne) {
          log("The client was unable to lookup the EJBHome. Please make sure " +
            "that you have deployed the ejb with the JNDI name " +
            "jndi-name on the WebLogic server at "+url);
          throw ne;
        }
  4. how to look up a class in weblogic[ Go to top ]

    hi all!

    >
    >   i have create a class in ejb and i want to give a jndi name for that class,and i want to access from the client.can any one let me know how to do this.

    Get a decent book on EJB. Usually I recommend Ed Roman's:

    Mastering EJB

    Or just get it for free, thanks to TSS:

    http://www.theserverside.com/books/masteringEJB/index.jsp?tmc

    HTH

    Slava
  5. please reference weblogic jndi example[ Go to top ]

    ctx = new InitialContext(env);
            System.out.println("Initial context created");

            try {
              ctx.createSubcontext("example");
              System.out.println("Subcontext 'example' created");
            }
            catch (NameAlreadyBoundException e) {
              // Subcontext already exists.
              // Note that WebLogic's Context implementation does not throw this
              // exception if the name is already bound to an identical object.
              System.out.println(
                "Subcontext 'example' already exists;"
                + " continuing with existing subcontext"
              );
            }

            String bindStr;
            String bindName = "example.one";

            // Create a unique String object (bindStr) and bind it to (bindName)
            DateFormat df = DateFormat.getDateTimeInstance(DateFormat.DEFAULT,
                                                           DateFormat.DEFAULT,
                                                           Locale.getDefault());
            bindStr = "Example String created at "+df.format(new Date());
            try {
              ctx.bind(bindName, bindStr);
              System.out.println("Bound '" + bindStr + "' to '"+bindName+"' for the first time.");
            }
            catch (NameAlreadyBoundException e) {
              // Binding already exists.
              // As for the createSubcontext() method, this exception is not thown
              // by the WebLogic implementation of Context when the name is aleady
              // bound to an identical object. However, we have created a unique
              // string by including the date and time here. Run the example more than
              // once in the same WL sever session and the exception will be thrown.
              System.out.println("Overriding old binding. Rebinding '" +
                                 bindStr +"' to '"+bindName+"'.");
              // Force a new binding
              ctx.rebind(bindName, bindStr);
            }

            if (((String)ctx.lookup(bindName)).equals(bindStr)) {
              System.out.println("Example finished successfully.");
            }
            else {
              System.out.println("Example failed.");
            }
          }
          catch (NamingException e) {
            System.out.println(e.toString());
          }