Page 2 of 5 FirstFirst 1234 ... LastLast
Results 11 to 20 of 43

Thread: HttpInvoker without web container?

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

    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.

  2. #12
    Join Date
    Jan 2007
    Posts
    139

    Default

    Quote Originally Posted by karldmoore View Post
    I'm guessing your problem might be to do with the serviceURL.

    Code:
    <property name="serviceUrl" value="http://localhost:8080/httpGroupDao"/>
    If your exposed service is called groupDao, the servlet name is remoting and the webapp is called test......

    Code:
    <property name="serviceUrl" value="http://localhost:8080/test/remoting/groupDao"/>

    I think part of my problem is I am using the Netbeans IDE and I have a multi-project app. We added a new sub-project which includes all of the dao/service layer code and basically modified this, adding a web/WEB-INF directory, which contains the web.xml file(no classes or lib YET). However, seeing that this sub-project was NOT set up as a web app, a jar is being created instead of a war. So, I think the problem is two fold; project structure and directory structure.

    At this point, I am going to replace this sub-project w/a true web app, move in the needed interfaces, classes(build to class dir) and dependencies(build to lib) and then try this again.

    Have you ever tried to use HttpInvoker w/Jetty, however? Do I need to set the ServletContext, like I would have to do w/Tomcat?

  3. #13
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,425

    Default

    I've never tried this with Jetty. The example I posted was run with Tomcat. There were no other changes required though then creating the project in webapps and putting the files in the location I stated. Hope this helps.

  4. #14
    Join Date
    Jan 2007
    Posts
    139

    Default

    It should help. I didn't have much like getting a web-app structured sub-project to play nice w/an application parent project, so I am mimicking a web app directory and placing the files in the proper spot for the build.

    I will let you know shortly if that works.

  5. #15
    Join Date
    Jan 2007
    Posts
    139

    Default

    so, you did NOT create a war file like you normally would, but manually moved the classes and libs into their respective directories?

    I am still getting 404s when using Jetty. Not sure what is going on.

  6. #16
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,425

    Default

    That right, I didn't create a WAR file. I don't think thats anything to do with it however.

  7. #17
    Join Date
    Jan 2007
    Posts
    139

    Default

    I don't either. I believe it has something to do w/the relationship between jetty.xml, web.xml and the applicationcontext.xml.

  8. #18
    Join Date
    Aug 2004
    Location
    San Francisco
    Posts
    423

    Default

    I'm developing and deploying applications using HttpInvoker using Jetty as the servlet container. I've looked through the above files and I can't see a difference in how I configure things.

    Basically, we have a bean '/Service' exposed via a servlet with mapping url pattern '/remote/*' under a context 'dataaccess' on server odin. The serviceUrl we use is

    http://odin:80/dataaccess/remote/Service

    That seems to agree with the other configuration and my web.xml is basically the same. My jetty (v5) configuration is:

    Code:
    <Call name="addWebApplication">
    	<Arg>/dataaccess/*</Arg>
    	<Arg>path to war file</Arg>
    	<Set name="extractWAR">true</Set>
      </Call>
    Jonny

  9. #19
    Join Date
    Jan 2007
    Posts
    139

    Default

    Quote Originally Posted by jwray View Post
    I'm developing and deploying applications using HttpInvoker using Jetty as the servlet container. I've looked through the above files and I can't see a difference in how I configure things.

    Basically, we have a bean '/Service' exposed via a servlet with mapping url pattern '/remote/*' under a context 'dataaccess' on server odin. The serviceUrl we use is

    http://odin:80/dataaccess/remote/Service

    That seems to agree with the other configuration and my web.xml is basically the same. My jetty (v5) configuration is:

    Code:
    <Call name="addWebApplication">
    	<Arg>/dataaccess/*</Arg>
    	<Arg>path to war file</Arg>
    	<Set name="extractWAR">true</Set>
      </Call>
    Jonny
    A couple of questions; I don't have the addWebApplication in my jetty.xml. Do I need this? Second, can I do this if the app is not packaged as a WAR file, like a normal web app?

  10. #20
    Join Date
    Jan 2007
    Posts
    139

    Default

    Quote Originally Posted by jwray View Post
    I'm developing and deploying applications using HttpInvoker using Jetty as the servlet container. I've looked through the above files and I can't see a difference in how I configure things.

    Basically, we have a bean '/Service' exposed via a servlet with mapping url pattern '/remote/*' under a context 'dataaccess' on server odin. The serviceUrl we use is

    http://odin:80/dataaccess/remote/Service

    That seems to agree with the other configuration and my web.xml is basically the same. My jetty (v5) configuration is:

    Code:
    <Call name="addWebApplication">
    	<Arg>/dataaccess/*</Arg>
    	<Arg>path to war file</Arg>
    	<Set name="extractWAR">true</Set>
      </Call>
    Jonny
    I believe that the following in a Jetty 6 jetty.xml should accomplish the same thing as the addWebApplication above, correct?

    Code:
    <property name="handler">
                <bean id="handlers"
                      class="org.mortbay.jetty.handler.HandlerCollection">
                    <property name="handlers">
                        <list>
                            <bean id="contexts"
                                  class="org.mortbay.jetty.handler.ContextHandlerCollection">
                                <property name="handlers">
                                    <list>
                                        <bean class="org.mortbay.jetty.webapp.WebAppContext">
                                            <property name="contextPath" value="/"/>
                                            <!--<property name="war" value="../web">-->
                                                <property name="resourceBase" value="../backcheck">
                                            </property>
                                        </bean>
                                    </list>
                                </property>

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
  •