cincheo / jsweet

A Java to JavaScript transpiler.
http://www.jsweet.org
Other
1.46k stars 158 forks source link

JaxRS client #101

Closed gege-fr closed 8 years ago

gege-fr commented 8 years ago

Hi, i just discovered jsweet and it seems promising. I have a question : is there a way to consume JaxRS services ?

Since one point of having java to code the web page is to also have java server-side. I don't know if i'm alone but I think it's worth thinking about.

Maybe by generating jsweet wrapper over a maven-generated js or ts client ? Or re-using the pojos and parsing the jaxrs service definition and pojos ? Or generating a client from wadl ?

Well, I wanted to raise this topic.

lgrignon commented 8 years ago

Woah, what a fast guy! :)

I will give it a try this week-end. Seems a promising project.

Thanks for your contribution to JSweet.

renaudpawlak commented 8 years ago

@GegeFR: there seem to be some regressions in JSweet because of latest improvements... So it will be hard for me to find the time to test it in the coming days. I will tell you when I find the right time. You are indeed quite fast ;)

gege-fr commented 8 years ago

Don't worry take your time. I'll also try to use it in a small "real life" personnal project. Need to do a porfolio for my kitchen designer of a wife :-) I wanted to use a jsweet / jaxrs / mongo stack an see if all's falling in place easily or not.

gege-fr commented 8 years ago

Sorry i have a (probably) dumb question : what are jsweet's limitations regarding the packages (java packages in the java source code) ?

It seems like I cant transpile any java code if it uses a class that is not in the same package. I re-read the language specifications but I probably missed something ...

EDIT : It works if i put the complete name of the class (with the package). EDIT2 : Even worse, your example with packages (blocksgame) transpiles ...

renaudpawlak commented 8 years ago

No. There are no specific limitations regarding to packages at compile time. What you describe is either a bug or a misunderstanding.

On the other hand, what you describe seems related to a typical problem at runtime with JavaScript. Typically, if you refer to a class that has not been yet declared, it will fail.

Maybe you could give us more information on what you are trying to do here?

gege-fr commented 8 years ago

Given the two following classes

package jsweet.client;
import jsweet.client.util.Toto;
public class Portfolio {
    public static void main(String[] args) {
        Toto toto = new Toto();
    }
}
package jsweet.client.util;
public class Toto {
}

I get the following error when building :

JSweet transpiler version 1.1.0-SNAPSHOT (build date: 2016-04-15 15:05:10)
WARN: candy jquery:1.10.0-1.0.0-20160202 was generated for a different version of the transpiler (current:1.1.0, candy:1.0.0)
WARN: candy jsweet-core:1.0.0-2016-01-22-1.0.0 was generated for a different version of the transpiler (current:1.1.0, candy:${pom.version})
WARN: candy bootstrap.datepicker:0.0.0-1.0.0-20160202 was generated for a different version of the transpiler (current:1.1.0, candy:1.0.0)
WARN: candy bootstrap:3.3.5-1.0.0-20160202 was generated for a different version of the transpiler (current:1.1.0, candy:1.0.0)
ERROR: cannot find name 'Toto' at D:\Workspace\CuisinesDartyLannion-frontend\src\main\java\jsweet\client\Portfolio.java(9)
ERROR: cannot find name 'Toto' at D:\Workspace\CuisinesDartyLannion-frontend\src\main\java\jsweet\client\Portfolio.java(9)
transpilation failed
org.apache.maven.plugin.MojoFailureException: transpilation failed with 2 error(s) and 4 warning(s)
    at org.jsweet.AbstractJSweetMojo.transpile(AbstractJSweetMojo.java:304)
    at org.jsweet.JSweetMojo.execute(JSweetMojo.java:41)
gege-fr commented 8 years ago

Oh ... I think I found, that's because my package name is beginning with "jsweet." , isn't it ?

renaudpawlak commented 8 years ago

YES! I was writing a response when I got your answer!!! The jsweet package is not allowed but does not raise any error (that would be a good enhancement). Please don't use jsweet as a package name. Also, watch out Globals classes, they have a special meaning. I'll create an issue.

gege-fr commented 8 years ago

I'll change the package of my generated swagger client : it was jsweet.client ... ;-)

renaudpawlak commented 8 years ago

see #113 thanks!

gege-fr commented 8 years ago

update :

incoming :

gege-fr commented 8 years ago

Done. Now sample project is tad simpler. Feedback will be welcomed ! :-)

renaudpawlak commented 8 years ago

See #100 for GWT Java emulation update.