5 Replies Latest reply: Mar 22, 2013 10:51 PM by 995593 RSS

    Cookie session id in one instance of webview affects other instance

    995593
      So my problem is that i want to use 2 instances of javafx2.2.7 webview at the same time in different containers(JFrame), so its embebed in a swing aplication.

      All goes well until you get session cookies, when this append if you are in the same website things start to go downhill.

      My guess is that the cookies are stored in the same instance of cookiehandler or some other class,so when one session cookie is changed so is the other runing on a diferent JFrame and in a diferent webview instance.

      Is there a way around this?

      Many Thanks
      André Bastos
        • 1. Re: Cookie session id in one instance of webview affects other instance
          peterz
          You can install your own cookie handler before you create WebViews. WebView won't replace whatever cookie handler is already installed.
          • 2. Re: Cookie session id in one instance of webview affects other instance
            995593
            Thank for your reply Peter,

            I´ve been pursuing your hint last night, but after some long hours analyzing this not sure if i know what you mean.

            How can i replace the cookiehandler, its an abstract class, i can extended it like the default cookiemanager, but i can´t force webview to use it or can i?

            Another thing, from this post:

            http://stackoverflow.com/questions/14385233/setting-a-cookie-using-javafxs-webengine-webview

            "Vasiliy also explained that WebView will install it's own implementation of the CookieHandler, while retaining cookies put into the default one."

            If this true, no matter what i do with the default cookiehandler this will not work, since webview will install it´s own implementation..

            It seems that someone forgot that an more than 1 webview instance could run at the same time, because the problem only arises if running in the same VM, in different VM it´s behaves as it should.

            If you have more toughts about this please share.

            Thanks
            • 3. Re: Cookie session id in one instance of webview affects other instance
              peterz
              WebView installs its own handler only if the default one is null, otherwise it won't replace the already installed one. CookieHandler is static -- that's why two WebViews share the same instance -- so you don't have to do anything special to make WebView aware of the handler. It will just use whatever handler is installed, as any code that uses HttpURLConnection would do.

              Still in your custom handler you'll have to somehow distinguish requests coming from two WebViews, that may be tricky given that the interface is simply
              Map get(URI uri, Map<String,List<String>> requestHeaders);
              • 4. Re: Cookie session id in one instance of webview affects other instance
                995593
                Yes, that´s what i understood when i was reading the interface cookiehandler, static.

                Very tricky stuff, and its really not my strong, cookies.
                But i only want this to work in one website, so i know the ulr for the cookies, i could add some code to differentiate the cookies to be able to have 2 or more of the same, but the problem is how do i get them back in the get method..

                Well, will think about this..If any thoughts about how to make this happen let me know.

                Thank you again Peter, this was helpful.
                • 5. Re: Cookie session id in one instance of webview affects other instance
                  995593
                  I found a way to overcome this problem by implementing a custom version of cookiemanager, although the original problem is not solved, i marked this as answered because it provided an solution to my question.