客户端不使用Windows的JRE 1.7中的URLConnection发送回会话cookie [英] Session cookie not send back by client using URLConnection in windows with JRE 1.7

查看:97
本文介绍了客户端不使用Windows的JRE 1.7中的URLConnection发送回会话cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个使用Java Web Start部署的应用程序.它使用URLConnection与Servlet通信,并通过Cookies(JSESSIONID)管理会话. 它与Java 1.5& Java兼容. 1.6.在 windows 中使用Java 1.7后,它不再起作用:cookie JSESSIONID不会发送回服务器(我使用apache axis的HTTPMonitor看到了).怎么了?

We have an application that is deploied using Java Web Start. It communicate with a servlet using URLConnection and managing session by Cookies (JSESSIONID). It worked well with Java 1.5 & 1.6. With Java 1.7 in windows It doesn't work anymore: cookie JSESSIONID is not send back to the server (I saw this using apache axis's HTTPMonitor). What's going wrong?

可以从Linux盒中使用Java Web Start启动相同的应用程序.

Launching the same application with Java Web Start from a linux box works as expected.

版本为:具有Java Web Start 10.4.0.22_04的JRE 1.7.0_04

Version are: JRE 1.7.0_04 with Java Web Start 10.4.0.22_04

推荐答案

我们感到非常沮丧的是,从Eclipse启动时,我们的应用程序运行良好,但通过Web Start运行时,无法与经过身份验证的REST端点通信,由于问题中描述的问题,JSESSIONID丢失了.我们正在运行Java 1.7.

We were getting incredibly frustrated with the fact that our application worked fine when launched from Eclipse but failed to communicate with our authenticated REST endpoints, when run via Web Start, due to the JSESSIONID going missing as per the problem described in the question. We are running Java 1.7.

经过大量的远程调试后,我们发现无论是否有目的(我只能在上面找到很少的文档,例如,这里的一线:

After much remote debugging, we discovered that whether intentional or not (I can only find little documentation on it, e.g. a one-liner here: http://docs.oracle.com/javase/tutorial/networking/cookies/cookiehandler.html), a Java Web Start application sets a default CookieHandler, usually an instance of com.sun.deploy.net.cookie.DeployCookieSelector, but whatever this is, this messes up the JSESSIONID cookie handling. Reset the default cookie handler to null java.net.CookieHandler.setDefault(null) and voila, the outgoing HTTP requests have the JSESSIONID cookie preserved!

BTW Windows和Linux都表现出了这种行为.

BTW Windows and Linux both exhibited this behaviour.

这篇关于客户端不使用Windows的JRE 1.7中的URLConnection发送回会话cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