Java Reference
In-Depth Information
Now you can inject this manually written proxy into
WeatherServiceClient
and run it with the
Client
main class.
Because your DAO class can extend
JdbcDaoSupport
to get a precreated
JdbcTemplate
instance,
your web service client can similarly extend the
WebServiceGatewaySupport
class to retrieve a
WebServiceTemplate
instance without explicit injection. At this point, you can comment out
the
webServiceTemplate
variable and setter method.
package com.apress.springenterpriserecipes.weather;
...
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
public class WeatherServiceProxy
extends WebServiceGatewaySupport
implements WeatherService {
public List<TemperatureInfo> getTemperatures(String city, List<Date> dates) {
...
// Invoke the remote web service
DocumentSource source = new DocumentSource(requestDocument);
DocumentResult result = new DocumentResult();
getWebServiceTemplate().sendSourceAndReceiveToResult(source, result);
...
}
}
However, without a
WebServiceTemplate
bean declared explicitly, you have to inject the default URI
to the proxy directly. The setter method for this property is inherited from the
WebServiceGatewaySupport
class.
<beans ...>
...
<bean id="weatherServiceProxy"
class="com.apress.springenterpriserecipes.weather.WeatherServiceProxy">
<property name="defaultUri"
value="
http://localhost:8080/weather/services"
/>
</bean>
</beans>
5-12. Developing Web Services with XML Marshalling
Problem
To develop web services with the contract-first approach, you have to process request and response
XML messages. If you parse the XML messages with XML parsing APIs directly, you'll have to deal with
the XML elements one by one with low-level APIs, which is a cumbersome and inefficient task.
Solution
Spring-WS supports using XML marshalling technology to marshal/unmarshal objects to/from XML
documents. In this way, you can deal with object properties instead of XML elements. This technology is
also known as
object/XML mapping (OXM)
, because you are actually mapping objects to and from XML
documents.
Search WWH ::
Custom Search