generated JS issue in Chrome, but not built-in browser

25 views
Skip to first unread message

erd

unread,
May 18, 2016, 2:05:02 PM5/18/16
to DukeScript
Hello,

I filled out most of the Plotly.js API in Dukescript (found here), and I would like to get it functioning in 'real' browsers. The 'sample' code runs perfectly fine in the minimal Netbeans built-in java web browser, but upon running the web-client BrowserMain, the charts do not appear. Knockout seems to initialize, but all of the chart <div>'s are empty. 

Upon loading, this is the log that appears.

Failed to load resource: the server responded with a status of 404 (Not Found)
Failed to load resource: the server responded with a status of 404 (Not Found)
Failed to load resource: the server responded with a status of 404 (Not Found)
Failed to load resource: the server responded with a status of 404 (Not Found)
Failed to load resource: the server responded with a status of 404 (Not Found)
Failed to load resource: the server responded with a status of 404 (Not Found)
Failed to load resource: the server responded with a status of 404 (Not Found)
Failed to load resource: the server responded with a status of 404 (Not Found)
Failed to load resource: the server responded with a status of 404 (Not Found)
Failed to load resource: the server responded with a status of 404 (Not Found)
Uncaught TypeError: Cannot read property 'clone__Ljava_lang_Object_2' of null


First things first, I noticed the page is looking in /lib/lib for the generated JS files. the strange part is that if I comment out the affecting line, it will look in ./ , but if I leave it as is, it will search in /lib/lib. Maybe I'm confused about how the packaging is supposed to work.  There's also that last TypeError. If anyone happens to know what is causing either of these, let me know!

Thanks,
-Evan

erd

unread,
May 18, 2016, 2:18:43 PM5/18/16
to DukeScript
I should also add that dropping the files manually into their correct locations obviously makes the 404's go away, but the problem still persists, so I suppose it's the TypeError causing the problem.

erd

unread,
May 18, 2016, 6:01:12 PM5/18/16
to DukeScript
I fixed the 404's by making the classpath prefix just '/'.  

After some sleuthing, I figured out the TypeError is caused by Jackson, but I'm still unsure of how to fix it. More specifically, invoking ObjectMapper breaks everything, eg

static private ObjectMapper mapper = new ObjectMapper();



Jaroslav Tulach

unread,
May 18, 2016, 11:58:58 PM5/18/16
to dukes...@googlegroups.com, erd
### erd : 18. 5. 2016 @ 11:05 ###
> First things first, I noticed the page is looking in /lib/lib for the
> generated JS files. the strange part is that if I comment out the affecting
> line
> <https://github.com/daykin/dukescript-plotlyjs/blob/master/PlotlySample/clie
> nt-web/pom.xml#L68>, it will look in ./ , but if I leave it as is, it will
> search in /lib/lib. Maybe I'm confused about how the packaging is supposed
> to work.

This is caused by the main JAR produced by client-web project having Class-
Path and also the JAR produced by client project having Class-Path attribute
as well. The warning is unfortunate, but harmless.

-jt



Jaroslav Tulach

unread,
May 19, 2016, 12:11:30 AM5/19/16
to dukes...@googlegroups.com, erd
### erd : 18. 5. 2016 @ 15:01 ###
Are you sure you want to use Jackson? Why? You are in a browser, there are
cheaper ways to parse JSON. Direct

@JavaScriptBody(body="return JSON.parse(t)", args={"t"})
static Object parseJSON(String t);

@JavaScriptBody(body="return json[p]", args={"json", "p"})
static Object getProp(Object json, String p);

Or, if you really want to model the JSON with Java classes, then @Model
annotation and classes it generates has been designed for that. Similar to
https://dukescript.com/update/2015/01/27/ParsingJSON.html but directly in
browser.

In any case it should be more lightweight than parsing via special Java
library.
-jt

Jaroslav Tulach

unread,
May 19, 2016, 12:28:58 AM5/19/16
to dukes...@googlegroups.com, erd, bck2...@apidesign.org
### erd : 18. 5. 2016 @ 15:01 ###
If you right click on "client-web" project and do "Clean" and then once again
and select "Debug", you'll be able to see reasonable code in the browser.

I used chromium with "Pause on Exceptions" being true and this is the
stacktrace:

