4 Replies Latest reply on Jul 1, 2008 3:02 AM by sankarguru

    java.lang.ClassCastException: javax.naming.Reference while a

    atulksh

      Hi,
      I am fresh to webservices under jboss. I have jboss4.0.4 with ejb3 and jdk 1.5 setup. I have downloaded the jboss web services 1.0.4 package and deployed it to the jboss instance. I then compiled the samples and was successful at it. I wanted to run the rpcstyle-client example (jaxrpc endpoint) and access the webservice using a standalone java client. I deployed the generated

      jaxrpc-samples-rpcstyle.war
      jaxrpc-samples-rpcstyle-client.jar

      and wrote a simple client as follows -

      import javax.naming.*;

      import java.util.*;

      import javax.xml.rpc.*;
      import javax.rmi.*;

      import org.jboss.test.ws.jaxrpc.samples.rpcstyle.TrivialService;

      public class TestWSClient {

      public void testTrivialAccess() throws Exception
      {
      InitialContext iniCtx = getInitialContext();
      Service service = (Service)iniCtx.lookup("java:comp/env/service/TrivialService");
      TrivialService port = (TrivialService)service.getPort(TrivialService.class);
      String person = "Kermit";
      String product = "Ferrari";
      String status = port.purchase(person, product);
      System.out.println("Status: " + status);
      }

      protected InitialContext getInitialContext() throws NamingException
      {
      Properties env = new Properties();
      env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      env.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming.client:org.jboss.naming");
      env.setProperty(Context.PROVIDER_URL, "jnp://localhost:1099");
      env.setProperty("j2ee.clientName", "jbossws-client");
      Properties p = System.getProperties();
      p.put("com.sun.xml.namespace.QName.useCompatibleSerialVersionUID", "1.0");
      System.setProperties(p);
      return new InitialContext(env);
      }

      public static void main(String[] args) {
      try {
      TestWSClient wsClient = new TestWSClient();
      wsClient.testTrivialAccess();
      } catch (Exception e) {
      e.printStackTrace();
      }
      }

      }

      But on running the code I got the following exception

      java.lang.ClassCastException: javax.naming.Reference

      When I looked at the object returned by JNDI lookup it is of type

      org.jboss.ws.jaxrpc.ServiceReferenceable

      According to the documentation -

      http://labs.jboss.com/portal/jbossws/user-guide/en/html/clients.html

      this should work and return a Service refrence. What am I doing wrong? Your help is greatly appreciated.

      Thank you.

        • 1. Re: java.lang.ClassCastException: javax.naming.Reference whi
          atulksh

          Hi,
          I have still not figured the problem. I tried to run all jboss-ws 1.0.4 samples which use a standard java client (JSE client) and use jndi to access a web-service deployed on the server - the samples are -

          samples/jaxrpc/rpcstyle

          samples/jaxrpc/jsr109pojo

          Both give the same exact response

          [junit] javax.naming.NamingException: Could not dereference object [Root exception is java.lang.ClassCastException: org.jboss.webservice.metadata.serviceref.ServiceRefMetaData]
          [junit] at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure
          (NamingContext.java:1150)
          [junit] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:70
          5)
          [junit] at org.jboss.naming.client.java.javaURLContextFactory$EncContextProxy.invoke(javaURLContextFactory.java135)
          [junit] at $Proxy1.lookup(Unknown Source)
          [junit] at javax.naming.InitialContext.lookup(InitialContext.java:351)
          [junit] at org.jboss.test.ws.jaxrpc.samples.rpcstyle.TrivialServiceRpcTestCase.setUp(TrivialServiceRpcTestCase.java:64)
          [junit] at junit.framework.TestCase.runBare(TestCase.java:125)

          Can anybody help please? Thanks a lot!

          • 2. Re: java.lang.ClassCastException: javax.naming.Reference whi
            atulksh

            Finally found my answer. This is a simple classpath issue. The jse client that I am running needs the following classes in it's classpath (including the jar which contains the service interface on whom methods are to be called)

            jbossall-client.jar
            jbossws14-client.jar
            activation.jar
            xml-apis.jar
            xercesImpl.jar
            mail.jar
            jboss-backport-concurrent.jar
            jbossretro-rt.jar

            It is frustrating that it gives such a vague exception providing no clue as to what might be the issue. I got the clue from ExpertsExchange

            http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21317023.html?qid=21317023

            Thank you folks.

            • 3. Re: java.lang.ClassCastException: javax.naming.Reference whi
              sankarguru

              i have same problem can you pls explain what's problem behind this?
              i put all the JNDI properties and set sessioncontext also
              still i am getting same error?
              is there problem in Jar file?
              i have included- Jboss-client-all.jar,activation-jar also

              can anybody explain what is the problem and solution

              • 4. Re: java.lang.ClassCastException: javax.naming.Reference whi
                sankarguru

                Topic:
                java.lang.ClassCastException

                i have same problem can you pls explain what's problem behind this?
                i put all the JNDI properties and set sessioncontext also
                still i am getting same error?
                is there problem in Jar file?
                i have included- Jboss-client-all.jar,activation-jar also

                can anybody explain what is the problem and solution