Deploying Spring Services

The WSO2 Web service Application Server (WSAS) provides a tool to simply expose a Spring bean as a Web service. All you have to do is provide a Spring context .xml file and a .jar file that contains the bean classes specified in the Spring context .xml file.

Writing a Simple Spring Bean

The following is a simple example of a Spring context .xml.

Specify a particular bean with an ID,and a class name which can be found in the .jar file.

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans><bean id="SimpleEchoBean" class="org.wso2.test.EchoBean"></bean>

</beans>

The Echo Bean for this example is given below. It can contain any type of service implementation.

package org.wso2.test;

/*** Example EchoBean***/

public class EchoBean {

public String echoString(String input) {

return input;

}

public int echoInt(int input) {

return input;

}

}

Adding a Spring Service to the Server

The Add Spring Service feature is used to upload the spring context.xml file and the .jar file with the bean classes.

Figure 1: Adding a spring service

  1. In the navigator, under Manage/Service, click Spring Service. The Add Spring Service page appears.
  2. Provide the hierarchical path of the service. This is optional. If you want to manage services separately, specifying a heirarchy is important. This allows you to customise your service EPR as you wish. And also it allows you to manage multiple versions of the same service changing only the business logic.

    Example: Consider a service "SpringTest"

    If no service hierarchy -> EPR is ../services/SpringTest

    With service hierarchy foo/bar/1.0.0 -> EPR is ../services/foo/bar/1.0.0/SpringTest

  3. Click Browse, and select the Spring context .xml file, and the Spring beans .jar file respectively.
  4. Click Upload. If the files are correct, the Select Beans to Deploy page appears. If the beans specified in the spring context .xml file are found in the .jar file, they will be displayed on this page.
  5. Select the Include check box for the beans you want to expose as web services.
  6. Click Generate. The services will appear on the Service List page. Several options are available to test your service and manage the quality of your service.

Figure 2: Select the required bean to deploy

Note: If your service implementation depends on any third party libraries, you can copy those into CARBON_HOME/lib/extensions directory and restart the server to get your service working.