7 Replies Latest reply on Sep 1, 2005 2:08 PM by Scott Jones

    Looking for example code

    Scott Jones Newbie

      I am looking for example client code, standalone client code, that calls a soap services that requires the creation of a soap header.

      Todate I have generated the stubs from the WSDL and been able to use the code below to access the service. But I am missing the steps of being able to either manually add the soap headers or to have a client handler do it for me. This is all from a java client outside any containers.

      
      HelloWorld_Impl service = new HelloWorld_Impl();
       HelloWorldEndpoint endPoint = service.getHelloWorldEndpointPort();
      
       Stub stub = (Stub) endPoint;
      
       stub._setProperty(Stub.USERNAME_PROPERTY, "scott");
       stub._setProperty(Stub.PASSWORD_PROPERTY, "password");
       stub._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:7070/helloworld/1.0");
      
      
      
       try {
       String output = endPoint.hello("Scott");
      
       } catch (RemoteException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
       super.fail("exception caught in test case");
       }
      
       }
      
      


      I tried added a client handler but nothing seams to execute it. I assume you have to be in a container for this methodology to work
      
      HelloWorld_Impl service = new HelloWorld_Impl();
       HelloWorldEndpoint endPoint = service.getHelloWorldEndpointPort();
      
       Stub stub = (Stub) endPoint;
      
       stub._setProperty(Stub.USERNAME_PROPERTY, "scott");
       stub._setProperty(Stub.PASSWORD_PROPERTY, "password");
       stub._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:7070/helloworld/1.0");
      
       HandlerRegistry hr = service.getHandlerRegistry();
      
      
       QName portName = new QName(MyFirstClientHandler.NAMESPACE_URI, MyFirstClientHandler.LOCAL_PART);
      
       List handlerChain = hr.getHandlerChain(portName);
      
       HandlerInfo hi = new HandlerInfo();
       hi.setHandlerClass(MyFirstClientHandler.class);
       handlerChain.add(hi);
      
       try {
       String output = endPoint.hello("Scott");
      
       } catch (RemoteException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
       super.fail("exception caught in test case");
       }
      
      
       }
      


        • 1. Re: Looking for example code
          Scott Jones Newbie

          Any help out there

          • 2. Re: Looking for example code
            Thomas Diesler Master


            tdiesler@satellite /cygdrive/d/projects/jboss-branch/jboss-4.0.x/testsuite
            $ ant -Dtest=org.jboss.test.webservice.handlerflow.HandlerFlowTestCase one-test
            
            one-test:
             [junit] Running org.jboss.test.webservice.handlerflow.HandlerFlowTestCase
             [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 1.512 sec
            


            • 3. Re: Looking for example code
              Scott Jones Newbie

              OK I am lost:

              The example you pointed me to is calling an EJB.

              I have a test client that was built from the wsdl of an ejb under 4.0.2 with wscompile.

              I can talk to the ejb via soap xml and the wsdl with no problem. I can not find any way to add a soap header to the classes already generate from wscompile.

              So I need an example of a j2se client that calls a webserice with a soap header.

              I have been able to attach a handler to the server side, but my client is not running under a container.

              Thanks for any help you can give.

              • 4. Re: Looking for example code
                Thomas Diesler Master

                With J2EE-1.4 compliant WS clients, you add the handler to the service-ref element, like this

                 <enterprise-beans>
                 <session>
                 <ejb-name>HelloEjb</ejb-name>
                 <home>org.jboss.test.webservice.handlerflow.HelloHome</home>
                 <remote>org.jboss.test.webservice.handlerflow.HelloRemote</remote>
                 <ejb-class>org.jboss.test.webservice.handlerflow.HelloBean</ejb-class>
                 <session-type>Stateless</session-type>
                 <transaction-type>Container</transaction-type>
                 <service-ref>
                 <service-ref-name>service/HelloService</service-ref-name>
                 <service-interface>javax.xml.rpc.Service</service-interface>
                 <wsdl-file>META-INF/wsdl/HelloService.wsdl</wsdl-file>
                 <jaxrpc-mapping-file>META-INF/jaxrpc-mapping.xml</jaxrpc-mapping-file>
                 <handler>
                 <handler-name>ClientHandler1</handler-name>
                 <handler-class>org.jboss.test.webservice.handlerflow.ClientHandler1</handler-class>
                 <soap-header>impl:HelloHeader</soap-header>
                 </handler>
                 <handler>
                 <handler-name>ClientHandler2</handler-name>
                 <handler-class>org.jboss.test.webservice.handlerflow.ClientHandler2</handler-class>
                 <soap-header>impl:HelloHeader</soap-header>
                 </handler>
                 </service-ref>
                 </session>
                 </enterprise-beans>
                


                There is no portable API that allows you to do that in WS4EE. Access to HandlerRegistry is not allowed.

                • 5. Re: Looking for example code
                  Thomas Diesler Master

                  In case you don't know how to do this for a standalone java client, have a look at application-client.xml.

                  • 6. Re: Looking for example code
                    zhang xu Newbie

                    acxsjones, i met the same question you've met.
                    in a standalone client, i wrote

                    String namespaceURI = "..";
                    List<HandlerInfo> list = new ArrayList<HandlerInfo>();
                     HandlerInfo hi = new HandlerInfo();
                     hi.setHandlerClass(MyClientHandler.class);
                     list.add(hi);
                    
                     service.getHandlerRegistry().setHandlerChain(
                     new QName(namespaceURI, "WSEEDemoEndpointPort"),
                     list);
                    

                    it throws such exception, it seems should be work, but it throws such excpetion
                    java.lang.UnsupportedOperationException: Components should not use the getHandlerRegistry() method
                    

                    can anybody help me?

                    • 7. Re: Looking for example code
                      Scott Jones Newbie

                      This is a site that I found a good "client" example that use wscompile to get the client handler in chain.

                      http://java.sun.com/webservices/docs/1.3/tutorial/doc/JAXRPC7.html