18 November 2008 - 2.5 |
The following example gives a complete walkthrough of how to implement and deploy a Web Service with the JBossWS plugin. The development environment is as follows:
Start by installing the above and setting the path to the wstools script as described in the Overview.
Create a standard empty Java project;
Add a source folder for our Java code:
Add a package for our classes:
Create a simple IHelloWorld interface:
package jbosstest; import java.rmi.Remote; import java.rmi.RemoteException; public interface IHelloWorld extends Remote { public String sayHello( String subject ) throws RemoteException; }
(JBossWS requires webservice classes to extend Remote and all web service methods to throw RemoteException)
Implement the interface:
package jbosstest; public class HelloWorld implements IHelloWorld { public String sayHello(String subject) { return "Hello " + subject + "!"; } }
Before we can use the plugin we need to enable the JBossWS Nature as described in Getting Started;
Once enabled, the project structure should be as follows (in the Project Explorer View):
Now we can publish our Web Service; right-click on the HelloWorld class and select "JBossWS / Publish as Web Service", which will open the "Publish" dialog as described in Publishing Web Services:
Most settings can be left at their default; just set the style to "rpc" and then select the advanced tab;
Here just select the "HelloWorld.war" entry from Package drop-down. Now select the Generate button, which will start generation of the project:
After the generation has finished, packaging will be run which will be visible in another console window:
After these steps, the project state should now be as follows:
Now all that is left is to deploy the generated WAR-file to our local JBoss server; right-click the generated HelloWorld.war 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:
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: