Java Reference
In-Depth Information
Listing 5-30. PolicyQuoteServiceEndpoint.java
public class PolicyQuoteServiceEndpoint extends ServletEndpointSupport
implements PolicyQuoteApplicationService{
private PolicyQuoteApplicationService policyQuoteService;
protected void onInit() {
this.policyQuoteService = (PolicyQuoteApplicationService)
getWebApplicationContext().
getBean(PolicyQuoteApplicationService.BEAN_KEY);
}
public double calculatePolicyQuote(String productCd, int age,
double sumAssured, int term) {
return policyQuoteService.calculatePolicyQuote(productCd, age,
sumAssured, term);
}
}
The key thing in this listing is that the endpoint class provides access to the Spring
application context. The onInit method was overridden to get hold of the application
service object.
Since I am trying to expose this service over HTTP using SOAP messages, the Axis
servlet has to be configured with the web container. This servlet plays a critical role in
coordinating web service calls from the external clients and then delivering them to the
endpoint. It also takes care of mapping SOAP messages to the appropriate endpoint
methods, as well as returning the values from the methods as SOAP responses. It is
responsible for creating the WSDL file, which is used by the clients to access the policy
quote web service. The Axis servlet is registered with the web container like any other
servlet, as shown in Listing 5-31. It is advisable to deploy the web service as a separate
web application for modularity and ease of maintenance.
Listing 5-31. web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns=" http://java.sun.com/xml/ns/j2ee"
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 
Search WWH ::




Custom Search