7 Replies Latest reply on Jun 19, 2010 2:04 PM by zurchman

    Casting to StubExr leads to ClassCastException

    gressho

      Hello,

      I'm trying to add WS-Security to my web services which are running fine
      without. I generated the client code with Netbeans 6.1 and built the
      following class to use it. I added all jars from wsrunclient to the classpath
      of my project and tried to run it. The result was


      java.lang.ClassCastException: $Proxy31 cannot be cast to org.jboss.ws.core.StubExt
      at javaapplication1.Main.main(Main.java:33)


      My code:
      /*
       * To change this template, choose Tools | Templates
       * and open the template in the editor.
       */
      
      package javaapplication1;
      
      import de.wwu.services.mailservice.Charset;
      import de.wwu.services.mailservice.Recipient;
      import de.wwu.services.mailservice.RecipientType;
      import java.io.File;
      import java.net.URL;
      import org.jboss.ws.core.StubExt;
      
      /**
       *
       * @author gressho
       */
      public class Main {
      
       /**
       * @param args the command line arguments
       */
       public static void main(String[] args) {
      
       try { // Call Web Service Operation
       de.wwu.services.mailservice.NotificationService service = new de.wwu.services.mailservice.NotificationService();
       de.wwu.services.mailservice.NotificationEndpoint port = service.getNotificationEndpointPort();
       URL securityURL = new File("META-INF/jboss-wsse-client.xml").toURI().toURL();
       URL securityConfig= new File("META-INF/standard-jaxws-client-config.xml").toURI().toURL();
       ((StubExt)port).setSecurityConfig(securityConfig.toExternalForm());
       ((StubExt)port).setConfigName("Standard WSSecurity Client");
       // TODO initialize WS operation arguments here
       de.wwu.services.mailservice.Message message = new de.wwu.services.mailservice.Message();
       message.setCharset(Charset.UTF_8);
       Recipient firstRecipient = new Recipient();
       firstRecipient.setRecipientType(RecipientType.TO);
       firstRecipient.setRecipientAddress("gressho@uni-muenster.de");
       message.getRecipients().add(firstRecipient);
       message.setSender("gressho@uni-muenster.de");
       message.setSubject("Clustertest");
       message.setContent("Diese Mail ist ein Test... Also gleich wegschmeißen!");
       port.NotifyRecipients(message);
       } catch (Exception ex) {
       ex.printStackTrace();
       // TODO handle custom exceptions here
       }
      
       // TODO code application logic here
       }
      
      }
      


      Every help is appreciated

      Werner


        • 1. Re: Casting to StubExr leads to ClassCastException
          gressho

          Hello,

          I've just observed that Netbeans generated JAX-WS 2.1 compliant client classes. In
          the news paper sample it was JAX-WS 2.0. Is that a problem? The classes look
          very similar to me.

          Best wishes

          Werner

          • 2. Re: Casting to StubExr leads to ClassCastException
            peterj

            I think you should use wsconsume to generate the client stubs, and then use those stubs. It will make your client much simpler - it will not need any of the security-related code you posted.

            See http://www.jboss.com/index.html?module=bb&op=viewtopic&t=127824 for a complete example.

            • 3. Re: Casting to StubExr leads to ClassCastException
              gressho

              Thanks,

              using the JBoss classes instead of JAX-WS 2.1 from Netbeans resolved the problem.

              • 4. Re: Casting to StubExr leads to ClassCastException
                jplistero

                I have the same problem.

                 

                How I uses jboss clases ?

                My project use JRE: jdk 1.6.0_13 ...  and reference to jbossall-client.jar , jbossws-native-core.

                 

                someone can help ? thanks.

                 

                here is the client webservice code.

                 

                 

                try {
                Service service = new Service();
                Port port =  service.getPort();
                ((StubExt) port).setConfigName("Standard WSSecurity Client");
                 
                port.doSomething("gogo");
                }catch (Exception e){
                e.printStackTrace();
                }
                • 5. Re: Casting to StubExr leads to ClassCastException
                  jim.ma

                  Hi juan ,  Can you give us more information about your problem ? Do you run this test in NetBeans too ?  Using jboss generated classes does not help ?

                  • 6. Re: Casting to StubExr leads to ClassCastException
                    jplistero

                    sorry for the time ...

                    I resolved, the key was in the class path, I referenced to jars that are referenced in the wsrunclient.sh ... 

                    (some for jboss-5.1.GA/client and jboss -5.1.GA/lib/endorsed)

                     

                    now I have another problem ... :-(

                     

                    I have a client.jar, that have the code I post it before ... (The client works perfect with a JUnit)

                    This client.jar is reference by a .war project ...

                     

                    When I deploy the war in jboss 4.0.5, when try to do "new Service()" the program freeze, and dont throw  any exception ...

                     

                    I try too, to deploy at jboss 5.1.0 and I have the exception ...

                    java.lang.ClassCastException: $Proxy344 cannot be cast to org.jboss.ws.core.StubExt

                     

                    I think is a reference problem ... I try a lot of combination ...

                    but I dont known how to resolved ...

                     

                    any ideas ?

                     

                    thanks!

                    • 7. Re: Casting to StubExr leads to ClassCastException
                      zurchman

                      The last error looks like another Classpath problem.

                       

                      You need to stick with one JBoss distribution.  All three that you mentioned should work the same, but the jars and the contents of the endorsed directory may be different.  If you have something that works with 5.1.GA, stick with that.

                       

                      Whenever you start a client without using wsrunclient from the command line you introduce the risk of getting the Classpath wrong.  Unfortunately, in many cases, especially when dealing with WS-Security, the problem turns out to be us or our code.