3 Replies Latest reply on Oct 29, 2013 9:09 AM by sfcoy

    ClassNotFoundException - different behaviour on JBoss 7.1

    akash_bansal

      Hi,

       

      I have two classes one is OutData and the other is ExtendedData as given below:

       

      OutData.java:

       

      public class OutData implements Serializable {

              public OutData(String internetAddress, String hostName) {

              this.internetAddress = internetAddress;

              this.hostName = hostName;

          }

       

          private String internetAddress;

          private String hostName;

       

          public String getInternetAddress() {

              return internetAddress;

          }

       

          public void setInternetAddress(String internetAddress) {

              this.internetAddress = internetAddress;

          }

       

          public String getHostName() {

              return hostName;

          }

       

          public void setHostName(String hostName) {

              this.hostName = hostName;

          }

      }

       

      ExtendedData.java:

       

      public class ExtendedData extends OutData implements Serializable {

          public ExtendedData(String internetAddress, String hostName,

                  String testProperty) {

              super(internetAddress, hostName);

              this.testProperty = testProperty;

          }

       

          private String testProperty;

       

          public String getTestProperty() {

              return testProperty;

          }

       

          public void setTestProperty(String testProperty) {

              this.testProperty = testProperty;

          }

      }

       

      One of my sessionbean has following source code:

       

      public interface RemoteCalculator {

          OutData responseFrom();

      }

       

      public class CalculatorBean implements RemoteCalculator {

          @Override

          public OutData responseFrom() {

              String ipAddress = null;

              OutData outData = null;

              try {

                  InetAddress ip = InetAddress.getLocalHost();

                  ipAddress = ip.getHostAddress();

                  String nodeName = System.getProperty("jboss.node.name");

                  System.out.println("Response from " + ipAddress + " NodeName: " + nodeName);

                  ExtendedData extendedData = new ExtendedData(ipAddress, nodeName, "Test Property");

                  outData = (OutData)extendedData;

              } catch (UnknownHostException e) {

                  e.printStackTrace();

              }

              return outData;

          }

       

      I have deployed all these four classes on JBoss 7.1.3 server.

       

      My EJB Client has only TWO classes - RemoteCalculator.class and OutData.class. When I call responseFrom() method of above session bean from JBoss, it throws ClassNotFoundException : ExtendedData.

      When I deploy same EJB on Weblogic 10.3 server, it works fine. It does not throw ClassNotFoundException : ExtendedData even though my ejb client does not have class definition of ExtendedData.

       

      I am attaching the source code of my session bean along with OutData and ExtendedData for ready reference.

       

      I would request to JBoss SMEs about the different behaviour of the same.

       

      Regards,

      Akash

        • 1. Re: ClassNotFoundException - different behaviour on JBoss 7.1
          sfcoy

          akash bansal wrote:

           

          ...

           

          When I deploy same EJB on Weblogic 10.3 server, it works fine. It does not throw ClassNotFoundException : ExtendedData even though my ejb client does not have class definition of ExtendedData.

           

          ...

          Regards,

          Akash

           

          I'm sorry, but I don't believe you. This is not possible using normal RMI.

           

          This cast that you're using:

          outData = (OutData)extendedData;
          

          does not change the type of object that is returned to the client. It is no different to this:

          outData = extendedData;
          

           

          Please provide a complete working example (including the WebLogic example).

           

          Additionally, please use a portable compression format. RAR files are a nuisance if you don't use Windows.

          • 2. Re: Re: ClassNotFoundException - different behaviour on JBoss 7.1
            akash_bansal

            Hi Stephen,

             

            I am attaching the working example.  You can deploy the ejb-test-deserialization-WL-1.0-SNAPSHOT.jar on Weblogic 10.3 server. To access this EJB, you would need to compile MyEJBUtil.java class packed into WeblogicClient.zip file. EJBs can also be compiled by compiling java files packed in EJB.zip.


            Regards,

            Akash

            • 3. Re: ClassNotFoundException - different behaviour on JBoss 7.1
              sfcoy

              Your example is using the proprietary WebLogic "t3" protocol, which means that your code is not portable.


              One of the features of the t3 protocol is "network class loading". Your example is working because the server is sending the client an ExtendedData.class file.