我想測試擺脫gwt-rpc入口點,而是使用基於JAX-RS/JSON的入口點。Gwt覆蓋每當方法得到使用時編譯錯誤
爲此,我只使用本機GWT RequestBuilder API。
根據下面引用的文檔。 http://www.gwtproject.org/doc/latest/tutorial/JSON.html
我面臨的問題是,編譯器似乎不滿意讓我使用任何覆蓋API,即任何沒有Java代碼編譯和標記爲本機的方法。
我當然使用最新的,最好的gwt 2.8編譯器。
如果我按照以下方式編寫我的覆蓋圖。
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();
}
該類不會編譯。 它不會編譯,因爲我的人工toString正在使用覆蓋API,例如, (getUserName())。
如果我將這些調用從類中取出,編譯器不會中斷處理類。
的進一步深入,如果我試圖做一個REST調用如下:
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);
}
}
再次,編制,應當失敗。 再次,這是我嘗試使用getUserName()的結果。
特別是,下面的代碼行破壞了編譯器。
LOGGER.info("responseOverlay: " + responseOverlay.getUserName());
由於編譯器運行的空指針異常給沒有其他提示,除了:
<no source info>: <source info not available>
我懷疑我處理或者與編譯器bug,或者一個功能,不知怎麼去支持,其API仍然流連忘返。但是與此同時,我會感到驚訝,因爲我認爲覆蓋是GWT的核心部分,這應該是正常的。所以我更有可能在我沒有發現的代碼中存在一些錯誤。
QUOTE完整的編譯錯誤:
[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
是任何人都經歷GWT 2.8問題疊加,還是我做某種錯誤的,其中我不知道。
親切的問候, 任何好的指針表示讚賞。
完美。 今天晚上我會試試。 並執行我對這個問題的無知。 我從一個普通的POJO開始,並開始從eclipse中使用註釋切片自動生成的gettters。現在我發現分號出現在最後並不是任意的。 許多thnks。 – 99Sono
工作正常。謝謝。 – 99Sono