Published on WSO2 Oxygen Tank (http://wso2.org)

Hello World with WSO2 WSF/Spring

By mccloud35
Created 2008-02-11 04:40

The tutorial by Tharindu Mathew explains, how to expose beans defined in the Spring Framework [1] as Web services, using WSO2 WSF/Spring [2]. It is assumed that the reader has a basic knowledge on the Spring Framework. Prior knowledge in Apache Axis2 is NOT required.

The complete Web project with the source is available here [3].

 

Applies To

WSF/Spring v1.0 beta or higher
JDK v1.5
Spring Framework v 2.0.7 or higher

 

Content

  1. Introduction [3]
  2. Getting Started [3]
  3. Step 1 - Setting up a Web Project [3]
  4. Step 2 - Configuring the web.xml [3]
  5. Step 3 - Writing the Hello World Class [3]
  6. Step 4 - Initializing the Spring Bean [3]
  7. Step 5 - Exposing it as a Web Service [3]
  8. Conclusion [3]

 

Axis2 [4] Web service engine for the deployment of Web services.

This means that it inherits all the power and versatility of Axis2, which has implemented most of the WS-* specifications. And now as a Spring user, this power is at your disposal.

 

ContextLoaderListner [5] to initialize the SpringAxis2Servlet. Rest of the entries are standard Web xml entries to initialize the servlet. The welcome-file list entry is not essential. But you can make use of it to see whether the Web service is properly deployed, and also, to look at the wsdl. This will be further illustrated later.

 

article [6] for more about Axis2 and its architecture.

Now let's get back to creating a Web service, inserting the following lines in your application context:

<bean id="services" class="org.wso2.spring.ws.WebServices">
    <property name="services">
    <list>
  <bean id="helloService" class="org.wso2.spring.ws.SpringWebService">       
            <property name="serviceBean" ref="helloworld"></property>
            <property name="serviceName" value="helloWorldService"></property>
         </bean>
    </list>
    </property>
</bean>

We define a Web services bean and in that we list the beans we want to expose as services. Since the “helloworld” bean is what we want to expose, we list it as a Spring Web service bean in this list. The service name field is mandatory as it decides how the URL of the web service, i.e. the access point of the service.

Note : You can't have more than once WebService bean. All beans you want to expose should be listed in the services list of the Web service bean as SpringWebService beans.

That's it! We're done making our hello world Web service. Now let's see how it looks.

Create a WAR out of your Web project (In Eclipse this is done by, right-clicking on the project, Select Export... > Web > WAR). Drop the WAR into the webapp directory of your servlet container (ex :- Tomcat 5.5). Point your browser to http://localhost:8080/WSFSpringHelloWorld [7] (Assuming your server is hosted on port 8080 of localhost). Click on service and you should see the service listed under helloworldWebService. Click on that and you can see the wsdl for the Web service.

 

 

 axis2_home

Illustration 2 - Axis2 home page

 

 hello_world_service

Illustration 3 - helloWorldService

 

helloworld_service_WSDL

Illustration 4 - WSDL of the hello world service

 

Hello World with Axis2. [8] It shows, how to automatically generate client stubs and create a client with just a few lines of code, using Axis2.

 

Author

Tharindu Mathew, Trainee Web Service Developer, tharindu at wso2.com

 


Source URL:
http://wso2.org/library/3208