06 August 2007 - 1.7.5 | home user-guide eclipse jbossws intellij netbeans maven 1.X/2.X PDF files forums bugs sourceforge

Home
Getting Started
User Guide
IDE/Tool Plugins

- Maven Plugins
  - Maven 1.X Plugin
    - Goals
    - Properties
  - Maven 2.X Plugin
    - Goals
    - Properties
- NetBeans Plugin
  - Installation
  - Project Integration
- IntelliJ Plugin
- Eclipse Plugin
  - soapUI Nature
- JBossWS Plugin
  - New in 2.0.0 beta2
  - Getting Started
  - Publishing Web Services
    - Publish POJO Example
  - Consuming a Web Service
  - Implementing a Web Service
    - Implement WSDL Example
  - Web Service Annotations
    - EJB3/WS Annotate Example

Search soapUI site
Project Documentation

- About soapUI
- Project Info
- Project Reports

## Implement WSDL with POJO Web Service - Walkthrough Example

The following example gives a complete walkthrough of how to implement and deploy a Web Service with the JBossWS plugin starting from an existing WSDL. As you will see, this is still a rather complex procedure, but future versions of the JBossWS Plugin will strive to simplify related tasks even further.

The development environment is as follows:

- The JBossIDE-200609232042-nightly-ALL.zip nightly build of JBossIDE on top of the eclipse SDK/WTP/etc.. components listed on the nightly-build page (bottom right)
- JBoss 4.0.4-GA with EJB3 profile
- JBossWS 1.0.3

Start by installing the above and setting the path to the wstools script as described in the Overview.

### Create the project and WSDL

Create an empty java-project:

Create a standard empty java project;

Add 2 folders:

- One source folder for src/java
- One normal folder for src/wsdl

Now manually craete a WSDL using the WTP WSDL editor or some other tool, the following is a "simple" RPC-style HelloWorld contract:

    <?xml version="1.0" encoding="UTF-8"?>
    <wsdl:definitions name="HelloWorld"
    	targetNamespace="http://www.example.org/HelloWorld/"
    	xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    	xmlns:tns="http://www.example.org/HelloWorld/"
    	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    	xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
    	<wsdl:types/>
    	<wsdl:message name="sayHelloRequest">
    		<wsdl:part name="sayHelloRequest" type="xsd:string"></wsdl:part>
    	</wsdl:message>
    	<wsdl:message name="sayHelloResponse">
    		<wsdl:part name="sayHelloResponse" type="xsd:string"></wsdl:part>
    	</wsdl:message>
    	<wsdl:portType name="IHelloWorld">
    		<wsdl:operation name="sayHello">
    			<wsdl:input message="tns:sayHelloRequest"></wsdl:input>
    			<wsdl:output message="tns:sayHelloResponse"></wsdl:output>
    		</wsdl:operation>
    	</wsdl:portType>
    	<wsdl:binding name="HelloWorld" type="tns:IHelloWorld">
    		<soap:binding style="rpc"
    			transport="http://schemas.xmlsoap.org/soap/http" />
    		<wsdl:operation name="sayHello">
    			<soap:operation
    				soapAction="http://www.example.org/HelloWorld/sayHello" />
    			<wsdl:input>
    				<soap:body use="literal"
    					namespace="http://www.example.org/HelloWorld/" />
    			</wsdl:input>
    			<wsdl:output>
    				<soap:body use="literal"
    					namespace="http://www.example.org/HelloWorld/" />
    			</wsdl:output>
    		</wsdl:operation>
    	</wsdl:binding>
    	<wsdl:service name="HelloWorldService">
    		<wsdl:port name="HelloWorldPort" binding="tns:HelloWorld">
    			<soap:address location="http://localhost:8080/HelloWorld" />
    		</wsdl:port>
    	</wsdl:service>
    </wsdl:definitions>

Save the contract to src/wsdl/HelloWorld.wsdl, your project should now be as follows:

### Import the WSDL contract

Now we need to enable the JBossWS Nature:

After enabling, add the HelloWorld.wsdl to the JBossWS node by right-clicking the WSDL and selecting "JBossWS / Add to JBossWS Project":

After this, your project should look as follows:

Now right click the "IHelloWorld" node under the "JBossWS Web Services" node and select "Generate / JBossWS Artifacts", which will open the following dialog:

Set the mapping file and namespace as above and select the "Generate" button. After successfull generation, your project should now look as follows:

### Implement and Publish the Service Interface

The generation in the previous step created an "IHelloWorld" interface which can now implement; in this example the implementing class will be helloworld.impl.HelloWorld:

    package helloworld.impl;

    import helloworld.IHelloWorld;

    public class HelloWorld implements IHelloWorld
    {
    	public String sayHello(String sayHelloRequest)
    	{
    		return "Hello " + sayHelloRequest + "!";
    	}
    }

Once implemented, right-click this class and select "JBossWS / Publish as Web Service", which opens the Publish dialog:

Set the style to rpc (as it was in our original WSDL) the rest can be left at default

Here we need to tell the plugin that we want to reuse our own WSDL and previously generated mapping file (to ensure a correct contract and mapping..). Also, we dont need to add the WSDL to our JBossWS project (since it has already been imported there..). Specify these options and the WSDL port from your WSDL (which goes into webservices.xml) before pressing "Generate".

After generating, your project should now look as follows:

As you can see, the previously generated WSDL and mapping files have been copies to the WEB-INF and WEB-INF/wsdl folders. Also, the webservices.xml file has been updated accordingly:

### Deploy Locally

Now all that is left is to deploy the generated WAR-file to our local JBoss server; right-click the generated HelloWorld.jar file and select "Run as / Run on Server" and then select your locally configured and running JBoss installation. You should get a deployment log in the servers console:

### Test

Double-click the previously generated "Request 1" entry under the "sayHello" node in the Project Explorer, this will open a SOAP request editor:

Change the '?' to 'Marc', save the request (CTRL-S) and press the green arrow in the toolbar for sending the request to the local Web Service. You will get the response in a new editor tab:

Next: Generating Web Service Annotations