10 Replies Latest reply on Jul 5, 2007 11:00 AM by andrea.le

    Writing WS client returning complex object

    andrea.le

      Hi this is my problem, i hope someone help me...

      i'm trying to deploy a simple web service that returns a complex Object.

      The class that I want to return is:

      package esempio;
      
      public class TestClass {
       private String name;
       public TestClass() {
       }
      
       public String getName() {
       return name;
       }
       public void setName(String name) {
       System.out.println("settato il nome: "+name);
       this.name = name;
       }
      }
      


      and this is the service class I wrote:

      package esempio;
      
      import javax.ejb.Stateless;
      import javax.jws.WebMethod;
      import javax.jws.WebParam;
      import javax.jws.WebResult;
      import javax.jws.WebService;
      import javax.jws.soap.SOAPBinding;
      
      @WebService(targetNamespace="urn:testws")
      @SOAPBinding(style= SOAPBinding.Style.DOCUMENT)
      @Stateless(name="provaServizio")
      public class ProvaServizioImpl {
       @WebMethod
       @WebResult(name="testClassResult")
       public TestClass getTestClass(
       @WebParam(name = "nome") String name) {
       TestClass ritorno = new TestClass();
       ritorno.setName(name);
       return ritorno;
       }
      }
      

      I packaged this two classe in a jar that I named "ws2.jar" and copied this jar in jboss 4.05GA server/default/deploy folder.

      The service seems deployed, because if put the address "localhost:8080/ws2/provaServizio?wsdl" on a browser it returns this WSDL:

      <definitions name="ProvaServizioImplService" targetNamespace="urn:testws">
       <types>
       <schema elementFormDefault="qualified" targetNamespace="http://esempio/jaws">
      <import namespace="urn:testws"/>
       <complexType name="TestClass">
       <sequence>
      <element name="name" nillable="true" type="string"/>
      </sequence>
      </complexType>
      </schema>
       <schema elementFormDefault="qualified" targetNamespace="urn:testws">
      <import namespace="http://esempio/jaws"/>
       <complexType name="getTestClass">
       <sequence>
      <element name="nome" nillable="true" type="string"/>
      </sequence>
      </complexType>
       <complexType name="getTestClassResponse">
       <sequence>
      <element name="testClassResult" nillable="true" type="ns2:TestClass"/>
      </sequence>
      </complexType>
      <element name="getTestClass" type="tns:getTestClass"/>
      <element name="getTestClassResponse" type="tns:getTestClassResponse"/>
      </schema>
      </types>
       <message name="ProvaServizioImpl_getTestClass">
      <part element="tns:getTestClass" name="parameters"/>
      </message>
       <message name="ProvaServizioImpl_getTestClassResponse">
      <part element="tns:getTestClassResponse" name="result"/>
      </message>
       <portType name="ProvaServizioImpl">
       <operation name="getTestClass">
      <input message="tns:ProvaServizioImpl_getTestClass"/>
      <output message="tns:ProvaServizioImpl_getTestClassResponse"/>
      </operation>
      </portType>
       <binding name="ProvaServizioImplBinding" type="tns:ProvaServizioImpl">
      <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
       <operation name="getTestClass">
      <soap:operation soapAction=""/>
       <input>
      <soap:body use="literal"/>
      </input>
       <output>
      <soap:body use="literal"/>
      </output>
      </operation>
      </binding>
       <service name="ProvaServizioImplService">
       <port binding="tns:ProvaServizioImplBinding" name="ProvaServizioImplPort">
      <soap:address location="http://sviluppo-012:8080/ws2/provaServizio"/>
      </port>
      </service>
      </definitions>
      


      So I think the service is working.

      Then I wrote this simple Client, including in its classpath the jar containing the TestClass file:

      import java.net.URL;
      
      import javax.naming.Context;
      import javax.xml.namespace.QName;
      import javax.xml.rpc.Service;
      import javax.xml.rpc.ServiceFactory;
      import esempio.ProvaServizioImpl;
      import esempio.TestClass;
      
      public class Client {
       public static void main(String[] args) throws Exception {
      
       System.out.println("Start");
      
       ServiceFactory factory= ServiceFactory.newInstance();
      
       Service factoryTest = factory.createService(new URL("http://localhost:8080/ws2/provaServizio?wsdl"),
       new QName("http://esempio/jaws", "ProvaServizioImplService"));
       ProvaServizioImpl proxyTest = (ProvaServizioImpl)factoryTest.getPort(ProvaServizioImpl.class);
      
       TestClass ritorno = (TestClass)proxyTest.getTestClass("test");
      
       System.out.println("ritorno del secondo servizio "+ritorno.getName());
       }
      }
      


      Running the Client it returns this error:
      "
      Exception in thread "main" org.jboss.ws.WSException: Cannot obtain java type mapping for: {urn:testws}getTestClass
      at org.jboss.ws.deployment.JSR109MetaDataBuilder.buildParameterMetaDataDoc(JSR109MetaDataBuilder.java:451)
      at org.jboss.ws.deployment.JSR109MetaDataBuilder.setupOperationsFromWSDL(JSR109MetaDataBuilder.java:200)
      at org.jboss.ws.deployment.JSR109ClientMetaDataBuilder.buildMetaDataInternal(JSR109ClientMetaDataBuilder.java:208)
      at org.jboss.ws.deployment.JSR109ClientMetaDataBuilder.buildMetaData(JSR109ClientMetaDataBuilder.java:126)
      at org.jboss.ws.deployment.JSR109ClientMetaDataBuilder.buildMetaData(JSR109ClientMetaDataBuilder.java:82)
      at org.jboss.ws.jaxrpc.ServiceImpl.(ServiceImpl.java:96)
      at org.jboss.ws.jaxrpc.ServiceFactoryImpl.createService(ServiceFactoryImpl.java:157)
      at org.jboss.ws.jaxrpc.ServiceFactoryImpl.createService(ServiceFactoryImpl.java:128)
      at Client.main(Client.java:19)
      "

      Now i know that there is error in mapping but i dont know if i wrong something in client or if i need some kind of configuration file(xml).

      I read thousands over thousands of examples about WS and clients, but I'm confused... using EJB3 i must generate some mapping file?
      In which way?
      I read examples that just return primitives types, but never complex Object types...

      Can u help me pls?