HI Paolo,

For invoking an EJB in an Orion server from a servlet/Jsp in a different
Orion instance you don't need at all to code nothing (jndi properties) in
your servlet/JSP. 

Simply: 

1)You have to add your ejb server in rmi.xml of the invoker Orion.
An example:
<server host="yourEJBHost" username="admin" password="123" />

2)Then you have to add the remote and home interfaces of you EJBs in the
classpath of the web app and say to Orion to use remote EJBs modifying the
ejb-module tag in orion-application.xml:
An example:
<ejb-module remote="true" path="yourmodule-ejb" /> 

Hope this help

Luciano  

-----Original Message-----
From: Paolo Ramasso [mailto:[EMAIL PROTECTED]]
Sent: giovedì 6 settembre 2001 18.10
To: Orion-Interest
Subject: Re: How to call A EJB in OC4j from other Servers


ciao
i used to access a remote ejb from a servlet.

put the home and remote in the -cp java option
> java -cp .....\orion.jar;.....yourhomeremote
com.evermind.server.ApplicationServer

code like this.


the servlet:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.net.*;
import javax.naming.*;
import javax.rmi.*;


public class MyServlet extends HttpServlet
{
  private static final String CONTENT_TYPE = "text/html";
  public void init(ServletConfig config) throws ServletException
  {
    super.init(config);
  }
  public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
  {
  Context context = null;
    Hashtable env = new Hashtable();
    response.setContentType(CONTENT_TYPE);
    PrintWriter out = response.getWriter();

   //env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.evermind.server.rmi.RMIInitialContextFactory");
   env.put(Context.SECURITY_PRINCIPAL, "admin");
   env.put(Context.SECURITY_CREDENTIALS, "paolo");
   env.put("java.naming.provider.url", "ormi://localhost:23791/ejb2");

   //env.put(Context.PROVIDER_URL, "ormi://localhost:23791/ejb1");
   env.put("java.naming.factory.initial",
"com.evermind.server.rmi.RMIInitialContextFactory");

   env.put("dedicated.connection" ,"true");

    try
    {
    out.println("EJBCellerServlet before context");
      context = new InitialContext (env);
      //context = new InitialContext ();
      out.println("EJBCallerServlet after context");
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }

 try {

  out.println("EJBCellerServlet before lookup");
    // MySessionEJBHome home =
(MySessionEJBHome)context.lookup("MySessionEJB");
        Object objref = context.lookup("MySessionEJB1");
        // Object objref =
context.lookup("java:comp/env/ejb/MySessionEJB1Home");
  out.println("EJBCellerServlet after lookup");



 out.println("EJBCellerServlet before cast");
   MySessionEJB1Home home =
(MySessionEJB1Home)PortableRemoteObject.narrow(objref,
                                              MySessionEJB1Home.class);


  out.println("EJBCellerServlet after cast");
    MySessionEJB1 hello = home.create();


      } catch (Exception e) {
        e.printStackTrace(out);
      }

    //response.setContentType(CONTENT_TYPE);
    //PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head><title>CallerServlet</title></head>");
    out.println("<body>");
    out.println("<p>The servlet has received a GET. This is the
reply.</p>");
    out.println("</body></html>");
    out.close();
  }
}


and the web.xml file:

<?xml version = '1.0' encoding = 'UTF-8'?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application
2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd";>
<web-app>
   <description>Empty web.xml file for Web Application</description>
   <servlet>
      <servlet-name>myservlet</servlet-name>
      <servlet-class>MyServlet</servlet-class>
   </servlet>
   <servlet-mapping>
      <servlet-name>myservlet</servlet-name>
      <url-pattern>/myservlet</url-pattern>
   </servlet-mapping>
   <session-config>
      <session-timeout>30</session-timeout>
   </session-config>
   <mime-mapping>
      <extension>html</extension>
      <mime-type>text/html</mime-type>
   </mime-mapping>
   <mime-mapping>
      <extension>txt</extension>
      <mime-type>text/plain</mime-type>
   </mime-mapping>
   <welcome-file-list>
      <welcome-file>index.jsp</welcome-file>
      <welcome-file>index.html</welcome-file>
   </welcome-file-list>
   <ejb-ref>
      <description>test 3</description>
      <ejb-ref-name>MySessionEJB1</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      <home>MySessionEJB1Home</home>
      <remote>MySessionEJB1</remote>
   </ejb-ref>
</web-app>

hope this helps
ciao
Paolo


Venkata_Nallam wrote:

> Dear All,
>         I would like to know, how to invoke a EJB bean in OC4J from
another
> machine.
> What are the steps I have to follow.
>
> It would appreciated if any one help in this regard.
>
> Thanking you
>
> With regards
> Venkata

Reply via email to