0 Replies Latest reply on Mar 13, 2006 4:42 AM by capaccino

    java.lang.ClassCastException: $Proxy82

    capaccino

      I create a hello session bean.
      in ejb-jar.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd" version="2.1">
      <display-name>EJBModwww</display-name>
      <enterprise-beans>

      <ejb-name>TestHello</ejb-name>
      wwww.TestHelloHome
      wwww.TestHello
      <ejb-class>wwww.TestHelloBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>

      </enterprise-beans>
      <assembly-descriptor>
      <container-transaction>

      <ejb-name>TestHello</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      </assembly-descriptor>
      </ejb-jar>

      jboss.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 4.0//EN" "http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd">


      <enterprise-beans>

      <ejb-name>TestHello</ejb-name>
      <jndi-name>TestHello</jndi-name>

      </enterprise-beans>


      web.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
      <display-name>www</display-name>

      <servlet-name>servlet1</servlet-name>
      <servlet-class>wwww.Servlet1</servlet-class>

      <servlet-mapping>
      <servlet-name>servlet1</servlet-name>
      <url-pattern>/servlet1</url-pattern>
      </servlet-mapping>
      <ejb-ref>
      <ejb-ref-name>ejb/TestHello</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      wwww.TestHelloHome
      wwww.TestHello
      </ejb-ref>
      </web-app>

      jboss-web.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 2.4//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_4_0.dtd">

      <jboss-web>
      <context-root>www</context-root>
      <ejb-ref>
      <ejb-ref-name>ejb/TestHello</ejb-ref-name>
      <jndi-name>TestHello</jndi-name>
      </ejb-ref>
      </jboss-web>

      the Servlet1.java source
      package wwww;

      import javax.servlet.*;
      import javax.servlet.http.*;
      import java.io.*;
      import java.util.*;
      import javax.naming.*;

      public class Servlet1 extends HttpServlet {
      private static final String CONTENT_TYPE = "text/html; charset=GBK";
      public void doGet(HttpServletRequest request, HttpServletResponse response) throws
      ServletException, IOException {
      response.setContentType(CONTENT_TYPE);
      PrintWriter out = response.getWriter();
      try {
      InitialContext ic = new InitialContext();
      //String name="TestHello";//jndi name
      String name = "java:comp/env/ejb/TestHello";
      Object obj = ic.lookup(name);
      TestHelloHome home=(TestHelloHome)obj;
      out.print(obj.getClass());
      } catch (Exception ex) {
      ex.printStackTrace();
      }
      out.close();
      }
      public void destroy() {
      }
      }

      When I run the Servelt1
      http://127.0.0.1:8080/www/servlet1
      There is a Exception:
      java.lang.ClassCastException: $Proxy82


      But there is no exception in the Application. The source:
      package wwww;

      import javax.naming.*;
      import java.lang.String;
      import javax.naming.InitialContext;
      import java.util.Hashtable;

      public class TestHelloTestClient1 {
      private Context getInitialContext() throws NamingException {
      Hashtable environment = new Hashtable();

      environment.put(Context.INITIAL_CONTEXT_FACTORY,
      "org.jnp.interfaces.NamingContextFactory");
      environment.put(Context.URL_PKG_PREFIXES,
      "org.jboss.naming:org.jnp.interfaces");
      environment.put(Context.PROVIDER_URL, "jnp://localhost:1099");

      return new InitialContext(environment);
      }
      //Main method
      public static void main(String[] args) {
      TestHelloTestClient1 client = new TestHelloTestClient1();
      try {
      Context context = client.getInitialContext();
      //look up jndi name
      Object obj = context.lookup("TestHello");
      //look up jndi name and cast to Home interface
      TestHelloHome home = (TestHelloHome)obj;
      System.out.println(home.create().hello("hello"));
      } catch (Exception ex) {
      ex.printStackTrace();
      }
      }
      }

      Who can tell me?
      Thanks.