OK, heres the working example I promised........ I would zip it up an attach it, but my computer isn't playing ball. The project in this example is called timeService.
Sooooo
The client will also require commons-codec.jar and commons-httpclient.jar on the classpath as well as the server prereqs.Code:tomcat
webapps
timeService
applicationContext.xml
invoker-servlet.xml
web.xml
classes
com/test/TimeService.class
com/test/TimeServiceImpl.class
lib
spring.jar
commons-logging-1.0.4.jar
Client
TimeServiceClient
client-applicationContext.xmlCode:package com.test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TimeServiceClient
{
public static void main ( String [] args )
{
ApplicationContext context = new ClassPathXmlApplicationContext ( "client-applicationContext.xml" );
TimeService timeService = ( TimeService ) context.getBean ( "timeService" );
System.out.println ( timeService.getDate () );
sleepPlease ();
System.out.println ( timeService.getDate () );
}
private static void sleepPlease ()
{
try
{
Thread.sleep ( 5000 );
}
catch ( InterruptedException e )
{
// ignore
}
}
}
ServerCode:<?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-2.0.xsd">
<bean id="httpInvokerRequestExecutor" class="org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor"/>
<bean id="timeService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<property name="serviceUrl" value="http://localhost:8080/timeService/invoker/timeService"/>
<property name="serviceInterface" value="com.test.TimeService"/>
<property name="httpInvokerRequestExecutor">
<ref bean="httpInvokerRequestExecutor"/>
</property>
</bean>
</beans>
TimeService
TimeServiceImplCode:package com.test;
import java.util.Date;
public interface TimeService
{
Date getDate ();
}
applicationContext.xmlCode:package com.test;
import java.util.Date;
public class TimeServiceImpl implements TimeService
{
public Date getDate ()
{
return new Date ();
}
}
invoker-servlet.xmlCode:<?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-2.0.xsd">
<bean id="timeService" class="com.test.TimeServiceImpl"/>
</beans>
web.xmlCode:<?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-2.0.xsd">
<bean name="/timeService" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="service">
<ref bean="timeService"/>
</property>
<property name="serviceInterface">
<value>com.test.TimeService</value>
</property>
</bean>
</beans>
Code:<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Time Service</display-name>
<description>Time Service</description>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>invoker</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/invoker/*</url-pattern>
</servlet-mapping>
</web-app>

