javaspringsessionhessianspring-remoting

Maintaining HTTP session between Hessian web service calls in Spring


I've set up my services as per Spring remoting documentation, but in the client applications I'd like to invoke service methods while reusing the same HTTP session as I'd like to store session related data on the server (instead of querying for that data on every call).

Is this possible?

Client side spring service configuration:

<bean id="partnersServiceImpl" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
    <property name="serviceUrl" value="http://localhost:8080/partners" />
    <property name="serviceInterface" value="somePackage.PartnersService" />
</bean>

Currently every method called generates a new sessionID:

PartnersService partners = (PartnersService) context.getBean("partnersServiceImpl");

List<?> partnersList = partners.getSomeData(2011); // Will have one SessionID
partnersList = partners.getSomeData(2012); // Will have a new SessionID

Solution

  • Try to put this code at the very start of you application:

    CookieHandler.setDefault( new CookieManager( null, CookiePolicy.ACCEPT_ALL ) );
    

    It is a simple setup for cookies support activation. See the javadocs for more information. I have a Hessian remoting too and this is what did the trick.