Java To WSDL
whereTypes defined
in separate xsd. 
Service Endpoint Interface
package com;
import
javax.jws.WebMethod;
import
javax.jws.WebService;
@WebService ( targetNamespace = "http://techyhouse.blogspot.com",
name = "DemoService" )
public interface DemoService 
{
      @WebMethod
      public void
testOne(TestVO testVO) throws TestException;
      @WebMethod
      public
String testTwo(String name) throws TestException;
      @WebMethod
      public
TestVO testThree(String name) throws TestException;
}
Service
Implementation
package com;
import
javax.jws.WebService;
@WebService(targetNamespace = "http://techyhouse.blogspot.com",
serviceName = "DemoService", 
      endpointInterface = "com.DemoService",
portName = "DemoServicePort")
public class DemoServiceImpl implements DemoService 
{
      @Override
      public void
testOne ( TestVO testVO ) throws TestException{}
      @Override
      public
String testTwo ( String name ) throws
TestException{
           
return null;
      }
      @Override
      public
TestVO testThree ( String name ) throws
TestException{
           
return null;
      }
}
Java
Beans  
package com;
import
java.io.Serializable;
import
javax.xml.bind.annotation.XmlAccessType;
import
javax.xml.bind.annotation.XmlAccessorType;
import
javax.xml.bind.annotation.XmlElement;
import
javax.xml.bind.annotation.XmlType;
@XmlAccessorType( XmlAccessType.FIELD )
@XmlType
public class
TestVO implements Serializable
{
      private static final long serialVersionUID 
= 5367711816L;
      @XmlElement(required=true,
defaultValue="1", nillable=false)
      private
Integer id;
      @XmlElement(required=false,
nillable=true)
      private
String name;
      @XmlElement(required=false)
      private
String[] data;
      public
Integer getId () { return id; }
      public void
setId ( Integer id ){ this.id =
id; }
      public String
getName (){ return name; }
      public void
setName ( String name ) { this.name =
name; }
      public
String[] getData (){ return data; 
}
      public void
setData ( String[] data ){ this.data =
data; }
}
Exception
classes
package com;
public class
TestException extends Exception
{
      private static final long    
serialVersionUID  = 8319892150394168546L;
}
Maven
configuration
<properties><cxf.version>2.4.1</cxf.version></properties>
<dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-frontend-jaxws</artifactId>
      <version>${cxf.version}</version>
</dependency>
<dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-transports-http</artifactId>
      <version>${cxf.version}</version>
</dependency>
<plugin>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-java2ws-plugin</artifactId>
      <version>${cxf.version}</version>
      <dependencies>
           
<dependency>
                 
<groupId>org.apache.cxf</groupId>
                 
<artifactId>cxf-rt-frontend-jaxws</artifactId>
                 
<version>${cxf.version}</version>
           
</dependency>
           
<dependency>
                 
<groupId>org.apache.cxf</groupId>
                 
<artifactId>cxf-rt-frontend-simple</artifactId>
                 
<version>${cxf.version}</version>
           
</dependency>
      </dependencies>
      <executions>
           
<execution>
                 
<id>process-classes</id>
                 
<phase>process-classes</phase>
                 
<configuration>
                       
<className>com.DemoServiceImpl</className>
                       
<genWsdl>true</genWsdl>
                       
<verbose>true</verbose>
                       
<argline> -createxsdimports
</argline>
                 
</configuration>
                 
<goals>
                       
<goal>java2ws</goal>
                 
</goals>
           
</execution>
      </executions>
</plugin>
After the maven project is built, check the targer/generated/wsdl folder for the wsdl and xsd.
DemoServiceImpl.wsdl
<?xml version="1.0"
encoding="UTF-8"?>
<wsdl:definitions name="DemoService" targetNamespace="http://techyhouse.blogspot.com"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://techyhouse.blogspot.com"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
  <wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
  <import namespace="http://techyhouse.blogspot.com"
