Java Reference
In-Depth Information
temperatureElement.addElement("min").setText(
Double.toString(temperature.getMin()));
temperatureElement.addElement("max").setText(
Double.toString(temperature.getMax()));
temperatureElement.addElement("average").setText(
Double.toString(temperature.getAverage()));
}
return responseElement;
}
}
In the preceding invokeInternal() method, you first extract the service parameters from the request
message. Here, you use XPath to help locate the elements. The XPath objects are created in the
constructor so that they can be reused for subsequent request handling. Note that you must also include
the namespace in the XPath expressions, or else they will not be able to locate the elements correctly.
After extracting the service parameters, you invoke the back-end service to handle the request.
Because this endpoint is configured in the Spring IoC container, it can easily refer to other beans
through dependency injection.
Finally, you build the response message from the back-end service's result. The dom4j library
provides a rich set of APIs for you to build an XML message. Remember that you must include the
default namespace in your response element.
With the service endpoint written, you can declare it in weather-servlet.xml . Because this endpoint
needs the weather service bean's help to query temperatures, you have to make a reference to it.
<bean id="temperatureEndpoint"
class="com.apress.springenterpriserecipes.weather.TemperatureDom4jEndpoint">
<property name="weatherService" ref="weatherService" />
</bean>
Publishing the WSDL File
The last step to complete your web service is to publish the WSDL file. In Spring-WS, it's not necessary
for you to write the WSDL file manually, although you may still supply a manually written WSDL file. You
only declare a DynamicWsdl11Definition bean in the web application context, and then it can generate
the WSDL file dynamically. MessageDispatcherServlet can also detect this bean by the WsdlDefinition
interface.
<bean id="temperature"
class="org.springframework.ws.wsdl.wsdl11.DynamicWsdl11Definition">
<property name="builder">
<bean class="org.springframework.ws.wsdl.wsdl11.builder.
XsdBasedSoap11Wsdl4jDefinitionBuilder">
<property name="schema" value="/WEB-INF/temperature.xsd" />
<property name="portTypeName" value="Weather" />
<property name="locationUri"
value=" http://localhost:8080/weather/services" />
</bean>
</property>
</bean>
Search WWH ::




Custom Search