invoker.clone__Ljava_lang_Object_2 (emul-0.19-rt.js:256614)
c.getDefault__Ljava_util_TimeZone_2 (emul-0.19-rt.js:102513)
c.initializeCalendar__VLjava_util_Locale_2 (emul-0.19-rt.js:56142)
CLS.cons__VLjava_lang_String_2Ljava_util_Locale_2 (emul-0.19-rt.js:55950)
c.class__V (jackson-databin…2.6.3.js:44848)
com_fasterxml_jackson_databind_util_StdDateFormat (jackson-databin…
2.6.3.js:44885)
c.class__V (jackson-databin…2.6.3.js:43935)
com_fasterxml_jackson_databind_ObjectMapper (jackson-databin…2.6.3.js:43962)
loadClass (bck2brwsr.js:163)
(anonymous function) (dukescript-plot…SNAPSHOT.js:21)
c.class__V (dukescript-plot…PSHOT.js:17248)
net_java_html_plotlyjs_Plotly (dukescript-plot…PSHOT.js:17275)
loadClass (bck2brwsr.js:163)
(anonymous function) (PlotlySample-1.…SNAPSHOT.js:33)
c.onPageLoad__V (PlotlySample-1.…NAPSHOT.js:868)
c.onPageLoad__V (PlotlySample-1.…APSHOT.js:2184)
c.main__V_3Ljava_lang_String_2 (mainclass.js:67)
invokeMethod (bck2brwsr.js:47)
extensionLoaded (bck2brwsr.js:33)

Looks like java.util.TimeZone.getDefault() isn't implemented properly in
bck2brwsr. Do you want to help me fix it? If so, the code is here:
http://source.apidesign.org/hg/bck2brwsr/file/9d46ae9d4a2e/rt/emul/compact/src/main/java/java/util/TimeZone.java#l615
Probably the best way to start is to copy one of the tests at
http://source.apidesign.org/hg/bck2brwsr/file/9d46ae9d4a2e/rt/emul/compacttest/src/test/java/org/apidesign/bck2brwsr/tck
and show that there is a difference between TimeZone.getDefault() on HotSpot
and on bck2brwsr VM. And then fix it.

-jt

PS: I tried to use "Custom->Run in Browser via TeaVM", but TeaVM is out of
lack as jackson uses quite a lot of reflection and it cannot handle it.





Jaroslav Tulach

unread,
May 19, 2016, 1:18:58 AM5/19/16
to dukes...@googlegroups.com, erd
### Jaroslav Tulach : 19. 5. 2016 @ 06:28 ###
> Looks like java.util.TimeZone.getDefault() isn't implemented properly in
> bck2brwsr. Do you want to help me fix it? If so, the code is here:
> http://source.apidesign.org/hg/bck2brwsr/file/9d46ae9d4a2e/rt/emul/compact/s
> rc/main/java/java/util/TimeZone.java#l615


Looking at the code it seems that calling Timezone.setDefault early on would
help. Maybe it is the quickest workaround.
-jt

Jaroslav Tulach

unread,
May 20, 2016, 12:07:00 AM5/20/16
to Evan Daykin, Anton Epple, DukeScript
Hello Evan.

### Evan Daykin : 19. 5. 2016 @ 12:53 ###
> Looks great, but one more question. Plotly is generally flexible with
> leaving most values unset, and defaulting them. Is there a way to leave
> some values null and let Plotly take care of it? eg

Yes, the String property can be null.

>
> @Model(className = "Point", targetId="", properties = {
> @Property(name = "x", type = double.class),
> @Property(name = "y", type = double.class),
> @Property(name = "color", type = String.class)
> })
> //other stuff...
> point = new Point(0,0);
> point.applyBindings();
> //pass point.toString() to javascript JSON.parse, plotly defaults color

Maybe you don't want to call applyBindings, but rather

Object js = Model.toRaw(new Point());

that will give use a raw JavaScript that you can pass to plotly.
-jt


>
> On Thu, May 19, 2016 at 1:32 AM, Anton Epple <toni....@eppleton.de> wrote:
> > I can confirm that. "Mutable=false" helped me a lot when dealing with the
> > charts in Oracle JET.
> > Even though JET is build on knockout, their Charts also expect „plain"
> > JavaScript values instead of the functions normally created with DS.
> > Here’s an example:
> >
> > https://github.com/dukescript/dsjetski/blob/master/client/src/main/java/co
> > m
> > /dukescript/test/DukeScriptJetStart/DataModel.java
> > <https://github.com/dukescript/dsjetski/blob/master/client/src/main/java/c
> > om/dukescript/test/DukeScriptJetStart/DataModel.java>
> >
> >
> > —Toni

Jaroslav Tulach

unread,
May 20, 2016, 12:09:00 AM5/20/16
to erd, dukes...@googlegroups.com, bck2...@apidesign.org
Here is the fix of TimeZone.getDefault() to return something:
http://source.apidesign.org/hg/bck2brwsr/rev/4b7ef2a05eb7
-jt

### Jaroslav Tulach : 19. 5. 2016 @ 06:28 ###
Reply all
Reply to author
Forward
0 new messages