Page 5 of 5 FirstFirst ... 345
Results 41 to 43 of 43

Thread: HttpInvoker without web container?

  1. #41
    Join Date
    Jan 2007
    Posts
    139

    Default

    I just got it working today in fact. Here is my jetty xml context/web app context portions:

    Code:
    <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="/webapps/app.war"/>
                                        </bean>
    I am having another problem now related to Serialization using HttpInvoker. I have an object which itself contains a set of other objects. These other objects have primitives, along w/other objects, as attributes. When attempt to serialize the entire class, I get "StreamCorruptedException Invalid Type Code:40" errors. The class in question has two primitive attributes, one an array of doubles, the other an array of ints. If I make both of these attributes transient, it works w/o the expection.

    I was under the impression that primitives were automatically serialized, so I am not sure why this is occurring. Any ideas?

  2. #42
    Join Date
    Jan 2007
    Posts
    139

    Default

    Quote Originally Posted by karldmoore View Post
    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>
    Ok, here is my latest dilemna . . .

    How to get your own class/interface objects to be used as arguments to the method exposed by HttpInvokerProxyFactoryBean.

    It seems that if I pass a java.lang.Object to a method, it works. However, if I pass one of my own interfaces, I get a java.lang.reflect.InvocationTargetException.

    Please see this post for more information:
    http://forum.springframework.org/showthread.php?t=34218

    This is a tough one. I have been stumped all day on it, and can't find ANYTHING close on the forums. The only thing I have seem is certain posts stating that HttpInvoker uses pass by value rather then pass by reference. Would this be a problem?

  3. #43
    Join Date
    Jan 2007
    Posts
    139

    Default

    Quote Originally Posted by mark_in_gr View Post
    I just got it working today in fact. Here is my jetty xml context/web app context portions:

    Code:
    <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="/webapps/app.war"/>
                                        </bean>
    I am having another problem now related to Serialization using HttpInvoker. I have an object which itself contains a set of other objects. These other objects have primitives, along w/other objects, as attributes. When attempt to serialize the entire class, I get "StreamCorruptedException Invalid Type Code:40" errors. The class in question has two primitive attributes, one an array of doubles, the other an array of ints. If I make both of these attributes transient, it works w/o the expection.

    I was under the impression that primitives were automatically serialized, so I am not sure why this is occurring. Any ideas?
    This error seems to be fixed in the latest 2.0.3 build(I got the one from 1/29/07)

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
  •