Results 1 to 10 of 43

Thread: HttpInvoker without web container?

Threaded View

  1. #11
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    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
    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
    The client will also require commons-codec.jar and commons-httpclient.jar on the classpath as well as the server prereqs.

    Client

    TimeServiceClient
    Code:
    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
    		}
    	}
    }
    client-applicationContext.xml
    Code:
    <?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>
    Server

    TimeService
    Code:
    package com.test;
    
    import java.util.Date;
    
    public interface TimeService
    {
    	Date getDate ();
    }
    TimeServiceImpl
    Code:
    package com.test;
    
    import java.util.Date;
    
    public class TimeServiceImpl implements TimeService
    {
    	public Date getDate ()
    	{
    		return new Date ();
    	}
    }
    applicationContext.xml
    Code:
    <?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>
    invoker-servlet.xml
    Code:
    <?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>
    web.xml
    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>
    Last edited by karldmoore; Jan 21st, 2007 at 05:01 AM.

Similar Threads

  1. Replies: 1
    Last Post: May 15th, 2005, 12:51 AM
  2. Container standard?
    By jbetancourt in forum Architecture
    Replies: 3
    Last Post: Apr 11th, 2005, 01:01 PM
  3. Replies: 2
    Last Post: Mar 27th, 2005, 10:50 PM
  4. AOP and pattern design
    By moo in forum AOP
    Replies: 12
    Last Post: Oct 19th, 2004, 01:17 PM
  5. Container Hierarchy
    By fbeauregard in forum Container
    Replies: 1
    Last Post: Sep 14th, 2004, 09:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •