1 Reply Latest reply on Jun 21, 2007 2:09 AM by sdwfxsf

    how to use jboss web service

    sdwfxsf

      Hi,
      I meet a problem when I use JBoss web service.
      On client I use wsconsume to generate the java classes.

      The code is:
      ApplicationService.java
      package greenback.esb.test;import javax.jws.WebMethod;
      import javax.jws.WebParam;
      import javax.jws.WebResult;
      import javax.jws.WebService;
      import javax.jws.soap.SOAPBinding;

      @WebService(name = "ApplicationService", targetNamespace = "http://test.esb.greenback/")
      @SOAPBinding(style = SOAPBinding.Style.RPC)
      public interface ApplicationService {
      @WebMethod
      @WebResult(partName = "return")
      public String process(
      @WebParam(name = "arg0", partName = "arg0")
      Po arg0);

      }



      ApplicationServiceService.java

      package greenback.esb.test;

      import java.net.MalformedURLException;
      import java.net.URL;
      import javax.xml.namespace.QName;
      import javax.xml.ws.Service;
      import javax.xml.ws.WebEndpoint;
      import javax.xml.ws.WebServiceClient;

      @WebServiceClient(name = "ApplicationServiceService", targetNamespace = "http://test.esb.greenback/", wsdlLocation = "http://192.168.168.188:8080/application/applicationESB?wsdl")
      public class ApplicationServiceService
      extends Service
      {

      private final static URL APPLICATIONSERVICESERVICE_WSDL_LOCATION;

      static {
      URL url = null;
      try {
      url = new URL("http://192.168.168.188:8080/application/applicationESB?wsdl");
      } catch (MalformedURLException e) {
      e.printStackTrace();
      }
      APPLICATIONSERVICESERVICE_WSDL_LOCATION = url;
      }

      public ApplicationServiceService(URL wsdlLocation, QName serviceName) {
      super(wsdlLocation, serviceName);
      }

      public ApplicationServiceService() {
      super(APPLICATIONSERVICESERVICE_WSDL_LOCATION, new QName("http://test.esb.greenback/", "ApplicationServiceService"));
      }


      @WebEndpoint(name = "ApplicationServicePort")
      public ApplicationService getApplicationServicePort() {
      return (ApplicationService)super.getPort(new QName("http://test.esb.greenback/", "ApplicationServicePort"), ApplicationService.class);
      }

      }


      ObjectFactory.java
      package greenback.esb.test;

      import javax.xml.bind.annotation.XmlRegistry;


      /**
      * This object contains factory methods for each
      * Java content interface and Java element interface
      * generated in the greenback.esb.test package.
      * An ObjectFactory allows you to programatically
      * construct new instances of the Java representation
      * for XML content. The Java representation of XML
      * content can consist of schema derived interfaces
      * and classes representing the binding of schema
      * type definitions, element declarations and model
      * groups. Factory methods for each of these are
      * provided in this class.
      *
      */
      @XmlRegistry
      public class ObjectFactory {


      /**
      * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: greenback.esb.test
      *
      */
      public ObjectFactory() {
      }

      /**
      * Create an instance of {@link Po }
      *
      */
      public Po createPo() {
      return new Po();
      }

      }


      package-info.java
      @javax.xml.bind.annotation.XmlSchema(namespace = "http://test.esb.greenback/")
      package greenback.esb.test;


      Po.java
      package greenback.esb.test;

      import javax.xml.bind.annotation.XmlAccessType;
      import javax.xml.bind.annotation.XmlAccessorType;
      import javax.xml.bind.annotation.XmlType;


      /**
      * Java class for po complex type.
      *
      * The following schema fragment specifies the expected content contained within this class.
      *
      *
      * <complexType name="po">
      * <complexContent>
      * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
      * <sequence>
      * <element name="age" type="{http://www.w3.org/2001/XMLSchema}int"/>
      * <element name="name" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
      * </sequence>
      * </restriction>
      * </complexContent>
      * </complexType>
      *
      *
      *
      */
      @XmlAccessorType(XmlAccessType.FIELD)
      @XmlType(name = "po", propOrder = {
      "age",
      "name"
      })
      public class Po {

      protected int age;
      protected String name;

      /**
      * Gets the value of the age property.
      *
      */
      public int getAge() {
      return age;
      }

      /**
      * Sets the value of the age property.
      *
      */
      public void setAge(int value) {
      this.age = value;
      }

      /**
      * Gets the value of the name property.
      *
      * @return
      * possible object is
      * {@link String }
      *
      */
      public String getName() {
      return name;
      }

      /**
      * Sets the value of the name property.
      *
      * @param value
      * allowed object is
      * {@link String }
      *
      */
      public void setName(String value) {
      this.name = value;
      }

      }



      the wsdl file is
      - <definitions name="ApplicationServiceService" targetNamespace="http://test.esb.greenback/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://test.esb.greenback/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      -
      - <xs:schema targetNamespace="http://test.esb.greenback/" version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      - <xs:complexType name="po">
      - <xs:sequence>
      <xs:element name="age" type="xs:int" />
      <xs:element minOccurs="0" name="name" type="xs:string" />
      </xs:sequence>
      </xs:complexType>
      </xs:schema>

      -


      -


      -
      -




      -
      <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
      -
      <soap:operation soapAction="" />
      -
      <soap:body namespace="http://test.esb.greenback/" use="literal" />

      -
      <soap:body namespace="http://test.esb.greenback/" use="literal" />



      -
      -
      <soap:address location="http://192.168.168.188:8080/application/applicationESB" />




      The test class is
      import greenback.esb.test.ApplicationService;
      import greenback.esb.test.ApplicationServiceService;
      import greenback.esb.test.Po;

      public class Test {
      public static void main(String[] args){
      ApplicationServiceService ss=new ApplicationServiceService();
      ApplicationService service=ss.getApplicationServicePort();
      Po po=new Po();
      po.setAge(12);
      po.setName("init");
      String s=service.process(po);
      System.out.println(s);
      }
      }


      Did I write the test class right?If it is not correct,what is the right way?
      When I run the test Class ,it throws an exception

      Exception in thread "Main Thread" org.jboss.remoting.CannotConnectException: Can not connect http client invoker.
      at org.jboss.remoting.transport.http.HTTPClientInvoker.useHttpURLConnection(HTTPClientInvoker.java:327)
      at org.jboss.remoting.transport.http.HTTPClientInvoker.transport(HTTPClientInvoker.java:133)
      at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:122)
      at org.jboss.remoting.Client.invoke(Client.java:1544)
      at org.jboss.remoting.Client.invoke(Client.java:530)
      at org.jboss.ws.core.soap.SOAPConnectionImpl.callInternal(SOAPConnectionImpl.java:192)
      at org.jboss.ws.core.soap.SOAPConnectionImpl.call(SOAPConnectionImpl.java:109)
      at org.jboss.ws.core.CommonClient.invoke(CommonClient.java:309)
      at org.jboss.ws.core.jaxws.client.ClientImpl.invoke(ClientImpl.java:185)
      at org.jboss.ws.core.jaxws.client.ClientProxy.invoke(ClientProxy.java:163)
      at org.jboss.ws.core.jaxws.client.ClientProxy.invoke(ClientProxy.java:149)
      at $Proxy13.process(Unknown Source)
      at Test.main(Test.java:19)
      Caused by: java.lang.ClassCastException: org.apache.axis.message.MessageElement
      at org.jboss.ws.core.soap.SOAPEnvelopeImpl.(SOAPEnvelopeImpl.java:59)
      at org.jboss.ws.core.soap.EnvelopeBuilderDOM.build(EnvelopeBuilderDOM.java:87)
      at org.jboss.ws.core.soap.EnvelopeBuilderDOM.build(EnvelopeBuilderDOM.java:76)
      at org.jboss.ws.core.soap.MessageFactoryImpl.createMessage(MessageFactoryImpl.java:253)
      at org.jboss.ws.core.soap.SOAPMessageUnMarshaller.read(SOAPMessageUnMarshaller.java:75)
      at org.jboss.remoting.transport.http.HTTPClientInvoker.readResponse(HTTPClientInvoker.java:463)
      at org.jboss.remoting.transport.http.HTTPClientInvoker.useHttpURLConnection(HTTPClientInvoker.java:299)
      ... 12 more

        • 1. how to use jboss web service
          sdwfxsf

          I am sorry the wsdl file changed after i submit,this is the new one

          &lt;definitions name='ApplicationServiceService' targetNamespace='http://cvicse.com/' xmlns='http://schemas.xmlsoap.org/wsdl/' xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' xmlns:tns='http://cvicse.com/' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
          &lt;types>
          &lt;xs:schema targetNamespace='http://cvicse.com/' version='1.0' xmlns:xs='http://www.w3.org/2001/XMLSchema'>
          &lt;xs:complexType name='po'>
          &lt;xs:sequence>
          &lt;xs:element name='age' type='xs:int'/>
          &lt;xs:element minOccurs='0' name='name' type='xs:string'/>
          &lt;/xs:sequence>
          &lt;/xs:complexType>
          &lt;/xs:schema>
          &lt;/types>
          &lt;message name='ApplicationService_processResponse'>
          &lt;part name='return' type='xsd:string'>&lt;/part>
          &lt;/message>
          &lt;message name='ApplicationService_process'>
          &lt;part name='arg0' type='tns:po'>&lt;/part>
          &lt;/message>
          &lt;portType name='ApplicationService'>
          &lt;operation name='process' parameterOrder='arg0'>
          &lt;input message='tns:ApplicationService_process'>&lt;/input>
          &lt;output message='tns:ApplicationService_processResponse'>&lt;/output>
          &lt;/operation>
          &lt;/portType>
          &lt;binding name='ApplicationServiceBinding' type='tns:ApplicationService'>
          &lt;soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http'/>
          &lt;operation name='process'>
          &lt;soap:operation soapAction=''/>
          &lt;input>
          &lt;soap:body namespace='http://cvicse.com/' use='literal'/>
          &lt;/input>
          &lt;output>
          &lt;soap:body namespace='http://cvicse.com/' use='literal'/>
          &lt;/output>
          &lt;/operation>
          &lt;/binding>
          &lt;service name='ApplicationServiceService'>
          &lt;port binding='tns:ApplicationServiceBinding' name='ApplicationServicePort'>
          &lt;soap:address location='http://192.168.168.188:8080/application/applicationESB'/>
          &lt;/port>
          &lt;/service>
          &lt;/definitions>


          I use JBoss AS 4.2.0 GA