<property name="serviceInterface"
value="com.apress.prospring3.ch16.service.ContactService" />
</bean>
As shown in Listing 16-9, a contactExporter bean was defined with the HttpInvokerServiceExporter
class, which is for exporting any Spring bean as a service via the HTTP invoker. Within the bean, two
properties are defined. The first one is the service property, indicating the bean providing the service.
For this property, the contactService bean is injected. The second property is the interface type to
expose, which is the com.apress.prospring3.ch16.service.ContactService interface.
Next, we need to define a servlet within the web deployment descriptor (/src/main/webapp/WEB-
INF/web.xml) for the service. Listing 16-10 shows the code snippet to add into the web.xml file.
Listing 16-10. Servlet Definition for the HTTP Invoker
<!-- Spring Remoting with HTTP Invoker -->
<servlet>
<servlet-name>contactExporter</servlet-name>
<servlet-class>
org.springframework.web.context.support.HttpRequestHandlerServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>contactExporter</servlet-name>
<url-pattern>/remoting/ContactService</url-pattern>
</servlet-mapping>
As shown in Listing 16-10, a servlet with the class HttpRequestHandlerServlet is defined, which is
used to expose the Spring exporter defined in the WebApplicationContext. Note the servlet name
(contactExporter) should match with the bean name of the exporter (see Listing 16-9; the bean name is
also contactExporter). Then, the servlet is mapped to the URL /remoting/ContactService under the web
context (i.e., http://localhost:8080/ch16) of the application.
Until now, if you are using the STS project's default setting, the project should have been rebuilt and
deployed to the tc Server. Now we can proceed to develop the client to invoke the service.
Invoking the Service
Invoking a service via the Spring HTTP invoker is very simple. First we configure a Spring
ApplicationContext, as shown in Listing 16-11 (http-invoker-app-context.xml).
Listing 16-11. Spring ApplicationContext for HTTP Invoker Client
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<bean id="remoteContactService"
class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<property name="serviceUrl"
value="http://localhost:8080/ch16/remoting/ContactService" />
<property name="serviceInterface"
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home