5 Replies Latest reply on Sep 10, 2005 1:01 PM by amna sipra

    Downloading classes from JBoss server

    Kalyan Newbie

      Though a crosspost, I thought that this is the appropriate forum. Please see below:

      Hi,

      I am running a client that accesses a bean that is deployed on a JBoss 3.2.5 server. I get a ClassNotFoundException for the bean home class while looking it up using JNDI. I have looked at the previous posts on the same issue, and we have installed the RMISecurityManager on the client and have given the client AllPermissions using policy file. But still the Home interface is not getting downloaded.

      Let us know if I am missing something else in order to enable auto download of classes from the Server.

      Here is the stack trace:

      javax.naming.CommunicationException [Root exception is java.lang.ClassNotFoundException: loadtest.server.ServerHome]
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:654)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:509)
       at javax.naming.InitialContext.lookup(Unknown Source)
       at loadtest.client.AbstractClient.run(AbstractClient.java:43)
       at loadtest.client.JNPClient.run(JNPClient.java:29)
       at loadtest.client.LoadTestClient.<init>(LoadTestClient.java:39)
       at loadtest.client.LoadTestClient.main(LoadTestClient.java:101)
      Caused by: java.lang.ClassNotFoundException: loadtest.server.ServerHome
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at java.lang.ClassLoader.loadClassInternal(Unknown Source)
       at java.lang.Class.forName0(Native Method)
       at java.lang.Class.forName(Unknown Source)
       at sun.rmi.server.LoaderHandler.loadProxyInterfaces(Unknown Source)
       at sun.rmi.server.LoaderHandler.loadProxyClass(Unknown Source)
       at sun.rmi.server.LoaderHandler.loadProxyClass(Unknown Source)
       at java.rmi.server.RMIClassLoader$2.loadProxyClass(Unknown Source)
       at java.rmi.server.RMIClassLoader.loadProxyClass(Unknown Source)
       at sun.rmi.server.MarshalInputStream.resolveProxyClass(Unknown Source)
       at java.io.ObjectInputStream.readProxyDesc(Unknown Source)
       at java.io.ObjectInputStream.readClassDesc(Unknown Source)
       at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
       at java.io.ObjectInputStream.readObject0(Unknown Source)
       at java.io.ObjectInputStream.readObject(Unknown Source)
       at java.rmi.MarshalledObject.get(Unknown Source)
       at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:30)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:552)

      Thanks,
      Kalyan.

        • 1. Re: Downloading classes from JBoss server
          Kalyan Newbie

          I wrote a simple test bean, and even that doesn't work: For those curious, below is the code:

          (Please note that the client is running on Windows and the server is on a solaris machine)

          Client:

          package test.ejb.client;
          
          import java.lang.reflect.Method;
          import java.util.Properties;
          
          import javax.naming.Context;
          import javax.naming.InitialContext;
          import javax.rmi.PortableRemoteObject;
          
          import test.ejb.server.Server;
          import test.ejb.server.ServerHome;
          
          public class EJBClient
          {
           private final String SERVER_URL = "jnp://solarismachine:6500";
          
           public EJBClient() throws Exception
           {
           Properties p = System.getProperties();
           p.put(Context.PROVIDER_URL,SERVER_URL);
           p.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
           Context context = new InitialContext(p);
          
           Object obj = context.lookup("ejbtest.Server");
           ServerHome home = (ServerHome)PortableRemoteObject.narrow(obj,ServerHome.class);
           Server server = home.create();
           System.out.println("Information: "+server.getInformation());
           }
          
           public static void main(String[] args)
           {
           try
           {
           new EJBClient();
           }
           catch (Exception e)
           {
           e.printStackTrace();
           }
           }
          }


          Remote Interface:

          package test.ejb.server;
          
          import java.rmi.RemoteException;
          
          import javax.ejb.EJBObject;
          
          public interface Server extends EJBObject
          {
           public String getInformation() throws RemoteException;
          }


          Home Interface:

          package test.ejb.server;
          
          import java.rmi.RemoteException;
          
          import javax.ejb.CreateException;
          import javax.ejb.EJBHome;
          
          public interface ServerHome extends EJBHome
          {
           public Server create() throws RemoteException, CreateException;
          }


          Bean Implementation:

          package test.ejb.server;
          
          import java.rmi.RemoteException;
          
          import javax.ejb.EJBException;
          import javax.ejb.SessionBean;
          import javax.ejb.SessionContext;
          
          public class ServerBean implements SessionBean
          {
           private SessionContext myCtx = null;
          
          
           public void ejbCreate()
           {
           System.out.println("Creating ejb.....");
           }
          
           public String getInformation()
           {
           return "SUCCESS";
           }
          
           public void ejbActivate() throws EJBException, RemoteException
           {
           }
          
           public void ejbPassivate() throws EJBException, RemoteException
           {
           }
          
           public void ejbRemove() throws EJBException, RemoteException
           {
           }
          
           public void setSessionContext(SessionContext ctx) throws EJBException, RemoteException
           {
           System.out.println("Setting session context"+ctx);
           myCtx = ctx;
           }
          }


          EJB-Jar XML:

          <?xml version="1.0"?>
          <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN' 'http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd'>
          <ejb-jar>
           <enterprise-beans>
           <session>
           <ejb-name>ejbtest.Server</ejb-name>
           <home>test.ejb.server.ServerHome</home>
           <remote>test.ejb.server.Server</remote>
           <ejb-class>test.ejb.server.ServerBean</ejb-class>
           <session-type>Stateless</session-type>
           <transaction-type>Container</transaction-type>
           </session>
           </enterprise-beans>
          </ejb-jar>


          The client run.bat file:

          java -cp C:\jboss-3.2.5\client\jbossall-client.jar;.\ejbtestclient.jar;-Djava.security.manager=java.rmi.RMISecurityManager -Djava.security.policy=all.policy test.ejb.client.EJBClient


          Following is the exception:

          javax.naming.CommunicationException [Root exception is java.lang.ClassNotFoundException: test.ejb.server.ServerHome]
           at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:654)
           at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:509)
           at javax.naming.InitialContext.lookup(Unknown Source)
           at test.ejb.client.EJBClient.<init>(EJBClient.java:34)
           at test.ejb.client.EJBClient.main(EJBClient.java:55)
          Caused by: java.lang.ClassNotFoundException: test.ejb.server.ServerHome
           at java.net.URLClassLoader$1.run(Unknown Source)
           at java.security.AccessController.doPrivileged(Native Method)
           at java.net.URLClassLoader.findClass(Unknown Source)
           at java.lang.ClassLoader.loadClass(Unknown Source)
           at java.lang.ClassLoader.loadClass(Unknown Source)
           at java.lang.ClassLoader.loadClassInternal(Unknown Source)
           at java.lang.Class.forName0(Native Method)
           at java.lang.Class.forName(Unknown Source)
           at sun.rmi.server.LoaderHandler.loadProxyInterfaces(Unknown Source)
           at sun.rmi.server.LoaderHandler.loadProxyClass(Unknown Source)
           at sun.rmi.server.LoaderHandler.loadProxyClass(Unknown Source)
           at java.rmi.server.RMIClassLoader$2.loadProxyClass(Unknown Source)
           at java.rmi.server.RMIClassLoader.loadProxyClass(Unknown Source)
           at sun.rmi.server.MarshalInputStream.resolveProxyClass(Unknown Source)
           at java.io.ObjectInputStream.readProxyDesc(Unknown Source)
           at java.io.ObjectInputStream.readClassDesc(Unknown Source)
           at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
           at java.io.ObjectInputStream.readObject0(Unknown Source)
           at java.io.ObjectInputStream.readObject(Unknown Source)
           at java.rmi.MarshalledObject.get(Unknown Source)
           at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:30)
           at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:552)
           ... 4 more


          • 2. Re: Downloading classes from JBoss server
            Kalyan Newbie

            No one has ever got this problem? Are there any places where I can check if my configuration is correct or not?

            Thanks,
            Kalyan.

            • 3. Re: Downloading classes from JBoss server
              Scott Stark Master

              Turn on rmi debugging on the client to see what the rmi codebase is seen as. The jdk javadocs have a section on the rmi properties and debug levels.

              • 4. Re: Downloading classes from JBoss server
                Kalyan Newbie

                Thanks Scott,

                I had missed a property on the server side for Dynamic Classloading. The DownloadServerClasses property of jboss:service=Webservice MBean was set to false. I changed it to true and now I see that the classes are being downloaded from the server (I had put some log statements in the Webserver.java class), but client still gets the following exception:

                Exception in thread "main" java.lang.NoClassDefFoundError: test.ejb.server.ServerHome


                at the code:

                ServerHome home = (ServerHome)PortableRemoteObject.narrow(obj,ServerHome.class);
                


                The client appears to be downloading the classes SeverHome.class and Server.class when I do the lookup (at the following code):

                Object obj = context.lookup("ejbtest.Server");


                After that I get NoClassDefFoundError for ServerHome class

                Please let me know if I am doing something wrong.

                Thanks,
                Kalyan.




                • 5. Re: Downloading classes from JBoss server
                  amna sipra Newbie

                  when i try to run an ejb application the following error occurs!!!
                  Can u help me out of it

                  The following stack trace is displayed

                  java.lang.NoClassDefFoundError: javax/ejb/EJBHome
                  at java.lang.ClassLoader.findBootstrapClass(Native Method)
                  at java.lang.ClassLoader.findBootstrapClass0(ClassLoader.java:727)
                  at java.lang.ClassLoader.loadClass(ClassLoader.java:284)
                  at java.lang.ClassLoader.loadClass(ClassLoader.java:282)
                  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
                  at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
                  at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
                  at java.lang.Class.forName0(Native Method)
                  at java.lang.Class.forName(Class.java:219)
                  at sun.rmi.server.LoaderHandler.loadProxyInterfaces(LoaderHandler.java:707)
                  at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:622)
                  at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:517)
                  at java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.java:639)
                  at java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:309)
                  at sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStream.java:241)
                  at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1469)
                  at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1432)
                  at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1626)
                  at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
                  at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
                  at java.rmi.MarshalledObject.get(MarshalledObject.java:135)
                  at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:353)
                  at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:333)
                  at javax.naming.InitialContext.lookup(InitialContext.java:347)
                  at An.displaySearchResult(An.java:93)
                  at An.displayPage(An.java:64)
                  at An.doPost(An.java:26)
                  at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
                  at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
                  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
                  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
                  at filters.ExampleFilter.doFilter(ExampleFilter.java:149)
                  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)
                  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
                  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
                  at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
                  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
                  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
                  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                  at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
                  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
                  at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
                  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
                  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
                  at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
                  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
                  at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
                  at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
                  at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
                  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
                  at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
                  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
                  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
                  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
                  at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
                  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
                  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
                  at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
                  at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:594)
                  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
                  at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
                  at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
                  at java.lang.Thread.run(Thread.java:534)


                  The code listing is here

                  For Remote interface

                  package tassie;

                  import javax.ejb.EJBObject;
                  import java.rmi.RemoteException;
                  import java.util.ArrayList;

                  public interface Search extends EJBObject {
                  public ArrayList search(String keyword) throws RemoteException;
                  }


                  for home interface


                  package tassie;

                  import java.rmi.RemoteException;
                  import javax.ejb.CreateException;
                  import javax.ejb.EJBHome;

                  public interface SearchHome extends EJBHome {
                  Search create() throws RemoteException, CreateException;
                  }


                  For bean class

                  package tassie;

                  import java.rmi.RemoteException;
                  import javax.ejb.SessionBean;
                  import javax.ejb.SessionContext;
                  import java.sql.*;
                  import java.util.ArrayList;

                  public class SearchBean implements SessionBean {


                  private Connection getConnection() {
                  Connection connection = null;
                  try {
                  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                  connection = DriverManager.getConnection("jdbc:odbc:TassieDB");
                  }
                  catch (Exception e) {
                  }
                  return connection;
                  }

                  public ArrayList search(String keyword) {
                  ArrayList retval = new ArrayList(50);
                  try {
                  Statement statement = getConnection().createStatement();
                  String sql = "SELECT Id, Title, Author, Publisher" +
                  " FROM Books" +
                  " WHERE Title LIKE '%" + keyword + "%'";

                  ResultSet rs = statement.executeQuery(sql);
                  while (rs.next()) {
                  String[] row = new String[4];
                  row[0] = rs.getString("Id");
                  row[1] = rs.getString("Title");
                  row[2] = rs.getString("Author");
                  row[3] = rs.getString("Publisher");
                  retval.add(row);
                  }
                  rs.close();
                  statement.close();
                  }
                  catch (Exception e) {
                  }
                  return retval;
                  }

                  public void ejbCreate() {
                  }

                  public void ejbRemove() {
                  }

                  public void ejbActivate() {
                  }

                  public void ejbPassivate() {
                  }

                  public void setSessionContext(SessionContext sc) {
                  }
                  }

                  n the client servlet is here

                  //package com.brainysoftware.tassie.servlet;

                  import javax.servlet.*;
                  import javax.ejb.*;
                  import javax.servlet.http.*;
                  import java.io.*;
                  import java.util.*;
                  import javax.naming.*;
                  import javax.rmi.PortableRemoteObject;
                  import tassie.Search;
                  import tassie.SearchHome;

                  public class An extends HttpServlet {

                  private String keyword;

                  /**Process the HTTP Get request*/
                  public void doGet(HttpServletRequest request, HttpServletResponse response)
                  throws ServletException, IOException {
                  displayPage(request, response);
                  }

                  /**Process the HTTP Post request*/
                  public void doPost(HttpServletRequest request, HttpServletResponse response)
                  throws ServletException, IOException {
                  keyword = request.getParameter("keyword");
                  displayPage(request, response);
                  }

                  private void displayPage(HttpServletRequest request, HttpServletResponse response)
                  throws ServletException, IOException {
                  /* In addition to the header and footer,
                  There are 4parts in this page:
                  1. The Welcome Title
                  2. Search form
                  3. The search result table
                  4. The link to the Check Shopping Cart page
                  */
                  response.setContentType("text/html");
                  PrintWriter out = response.getWriter();

                  // header
                  out.println("");
                  out.println("");
                  out.println("Welcome to Tassie Online Bookstore");
                  out.println("");
                  out.println("");
                  out.println("");

                  // Welcome Title
                  out.println("<H2>Welcome To Tassie Online Bookstore</H2>");

                  // Search form
                  out.println("");
                  out.println("<FORM METHOD=POST>");
                  out.println("Title: <INPUT TYPE=TEXT NAME=keyword>");
                  out.println("<INPUT TYPE=SUBMIT VALUE=Search");
                  out.println("");
                  out.println("");

                  // Search result
                  out.println("");
                  out.println("<H3>Search Result</H3>");
                  out.println("");
                  displaySearchResult(out);
                  out.println("");

                  // Link to the Check Shopping Cart link
                  out.println("");
                  out.println("<A HREF=Hello>Check Shopping Cart");

                  // footer
                  out.println("");
                  out.println("");
                  out.println("");

                  // Displaying the Search form

                  }

                  /**Clean up resources*/
                  private void displaySearchResult(PrintWriter out) {
                  if (keyword!=null && !keyword.trim().equals("")) {
                  // keyword okay, display the result here.

                  Properties properties = new Properties();
                  properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                  properties.put(Context.PROVIDER_URL, "localhost:1099");
                  try {
                  // Get a naming context
                  InitialContext jndiContext = new InitialContext(properties);
                  System.out.println("got context");
                  // Get a reference to the Bean
                  Object ref = jndiContext.lookup("Search");
                  System.out.println("got reference");
                  // Get a reference from this to the Bean's Home interface
                  SearchHome home = (SearchHome)
                  PortableRemoteObject.narrow (ref, SearchHome.class);

                  // Create an Adder object from the Home interface
                  Search searchBean = home.create();
                  ArrayList arrayList = searchBean.search(keyword);
                  int rowCount = arrayList.size();
                  out.println("<TABLE BORDER=1>");
                  out.println("");
                  out.println("<TH WIDTH=350>Title");
                  out.println("<TH WIDTH=150>Author");
                  out.println("<TH WIDTH=150>Publisher");
                  out.println("<TH WIDTH=50> ");
                  out.println("");

                  for (int i=0; i<rowCount; i++) {
                  String[] s = (String[]) arrayList.get(i);
                  out.println("");
                  out.println("" + s[1] + "");
                  out.println("" + s[2] + "");
                  out.println("" + s[3] + "");
                  out.println("<A HREF=com.brainysoftware.tassie.servlet.BookDetailsServlet?bookId=" +
                  s[0] + ">Details");
                  out.println("");
                  }
                  out.println("");

                  }
                  catch(Exception e) {
                  System.out.println(e.toString());
                  }

                  }
                  }
                  }