Skip to main content

Code-first development

Code-first development means starting from an existing Java interface of a web service provider from which a WSDL can automatically be generated. Talend ESB, in the examples/talend/cxf folder, provides a dev-guide-java-first sample functionally equivalent to the dev-guide-wsdl-first example explored in the previous section. CXF's Java2ws tool, configured within the cxf-java2ws-plugin Maven plugin, is used for this process. For example, given a simple web service interface:

package service;

import javax.jws.WebService;
import javax.jws.WebMethod;

public interface DoubleItPortType {
   public int doubleIt(int numberToDouble);

The code first developer will implement the web service, adding annotations to indicate desired web service configuration information:

package service;

import javax.jws.WebService;

@WebService(targetNamespace = "",
            endpointInterface = "service.DoubleItPortType",
            serviceName = "DoubleItService",
            portName = "DoubleItPort")
public class DoubleItPortTypeImpl implements DoubleItPortType {

    public int doubleIt(int numberToDouble) {
        return numberToDouble * 2;

If the Maven pom.xml has the cxf-java2ws-plugin configured as follows:


An autogenerated two-part WSDL supporting this web service will be created, as shown below (certain areas truncated for brevity). The first file, DoubleItPortTypeImpl.wsdl contains message input and output information as well as the generic wsdl:portType that lists the method calls available. The wsdl:portType value incorporates the name of the web service interface. This interface also provides (from its doubleIt method) the name of the specific operation and its parameters.

<wsdl:definitions name="DoubleItPortType" targetNamespace="http://service/">
        <xs:schema elementFormDefault="unqualified" 
            targetNamespace="http://service/" version="1.0">
            <xs:element name="doubleIt" type="tns:doubleIt" />
            <xs:element name="doubleItResponse" type="tns:doubleItResponse" />
            <xs:complexType name="doubleIt">
                    <xs:element name="arg0" type="xs:int" />
            <xs:complexType name="doubleItResponse">
                    <xs:element name="return" type="xs:int" />
    <wsdl:message name="doubleIt">
        <wsdl:part name="parameters" element="ns1:doubleIt"/>
    <wsdl:message name="doubleItResponse">
        <wsdl:part name="parameters" element="ns1:doubleItResponse"/>
    <wsdl:portType name="DoubleItPortType">
        <wsdl:operation name="doubleIt">
            <wsdl:input name="doubleIt" message="ns1:doubleIt"/>
            <wsdl:output name="doubleItResponse" 

The second file, DoubleItPortType.wsdl imports the former file and provides the explicit wsdl:binding and wsdl:service connection information. The wsdl:service incorporates the service name and port name values specified on the Java web service implementation above.

<wsdl:definitions name="DoubleItService" 
    <wsdl:import namespace="http://service/" location="DoubleItPortType.wsdl"/>
    <wsdl:binding name="DoubleItServiceSoapBinding" 
        <soap:binding style="document" 
            transport="" />
        <wsdl:operation name="doubleIt">
            <soap:operation soapAction="" style="document" />
            <wsdl:input name="doubleIt">
                <soap:body use="literal" />
            <wsdl:output name="doubleItResponse">
                <soap:body use="literal" />
    <wsdl:service name="DoubleItService">
        <wsdl:port name="DoubleItPort" 
            <soap:address location="http://localhost:9090/DoubleItPort" />

This sample can be compiled and deployed just as explained in the previous wsdl-first example--only difference, for Talend ESB OSGi deployment, to use install as the bundle install string.

In the next Java-first example we'll demonstrate other helpful tools for web services development, including the m2eclipse plugin, Apache CXF's Maven archetypes for creating skeleton code and soapUI for making test SOAP calls.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!