Session cookie not send back by client using URLConnection in windows with JRE 1.7

余生颓废 提交于 2020-01-04 08:05:10

问题


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?

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

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


回答1:


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 and Linux both exhibited this behaviour.



来源:https://stackoverflow.com/questions/11010592/session-cookie-not-send-back-by-client-using-urlconnection-in-windows-with-jre-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!