Java FX Browser

Questions, answers, tips and ideas on Servoy Client

Java FX Browser

Postby d.pearce1417196993 » Sat Nov 26, 2016 6:49 pm

Has anyone managed to find the code to allow cookies to work within the Java FX browser in smart client.

I have an application which I want to embed zoho reports and it works fine in developer, but on the same machine i get:

"Note: Cookie is disable in your browser. Please enable the cookie to continue."

I tried some code to try and activate the cookie store when creating the browser in my code, but that creates an error.

Its odd that it works in developer on the same machine. Just to be safe I have tried running the solution in the server once so it gets the cookie, thinking (stupidly) that that might have an effect.

Just wondered if any had any code to allow cookies to be set by the URL i am going to within Java FX when creating the browser engine. It doesnt appear to be in the module i downloaded from servoy.

Thanks

David
d.pearce1417196993
 
Posts: 16
Joined: Fri Nov 28, 2014 7:49 pm

Re: Java FX Browser

Postby d.pearce1417196993 » Wed Nov 30, 2016 11:00 am

Just to add where we have got to, and are failing:
Code: Select all
var Platform = Packages.javafx.application.Platform,
      WebView = Packages.javafx.scene.web.WebView,
      Scene = Packages.javafx.scene.Scene,
      Runnable = java.lang.Runnable,
      ChangeListener = Packages.javafx.beans.value.ChangeListener,
      State = Packages.javafx.concurrent.Worker.State,
      CookieHandler=java.net.CookieHandler,
      CookieStore=java.net.CookieStore,
      CookiePolicy=java.net.CookiePolicy,
      CookieManager=java.net.CookieManager

   var latch = new java.util.concurrent.CountDownLatch(1)
   //Setup the UI for the JFXWebViewPanel
   Platform.runLater(new Runnable({
      run: function() {
         try {
            browser = new WebView();
            webEngine = browser.getEngine()               
            cookieStore=new CookieStore();
            cookiePolicy=new CookiePolicy();
            cookieManager=new CookieManager(cookieStore, cookiePolicy);
            CookieHandler.setDefault(cookieManager);
   


We added this code to the normal JavaFX declaration for the web engine. Just to emphasize we are only bastardising other peoples code and are not Java people!!!

We get this error:
Code: Select all
ERROR InternalError: error instantiating (0): class java.net.CookieStore is interface or abstract (/Users/davidpearce/Servoy_Workspace_Nephos748/svyJFXWebView/forms/JFXWebViewPanel_cookies.js#174)
InternalError: error instantiating (0): class java.net.CookieStore is interface or abstract (/Users/davidpearce/Servoy_Workspace_Nephos748/svyJFXWebView/forms/JFXWebViewPanel_cookies.js#174)
   at /Users/davidpearce/Servoy_Workspace_Nephos748/svyJFXWebView/forms/JFXWebViewPanel_cookies.js:174

As always, you feel you are on the right track but just not quite their.

Can anyone point us to whether we are completely in the wrong direction or maybe we have just declared the CookieStore variable wrongly! I am so naive I even put Packages. before the variable declarations, but that made no difference !.

Any help or suggestions welcome.

David
d.pearce1417196993
 
Posts: 16
Joined: Fri Nov 28, 2014 7:49 pm

Re: Java FX Browser

Postby IT2Be » Wed Nov 30, 2016 12:17 pm

The CookieStore is an Abstract Class or an Interface that means that there must be (or else you have to create it yourself) a class extending or interfacing that CookieStore class/interface.

An Abstract Class or Interface can not be instantiated so this is where you go wrong: 'cookieStore=new CookieStore();'

Where is that code sample that you picked this up from?
Marcel J.G. Trapman (IT2BE)
SAN partner - Freelance Java and Servoy
Servoy Components - IT2BE Plug-ins and Beans for Servoy
ServoyForge - Open Source Components for Servoy
User avatar
IT2Be
Servoy Expert
 
Posts: 4763
Joined: Tue Oct 14, 2003 7:09 pm
Location: Germany

Re: Java FX Browser

Postby d.pearce1417196993 » Wed Nov 30, 2016 12:52 pm

Thanks marcel,

I got a bit further by using the default in memory cookie store. I am trying to get a zoho report to show in my solution.
It now shows the login panel, but then tells me to reload the page, every time i login, so its a step forward, but still no joy.
I thought it might be the policy, so I think I am now setting that correctly to "CookiePolicy.ACCEPT_ALL"
The only other thing I can think is having a non memory cookie store, but I am not sure that that is the problem and there doesnt appear to be an easy way to set one. If I did I can see it would be in the CookieManager() class, but not sure whether you can just set a location.

Code: Select all
var Platform = Packages.javafx.application.Platform,
      WebView = Packages.javafx.scene.web.WebView,
      Scene = Packages.javafx.scene.Scene,
      Runnable = java.lang.Runnable,
      ChangeListener = Packages.javafx.beans.value.ChangeListener,
      State = Packages.javafx.concurrent.Worker.State,
      CookieHandler=java.net.CookieHandler,
      CookieStore=java.net.CookieStore,
      CookiePolicy=java.net.CookiePolicy,
      CookieManager=java.net.CookieManager

   var latch = new java.util.concurrent.CountDownLatch(1)
   //Setup the UI for the JFXWebViewPanel
   Platform.runLater(new Runnable({
      run: function() {
         try {
            browser = new WebView();
            webEngine = browser.getEngine()   
            cookieManager=new CookieManager();
            cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL)
            CookieHandler.setDefault(cookieManager)
            cookieStore=cookieManager.getCookieStore()
            
            application.output('CookieStore'+cookieStore)
d.pearce1417196993
 
Posts: 16
Joined: Fri Nov 28, 2014 7:49 pm

Re: Java FX Browser

Postby IT2Be » Wed Nov 30, 2016 1:15 pm

I am a bit busy right now so I can only give you pointers.

Are there properties/setters available for that CookieStore?
Or can you override them?
Marcel J.G. Trapman (IT2BE)
SAN partner - Freelance Java and Servoy
Servoy Components - IT2BE Plug-ins and Beans for Servoy
ServoyForge - Open Source Components for Servoy
User avatar
IT2Be
Servoy Expert
 
Posts: 4763
Joined: Tue Oct 14, 2003 7:09 pm
Location: Germany

Re: Java FX Browser

Postby d.pearce1417196993 » Wed Nov 30, 2016 1:42 pm

Looking into it. it is a bit weird in that it doesnt appear to have any properties to set the location of a real one. Almost looks like you need to subclass somehow.
The odd thing is i dont see why zoho shouldnt work with an in memory store, which i definitely now have as i dont get the original error saying cant set cookies!
d.pearce1417196993
 
Posts: 16
Joined: Fri Nov 28, 2014 7:49 pm

Re: Java FX Browser

Postby IT2Be » Wed Nov 30, 2016 1:49 pm

That could be the reason that this is an Abstract or an Interface (which is it btw?) so you can create your own class of off it...
Marcel J.G. Trapman (IT2BE)
SAN partner - Freelance Java and Servoy
Servoy Components - IT2BE Plug-ins and Beans for Servoy
ServoyForge - Open Source Components for Servoy
User avatar
IT2Be
Servoy Expert
 
Posts: 4763
Joined: Tue Oct 14, 2003 7:09 pm
Location: Germany


Return to Servoy Client

Who is online

Users browsing this forum: No registered users and 2 guests

cron