Announcement Announcement Module
Collapse
No announcement yet.
problem when transfering a pojo object by using hessian Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • problem when transfering a pojo object by using hessian

    Hi All,

    Here's the xml configuration and class definition of my environment.

    Code:
    <bean id="simpleObject" class="example.SimpleObject">
        	<property name="accountService" ref="hessianService"/>
        </bean>
        
    <bean id="hessianService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
        	<property name="serviceUrl" value="http://localhost:7080/spring/hessian/AccountService"/>
        	<property name="serviceInterface" value="example.AccountService"/>
    </bean>
    Code:
    package example;
    
    import java.util.*;
    
    public interface AccountService{
    	public Order getOrder(String id);
    	public Date getCurrentDate();
    }
    Code:
    package example;
    
    import java.util.*;
    
    public interface Order{
    	public Date getOrderDate();
    	public String getOrderId();
    }
    Code:
    package example;
    
    import java.util.*;
    
    public class AccountServiceImpl implements AccountService{
            public Order getOrder(String id){
                    Order order = new OrderImpl(id);
                    return order;
            }
            public Date getCurrentDate(){
                    return new Date();
            }
    }
    Code:
    package example;
    
    import java.io.*;
    import java.util.*;
    
    public class OrderImpl implements Order, Serializable{
            private String id;
            private Date date;
    
            public OrderImpl(String id){
                    this.id = id;
                    this.date = new Date();
            }
    
            public Date getOrderDate(){
                    return this.date;
            }
    
            public String getOrderId(){
                    return this.id;
            }
    }
    Here, in my class SimpleObject, I could call the method getCurrentDate() of instance accountService and get the correct result. But if I call getOrder("100"), it will remind me the following exception.

    java.lang.InstantiationException: example.Order
    at java.lang.Class.newInstance0(Class.java:293)
    at java.lang.Class.newInstance(Class.java:261)
    at com.caucho.hessian.io.JavaDeserializer.instantiate (JavaDeserializer.java:172)
    at com.caucho.hessian.io.JavaDeserializer.readMap(Jav aDeserializer.java:112)
    at com.caucho.hessian.io.HessianInput.readObject(Hess ianInput.java:662)
    at com.caucho.hessian.io.HessianInput.readReply(Hessi anInput.java:241)
    at com.caucho.hessian.client.HessianProxy.invoke(Hess ianProxy.java:179)
    at $Proxy0.getOrder(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at org.springframework.remoting.caucho.HessianClientI nterceptor.invoke(HessianClientInterceptor.java:11 5)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :170)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:176)
    at $Proxy1.getOrder(Unknown Source)
    at example.SimpleObject.printOrder(SimpleObject.java: 15)
    at example.SimpleObject.main(SimpleObject.java:23)
    Exception in thread "main" org.springframework.remoting.RemoteAccessException : Cannot access Hessian service at [http://localhost:7080/spring/hessian/AccountService]; nested exception is java.io.IOException: java.lang.InstantiationException: example.Order
    java.io.IOException: java.lang.InstantiationException: example.Order
    at com.caucho.hessian.io.JavaDeserializer.readMap(Jav aDeserializer.java:119)
    at com.caucho.hessian.io.HessianInput.readObject(Hess ianInput.java:662)
    at com.caucho.hessian.io.HessianInput.readReply(Hessi anInput.java:241)
    at com.caucho.hessian.client.HessianProxy.invoke(Hess ianProxy.java:179)
    at $Proxy0.getOrder(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at org.springframework.remoting.caucho.HessianClientI nterceptor.invoke(HessianClientInterceptor.java:11 5)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :170)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:176)
    at $Proxy1.getOrder(Unknown Source)
    at example.SimpleObject.printOrder(SimpleObject.java: 15)
    at example.SimpleObject.main(SimpleObject.java:23)

    Any hints?

    Thank you

  • #2
    Hi,

    I've never used the Hessian protocol but it looks from your stack trace that it's trying to construct an instance of the Order interface rather than the implementation class.

    I'd either look into the Hessian docs and see if it has anything to say about that, and/or change the service methods to remove the Order interface and just return the implementation.

    Jonny

    Comment


    • #3
      Originally posted by jwray
      Hi,

      I've never used the Hessian protocol but it looks from your stack trace that it's trying to construct an instance of the Order interface rather than the implementation class.

      I'd either look into the Hessian docs and see if it has anything to say about that, and/or change the service methods to remove the Order interface and just return the implementation.

      Jonny
      Hi jwray,

      Thank you. You're right. If I change the return type of method getOrder from interface Order to its implementation class OrderImpl could solve the problem.

      So that means I can hide the detail implementation class from its interface, right? Maybe I should design some adapters to transfer the objects.

      Thank you for your answer.

      Any hints about that?
      Last edited by henryzhou; Mar 2nd, 2006, 02:12 AM.

      Comment

      Working...
      X