This is an example on how to create a wsdl from java code, with types defined in separate xsd. I used maven java2ws task to achieve the same.
After the maven project is built, check the targer/generated/wsdl folder for the wsdl and xsd.
Service Endpoint Interface
package com;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService ( targetNamespace = "http://com", name = "TestService" )
public interface TestService
{
@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://com", serviceName = "TestService",
endpointInterface = "com.TestService", portName = "TestServicePort")
public class TestServiceImpl implements TestService
{
@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.TestServiceImpl</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.
TestServiceImpl.wsdl
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="TestService" targetNamespace="http://com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://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://com" schemaLocation="TestServiceImpl_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="TestService">
<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="TestServiceSoapBinding" type="tns:TestService">
<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="TestService">
<wsdl:port name="TestServicePort" binding="tns:TestServiceSoapBinding">
<soap:address location="http://localhost:9090/TestServicePort"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>