<bean id="castorMarshaller"
class="org.springframework.oxm.castor.CastorMarshaller">
<property name="mappingLocation" value="classpath:oxm-mapping.xml"/>
</bean>
</beans>
The important points for Listing 16-26 are as follows:
The <mvc:annotation-driven> tag enables the annotation support for Spring MVC
·
(i.e., the @Controller annotation), as well as registers Spring 3's type conversion
and formatting system. In addition, JSR-303 validation support is also enabled
under the definition of this tag.
Under <mvc:annotation-driven>, the <mvc:message-converters> tag declares the
·
instances of HttpMessageConverter that will be used for media conversion for
supported formats. Note that the <mvc:message-converters> tag was introduced in
Spring 3.1. Because we will support both JSON and XML as the data format, two
converters are declared. The first one is MappingJacksonHttpMessageConverter,
which is Spring's support for the Jackson JSON library
(http://jackson.codehaus.org). The other one is
MarshallingHttpMessageConverter, which is provided by the spring-oxm module
for XML marshaling/unmarshaling. Within the MarshallingHttpMessageConverter,
we need to define the marshaler and unmarshaler to use, which is the one
provided by Castor in our case.
For the castorMarshaller bean, we use the Spring-provided class
·
org.springframework.oxm.castor.CastorMarshaller, which integrates with Castor,
and we provide the mapping location that Castor required for its processing.
The <context:component-scan> tag instructs Spring to scan for the specified
·
package for controller classes.
Now, the server-side service is complete. If your tc Server is on, the project would have been built
and deployed to the server automatically. If not, rebuild the project and start the server.
You may find that while starting the web application, errors will be reported by Spring, because of
the previous implemented samples. To fix this, do the following:
Move the controller class HomeController from the package
1.
com.apress.prospring3 to a new package called
com.apress.prospring3.ch16.web.app.controller.
In the file src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml,
2.
change the line from <context:component-scan base-
package="com.apress.prospring3" /> to <context:component-scan base-
package="com.apress.prospring3.ch16.web.app.controller" />.
Using curl to Test RESTful-WS
Let's do a quick test of the RESTful web services that we implemented. One easy way is to use curl
(http://curl.haxx.se), which is a command-line tool for transporting data with URL syntax. To use the
tool, just download it from the web site and extract in onto your computer.
For example, to test the retrieval of all contacts, open a command prompt in Windows or a terminal
in Unix/Linux, and fire the command shown in Listing 16-27.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home