schemaLocation="DemoServiceImpl_schema1.xsd"/>
</schema>
  </wsdl:types>
  <wsdl:message name="testThreeResponse">
    <wsdl:part name="parameters" element="tns:testThreeResponse">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="testTwoResponse">
    <wsdl:part name="parameters" element="tns:testTwoResponse">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="TestException">
    <wsdl:part name="TestException" element="tns:TestException">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="testOne">
    <wsdl:part name="parameters" element="tns:testOne">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="testTwo">
    <wsdl:part name="parameters" element="tns:testTwo">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="testOneResponse">
    <wsdl:part name="parameters" element="tns:testOneResponse">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="testThree">
    <wsdl:part name="parameters" element="tns:testThree">
    </wsdl:part>
  </wsdl:message>
   <wsdl:portType name="DemoService">
    <wsdl:operation name="testThree">
      <wsdl:input name="testThree" message="tns:testThree">
    </wsdl:input>
      <wsdl:output name="testThreeResponse" message="tns:testThreeResponse">
    </wsdl:output>
      <wsdl:fault name="TestException" message="tns:TestException">
    </wsdl:fault>
    </wsdl:operation>
    <wsdl:operation name="testTwo">
      <wsdl:input name="testTwo" message="tns:testTwo">
    </wsdl:input>
      <wsdl:output name="testTwoResponse" message="tns:testTwoResponse">
    </wsdl:output>
      <wsdl:fault name="TestException" message="tns:TestException">
    </wsdl:fault>
    </wsdl:operation>
    <wsdl:operation name="testOne">
      <wsdl:input name="testOne" message="tns:testOne">
    </wsdl:input>
      <wsdl:output name="testOneResponse" message="tns:testOneResponse">
    </wsdl:output>
      <wsdl:fault name="TestException" message="tns:TestException">
    </wsdl:fault>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="DemoServiceSoapBinding"
type="tns:DemoService">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="testThree">
      <soap:operation soapAction="" style="document"/>
      <wsdl:input name="testThree">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="testThreeResponse">
        <soap:body use="literal"/>
      </wsdl:output>
      <wsdl:fault name="TestException">
        <soap:fault name="TestException" use="literal"/>
      </wsdl:fault>
    </wsdl:operation>
    <wsdl:operation name="testTwo">
      <soap:operation soapAction="" style="document"/>
      <wsdl:input name="testTwo">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="testTwoResponse">
        <soap:body use="literal"/>
      </wsdl:output>
      <wsdl:fault name="TestException">
        <soap:fault name="TestException" use="literal"/>
      </wsdl:fault>
    </wsdl:operation>        
    <wsdl:operation name="testOne">
      <soap:operation soapAction="" style="document"/>
      <wsdl:input name="testOne">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="testOneResponse">
        <soap:body use="literal"/>
      </wsdl:output>
      <wsdl:fault name="TestException">
        <soap:fault name="TestException" use="literal"/>
      </wsdl:fault>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="DemoService">
    <wsdl:port name="DemoServicePort"
binding="tns:DemoServiceSoapBinding">
      <soap:address location="http://localhost:9090/DemoServicePort"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>
DemoServiceImpl_Schema.xsd
<?xml version="1.0"
encoding="utf-8"?>
<xs:schema xmlns:tns="http://techyhouse.blogspot.com"
xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://techyhouse.blogspot.com">
  <xs:element name="testOne"
type="tns:testOne"/>
  <xs:element name="testOneResponse"
type="tns:testOneResponse"/>
  <xs:element name="testThree"
type="tns:testThree"/>
  <xs:element name="testThreeResponse"
type="tns:testThreeResponse"/>
  <xs:element name="testTwo"
type="tns:testTwo"/>
  <xs:element name="testTwoResponse"
type="tns:testTwoResponse"/>
  <xs:complexType name="testThree">
    <xs:sequence>
      <xs:element minOccurs="0" name="arg0"
type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="testThreeResponse">
    <xs:sequence>
      <xs:element minOccurs="0" name="return"
type="tns:testVO"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="testVO">
    <xs:sequence>
      <xs:element default="1" name="id"
type="xs:int"/>
      <xs:element minOccurs="0" name="name"
nillable="true" type="xs:string"/>
      <xs:element maxOccurs="unbounded" minOccurs="0"
name="data" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="testTwo">
    <xs:sequence>
      <xs:element minOccurs="0" name="arg0"
type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="testTwoResponse">
    <xs:sequence>
      <xs:element minOccurs="0" name="return"
type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="testOne">
    <xs:sequence>
      <xs:element minOccurs="0" name="arg0"
type="tns:testVO"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="testOneResponse">
    <xs:sequence/>
  </xs:complexType>
  <xs:complexType name="TestException">
    <xs:sequence/>
  </xs:complexType>
  <xs:element name="TestException"
type="tns:TestException"/>
</xs:schema>
No comments:
Post a Comment