I am trying to test getting rid of gwt-rpc entrypoints and instead use JAX-RS / JSON based entrypoints.
To do this, I am simply using the native GWT RequestBuilder apis.
As per the documentation here referenced next. http://www.gwtproject.org/doc/latest/tutorial/JSON.html
The problem I am facing is that the compiler seems unhappy about letting me make use of any overlay API, namely any method that has no java code to be compiled and that is flagged as native.
I am of course using the latest, and greatest, gwt 2.8 compiler.
If I write my overlay as follows.
public class UserLoginGwtRpcMessageOverlay extends JavaScriptObject {
/**
* Mandatory PROTECTED no arguments constructor.
*/
protected UserLoginGwtRpcMessageOverlay() {
super();
}
public final native String getUserName(); /*
* { return userName; }
*/
public final native String getHashedPassword(); /*
* { return hashedPassword;
* }
*/
public final String toStringOverlay() {
return getUserName() + "-" + getHashedPassword();
}
The class will not compile. And it will not compile because my artifical toString is making use of the overlay APIs, e.g. ( getUserName()).
If I were to take those calls out of the class, it the compiler would not break handling the class.
Going further, If I try to make a rest call as follows:
private void invokeRestService() {
try {
// (a) prepare the JSON request to the server
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, JSON_URL);
// (b) send an HTTP Json request
Request request = builder.sendRequest(null, new RequestCallback() {
// (i) callback handler when there is an error
public void onError(Request request, Throwable exception) {
LOGGER.log(Level.SEVERE, "Couldn't retrieve JSON", exception);
}
// (ii) callback result on success
public void onResponseReceived(Request request, Response response) {
if (200 == response.getStatusCode()) {
UserLoginGwtRpcMessageOverlay responseOverlay = JsonUtils
.<UserLoginGwtRpcMessageOverlay>safeEval(response.getText());
LOGGER.info("responseOverlay: " + responseOverlay.getUserName());
} else {
LOGGER.log(Level.SEVERE, "Couldn't retrieve JSON (" + response.getStatusText() + ")");
}
}
});
} catch (RequestException e) {
LOGGER.log(Level.SEVERE, "Couldn't execute request ", e);
}
}
Again, the compilation shall fail. Once more this is the result of me trying to use the getUserName().
In particular, the followig line of code breaks the compiler.
LOGGER.info("responseOverlay: " + responseOverlay.getUserName());
Given that the compiler is running null pointer exceptions giving no other hint besides:
<no source info>: <source info not available>
I suspect I am dealing either with a compiler bug, or a feature that somehow got de-supported and whose APIs still linger. But at the same time, I would be surprised as I would assume overlays to be a core part of GWT, this should just work. So more likely I have some bug in the code I am not spotting.
QUOTE FULL compile error:
[INFO] --- gwt-maven-plugin:2.8.0:compile (gwt-compile) @ jntl-expenses-frontend --- [INFO] Compiling module org.gwtproject.tutorial.TodoList [INFO] Compiling 1 permutation [INFO] Compiling permutation 0... [INFO] [ERROR] An internal compiler exception occurred [INFO] com.google.gwt.dev.jjs.InternalCompilerException: Unexpected error during visit. [INFO] at com.google.gwt.dev.jjs.ast.JVisitor.translateException(JVisitor.java:111) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:276) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:265) [INFO] at com.google.gwt.dev.jjs.impl.MakeCallsStatic$CreateStaticImplsVisitor.visit(MakeCallsStatic.java:222) [INFO] at com.google.gwt.dev.jjs.ast.JMethod.traverse(JMethod.java:777) [INFO] at com.google.gwt.dev.jjs.ast.JVisitor.accept(JVisitor.java:127) [INFO] at com.google.gwt.dev.jjs.ast.JVisitor.accept(JVisitor.java:122) [INFO] at com.google.gwt.dev.jjs.impl.MakeCallsStatic$CreateStaticImplsVisitor.getOrCreateStaticImpl(MakeCallsStatic.java:240) [INFO] at com.google.gwt.dev.jjs.impl.Devirtualizer$RewriteVirtualDispatches.ensureDevirtualVersionExists(Devirtualizer.java:271) [INFO] at com.google.gwt.dev.jjs.impl.Devirtualizer$RewriteVirtualDispatches.endVisit(Devirtualizer.java:160) [INFO] at com.google.gwt.dev.jjs.ast.JMethodCall.traverse(JMethodCall.java:268) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.traverse(JModVisitor.java:361) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:273) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:265) [INFO] at com.google.gwt.dev.jjs.ast.JVisitor.accept(JVisitor.java:118) [INFO] at com.google.gwt.dev.jjs.ast.JBinaryOperation.traverse(JBinaryOperation.java:89) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.traverse(JModVisitor.java:361) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:273) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:265) [INFO] at com.google.gwt.dev.jjs.ast.JVisitor.accept(JVisitor.java:118) [INFO] at com.google.gwt.dev.jjs.ast.JExpressionStatement.traverse(JExpressionStatement.java:42) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor$ListContext.traverse(JModVisitor.java:88) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.acceptWithInsertRemove(JModVisitor.java:331) [INFO] at com.google.gwt.dev.jjs.ast.JBlock.traverse(JBlock.java:92) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.traverse(JModVisitor.java:361) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:273) [INFO] at com.google.gwt.dev.jjs.ast.JVisitor.accept(JVisitor.java:139) [INFO] at com.google.gwt.dev.jjs.ast.JIfStatement.traverse(JIfStatement.java:53) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor$ListContext.traverse(JModVisitor.java:88) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.acceptWithInsertRemove(JModVisitor.java:331) [INFO] at com.google.gwt.dev.jjs.ast.JBlock.traverse(JBlock.java:92) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.traverse(JModVisitor.java:361) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:273) [INFO] at com.google.gwt.dev.jjs.ast.JVisitor.accept(JVisitor.java:139) [INFO] at com.google.gwt.dev.jjs.ast.JVisitor.accept(JVisitor.java:135) [INFO] at com.google.gwt.dev.jjs.ast.JMethodBody.traverse(JMethodBody.java:83) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.traverse(JModVisitor.java:361) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:273) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:265) [INFO] at com.google.gwt.dev.jjs.ast.JMethod.visitChildren(JMethod.java:786) [INFO] at com.google.gwt.dev.jjs.ast.JMethod.traverse(JMethod.java:778) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor$ListContextImmutable.traverse(JModVisitor.java:169) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.acceptWithInsertRemoveImmutable(JModVisitor.java:336) [INFO] at com.google.gwt.dev.jjs.ast.JClassType.traverse(JClassType.java:147) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.traverse(JModVisitor.java:361) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:273) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:265) [INFO] at com.google.gwt.dev.jjs.ast.JProgram.visitModuleTypes(JProgram.java:1284) [INFO] at com.google.gwt.dev.jjs.ast.JProgram.traverse(JProgram.java:1249) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.traverse(JModVisitor.java:361) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:273) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:265) [INFO] at com.google.gwt.dev.jjs.impl.Devirtualizer.execImpl(Devirtualizer.java:409) [INFO] at com.google.gwt.dev.jjs.impl.Devirtualizer.exec(Devirtualizer.java:324) [INFO] at com.google.gwt.dev.jjs.JavaToJavaScriptCompiler.normalizeSemantics(JavaToJavaScriptCompiler.java:489) [INFO] at com.google.gwt.dev.jjs.JavaToJavaScriptCompiler.compilePermutation(JavaToJavaScriptCompiler.java:364) [INFO] at com.google.gwt.dev.jjs.JavaToJavaScriptCompiler.compilePermutation(JavaToJavaScriptCompiler.java:272) [INFO] at com.google.gwt.dev.CompilePerms.compile(CompilePerms.java:198) [INFO] at com.google.gwt.dev.ThreadedPermutationWorkerFactory$ThreadedPermutationWorker.compile(ThreadedPermutationWorkerFactory.java:50) [INFO] at com.google.gwt.dev.PermutationWorkerFactory$Manager$WorkerThread.run(PermutationWorkerFactory.java:74) [INFO] at java.lang.Thread.run(Thread.java:745) [INFO] Caused by: java.lang.NullPointerException [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.traverse(JModVisitor.java:361) [INFO] at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:273) [INFO] ... 59 more [INFO] [ERROR] : [INFO] [ERROR] at UserLoginGwtRpcMessageOverlay.java(23): org.gwtproject.tutorial.client.overlay.UserLoginGwtRpcMessageOverlay.getUserName()Ljava/lang/String; [INFO] com.google.gwt.dev.jjs.ast.JMethod [INFO]
[ERROR] at TodoList.java(148): responseOverlay.getUserName() [INFO]
com.google.gwt.dev.jjs.ast.JMethodCall [INFO] [ERROR] at TodoList.java(148): "responseOverlay: " + responseOverlay.getUserName() [INFO]
com.google.gwt.dev.jjs.ast.JBinaryOperation [INFO] [ERROR] at TodoList.java(148): "responseOverlay: " + responseOverlay.getUserName() [INFO]
com.google.gwt.dev.jjs.ast.JExpressionStatement [INFO]
[ERROR] at TodoList.java(145): { [INFO] final UserLoginGwtRpcMessageOverlay responseOverlay = (UserLoginGwtRpcMessageOverlay) JsonUtils.safeEval(response.getText()); [INFO] TodoList.$clinit(); [INFO] "responseOverlay: " + responseOverlay.getUserName(); [INFO] } [INFO] com.google.gwt.dev.jjs.ast.JBlock [INFO]
[ERROR] at TodoList.java(145): if (200 == response.getStatusCode()) { [INFO] final UserLoginGwtRpcMessageOverlay responseOverlay = (UserLoginGwtRpcMessageOverlay) JsonUtils.safeEval(response.getText()); [INFO] TodoList.$clinit(); [INFO] "responseOverlay: " + responseOverlay.getUserName(); [INFO] } else { [INFO] TodoList.$clinit(); [INFO] Level.$clinit(); [INFO]
"Couldn\'t retrieve JSON (" + response.getStatusText() + ")"; [INFO] } [INFO] com.google.gwt.dev.jjs.ast.JIfStatement [INFO]
[ERROR] at TodoList.java(144): { [INFO] if (200 == response.getStatusCode()) { [INFO] final UserLoginGwtRpcMessageOverlay responseOverlay = (UserLoginGwtRpcMessageOverlay) JsonUtils.safeEval(response.getText()); [INFO] TodoList.$clinit(); [INFO] "responseOverlay: " + responseOverlay.getUserName(); [INFO] } else { [INFO] TodoList.$clinit(); [INFO] Level.$clinit(); [INFO] "Couldn\'t retrieve JSON (" + response.getStatusText() + ")"; [INFO] } [INFO] } [INFO]
com.google.gwt.dev.jjs.ast.JBlock [INFO] [ERROR] at TodoList.java(144): { [INFO] if (200 == response.getStatusCode()) { [INFO] final UserLoginGwtRpcMessageOverlay responseOverlay = (UserLoginGwtRpcMessageOverlay) JsonUtils.safeEval(response.getText()); [INFO] TodoList.$clinit(); [INFO] "responseOverlay: " + responseOverlay.getUserName(); [INFO] } else { [INFO] TodoList.$clinit(); [INFO] Level.$clinit(); [INFO] "Couldn\'t retrieve JSON (" + response.getStatusText() + ")"; [INFO] } [INFO] } [INFO]
com.google.gwt.dev.jjs.ast.JMethodBody [INFO] [ERROR] at TodoList.java(144): org.gwtproject.tutorial.client.TodoList$3.onResponseReceived(Lcom/google/gwt/http/client/Request;Lcom/google/gwt/http/client/Response;)V [INFO] com.google.gwt.dev.jjs.ast.JMethod [INFO]
[ERROR] at TodoList.java(136): org.gwtproject.tutorial.client.TodoList$3 (final extends Object implements RequestCallback) [INFO]
com.google.gwt.dev.jjs.ast.JClassType [INFO] [ERROR] at Unknown(0): [INFO]
com.google.gwt.dev.jjs.ast.JProgram
Is anyone else experiencing problems in GWT 2.8 with overlays, or am I making some sort of mistake of which I am not aware.
Kind regards, Any good pointer is appreciated.