简体   繁体   中英

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

Check out the source code of HessianProxy.sendRequest() - it uses standard URLConnection to connect to server and does not handle any cookies. Thus I believe Hessian has no support for cookies at all. After all HTTP is just a transport protocol, while cookies are strictly browser-related technology.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM