Integrating Apache Axis with the Spring Frameworkby Alexander Prohorenko and Olexiy Prohorenko Nowadays, many applications work in decentralized, distributed environments. Most of these applications need to exchange structured information with other applications. One of the best ways to do this is to use a SOAP ("Simple Object Access Protocol") protocol. The SOAP protocol has many different implementations, but this article will focus on Apache Axis. Apache Axis is becoming popular among developers because "it has proven itself to be a reliable and stable base on which to implement Java Web services." At it‘s core, Axis is mainly a framework for constructing SOAP processors like clients and servers, but its use is not limited to this. Another framework which is also very widely used and supposed to be a "best fit" for lightweight applications is the Spring Framework. Spring is a layered J2EE application framework, which includes, but is not limited to, the most complete lightweight container and flexible MVC Web application framework. Spring was created to address the complexity of enterprise application development. So, what happens if you connect these two "best fit" frameworks together? This question has been asked often—and there are many different ways to mix the two. In this article, you‘ll write a SOAP Web service using Apache Axis with classes available for configuration and initialization using the Spring Framework. Hopefully, this will give you an idea of the possiblities made available by using the two frameworks together.
What You Will NeedTo understand and run everything described in the article, first of all you have to be familiar with J2EE in general, Spring and at least to have basic understanding of Web services. You need to have some hands-on experience with developing Web applications. You can expect this article to be a tutorial or how-to guide. The list of software which will be used within this article: You‘ll use the following software to compile and run your code:The Code for the Business LogicYou will be writing a Web service which will have a
Here‘s the code for the class, implementing the interface:
This code is simple and does not require any comments. The business logic can contain any methods you want.
The Code for the Web ServiceThe Web service requires you to have an interface and an implementation. First comes the interface,
The interface needs to extend
This implementation is much like the business logic (except the fact that it does not include method itself). This class extends the Using the Spring framework, initialize the
The Spring ConfigurationThe Spring configuration starts in the
This configures Spring‘s application context path and sets the mapping of
Note: The Web service servlet needs to run in the same Web application as the Spring context to allow for access to Spring‘s facilities.
Configuring AxisNow, you need to configure your Axis class and setup the parameters of the Web service. This will require creating a specialdeploy.wsdd file. You don‘t need to configure too many of its options, but in case you ever need to, this file is very well documented at Apache Axis‘ Deployment (WSDD) Reference. For now, however, you will need only a few options:
Define the service name as webservice . This name is used to deploy and undeploy an Axis service. className defines the backend implementation class, which is us.prokhorenko.springaxis.soap.WebServiceImpl (WebServiceImpl.java ). Use allowedMethods to determine which methods are allowed to be exposed as Web services; in this example, you are allowing everything. At least, wsdlTargetNamespace defines the namespace for this service, which is set to urn:soap.springaxis. . Now, the add Axis configuration to the web.xml file:
The most important thing to note is the mapping: the code maps /soap/ to Axis‘ Web services.
Building EverythingThis example uses the Apache Ant tool for building the project into WAR. Thebuild.xml is pretty standard and normally would not require any changes except for the Axis configuration:
It sets the file option which points to the deploy.wsdd configuration file. And you may also need to set the proper values in the properties.xml file.
Here‘s how the sample building and deploying process looks:
Now the application is deployed and ready to serve.
RunningThe source code for this article includes a sample SOAP client. It will allow you to easily test your Web service configuration and confirm that everything‘s working as it‘s supposed to. The client is configured to use the endpointhttp://localhost:8080/springaxis/soap/webservice . It calls the doSomeWork() method and passes "TheNameOfWork" as an argument. After building and deploying, you‘ll be able to run this client at http://localhost:8080/springaxis/SOAP.html
Hopefully, this gives you a detailed and easy-to-repeat tutorial on enabling methods from business logic as Web services.
Resources
|
|