Prashant,

You cannot initialize the context within the servlet. Use web.xml with the
following entries with your values:

<context-param>
<!-- The context-param element contains the declaration of a web
application's servlet context initialization parameters. There are two
special kinds of initialization parameters for the optional cases where the
parameter is used to obtain the JNDI name of an EJB or a data source for a
subsequent look up. These are indicated by an context-param element together
with an accompanying ejb-ref or resource-ref element with matching name.
-->
 
    <param-name>theName</param-name>
    <!-- The name of the configuration parameter. -->
 
    <param-value>theValue</param-value>
    <!-- The value of the configuration parameter. -->
 
</context-param> 

<resource-ref>
<!-- The optional resource-ref element contains a declaration of a Web
Application's reference to an external resource. An context-param with the
same name must be present whose value will be the JNDI data source. The
context-param's value may be specified at deployment time. -->
 
    <description>The description</description>
    <!-- A short description, use etc. -->
 
    <res-ref-name>theContextParam</res-ref-name>
    <!-- Specifies the name of the resource factory reference name. This
value is the name of the context-param whose value contains the JNDI name of
the data source. -->
 
    <res-type>com.the.TypeOfResource</res-type>
    <!-- Specifies the (Java class) type of the data source. -->
 
    <res-auth>CONTAINER|SERVLET</res-auth>
    <!-- The res-auth element indicates whether the application component
code performs resource signon programmatically or whether the container
signs onto the resource based on the principle mapping information supplied
by the deployer. Must be CONTAINER or SERVLET. -->
 
</resource-ref>
 
<ejb-ref>
<!-- Used in conjunction with a matching context-param of the same name to
indicate that this parameter will be used to obtain the JNDI name of an EJB.
-->
 
    <description>The description</description>
    <!-- A short description, use etc. -->
 
    <ejb-ref-name>nameOfEJB</ejb-ref-name>
    <!-- Contains the name of an EJB reference. This name must match an
context-param name. -->
 
    <ejb-ref-type>com.type.OfEJBBean</ejb-ref-type>
    <!-- Contains the expected java class type of the referenced EJB. -->
 
    <home>com.type.OfEJBHome</home>
    <!-- Contains the fully qualified name of the EJB's home interface. -->
 
    <remote>com.type.OfEJB</remote>
    <!-- Contains the fully qualified name of the EJB's remote interface.
-->
 
    <ejb-link>nameOfEJB</ejb-link>
    <!-- Used in the ejb-ref element to specify that an EJB reference is
linked to an EJB in an encompassing J2EE application package. The value of
the ejb-link element must be the ejb-name of and EJB in the J2EE application
package. -->
 
</ejb-ref>

You now need to tell Orion where to find the ejb. You need to be sure that
the following entries are in your hello-application.xml:
 
<application>
   <!-- The application element is the root element of a J2EE application
deployment descriptor. -->
 
   <module>
      <!-- The module element represents a single J2EE module and contains
an ejb, java, or web element, which indicates the module type and contains a
path to the module file, and an optional alt-dd element, which specifies an
optional URI to the post-assembly version of the deployment descriptor. The
application deployment descriptor must have one module element for each J2EE
module in the application package. -->
 
      <ejb>pathToEJB.jar</ejb>
         <!-- The ejb element specifies the URI of a ejb-jar, relative to
the top level of the application package. -->
 
      <java>pathToClient.jar</java> <!-- if you have an application client
-->
         <!-- The java element specifies the URI of a java application
client module, relative to the top level of the application package. -->
 
   </module>
 
   <web>
      <!-- The web element contains the web-uri and context-root of a web
application module. -->
 
      <web-uri>pathTo.war</web-uri>
         <!-- The web-uri element specifies the URI of a web application
file, relative to the top level of the application package. -->
 
      <context-root>thedir/</context-root>
         <!-- The context-root element specifies the context root of a web
application. -->
 
   </web>
 
</application> 

The module and web tags tell Orion to link these items together as an
application.
 
Now in the server.xml, make sure that the following entries are there:
 
 <web-site path="./hello-web-site.xml" />
 <application name="hello" path="./hello-application.xml" />
 
 
See if this gets us any further.
 
 
Dave


-----Original Message-----
From: Prashant Gaikwad [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, September 11, 2001 6:27 AM
To: Orion-Interest
Subject: Calling EJB From a Servlet..


HI Friends,
            I'm having a serious problem in my code and am unable to
understand. I've deployed a simple Hello bean on the orion container and
want to access it from a servlet. I have the servlet in
D:\Oracle\iSuites\j2ee\home\default-web-app\WEB-INF\classes\trg\HelloServlet
. Following is the code in servlet

 try {

                        trace("In Try");
                        Hashtable h = new Hashtable();
        
h.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.evermind.server.rmi.
RMIInitialContextFactory");
                        h.put(javax.naming.Context.SECURITY_PRINCIPAL,
"ejb");
                        h.put(javax.naming.Context.SECURITY_CREDENTIALS,
"ejbadmin");
        
h.put(javax.naming.Context.PROVIDER_URL,"ormi://localhost/Hello");
                        trace("Before Init Contect ");
                        Context context = new InitialContext (h);
                        trace("after Initial context");
                            Object boundObject =
context.lookup("java:comp/env/ejb/HelloHome");
                             trace("At Trap");
                           helloHome = (HelloHome)
javax.rmi.PortableRemoteObject.narrow(boundObject,HelloHome.class);
                              }
                           catch (Throwable exception) {
                                        exception.printStackTrace();
        
                 //System.out.println("Look up exception :" +
exception.toString());
         //throw new ServletException(
         //   "Unable to get home interface: " + exception.toString());
      }


 When I run servlet from browser I get an exception when the Context is
getting crerated as  folloew             

D:\Oracle\iSuites\j2ee\home>java -jar orion.jar
Oracle9iAS (1.0.2.2) Containers for J2EE initialized
ConstructorBefore TryIn TryBefore Init Contect
java.lang.NullPointerException: d
omain was null
        at com.evermind.server.rmi.RMIServer.addNode(RMIServer.java:428)
        at
com.evermind.server.rmi.RMIServer.getConnection(RMIServer.java:497)
        at
com.evermind.server.rmi.RMIInitialContextFactory.getInitialContext(RM
IInitialContextFactory.java:150)
        at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
        at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
        at javax.naming.InitialContext.init(Unknown Source)
        at javax.naming.InitialContext.<init>(Unknown Source)
        at trg.HelloServlet.init(HelloServlet.java:49)
        at
com.evermind.server.http.HttpApplication.loadServlet(HttpApplication.
java:1580)
        at
com.evermind.server.http.HttpApplication.findServlet(HttpApplication.
java:3722)
        at
com.evermind.server.http.HttpApplication.getRequestDispatcher(HttpApp
lication.java:1995)
        at
com.evermind.server.http.HttpRequestHandler.processRequest(HttpReques
tHandler.java:444)
        at
com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.ja
va:189)
        at com.evermind.util.ThreadPoolThread.run(ThreadPoolThread.java:62)
In _hello




Please let me know where I'm going wrong. 
Thanks in advance
Prashant








Reply via email to