2016-11-24 11 views
0

gwt-rpcのエントリポイントを削除し、代わりにJAX-RS/JSONベースのエントリポイントをテストしようとしています。メソッドが使用されるたびにGwt Overlayコンパイルエラーが発生する

これを行うには、単純にネイティブ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(); 
    } 

クラスはコンパイルされません。 私のartifical toStringがオーバーレイAPIを使用しているため、コンパイルされません。 (getUserName())。

これらの呼び出しをクラスから取り除くと、コンパイラはそのクラスの処理を中断しません。

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); 
     } 
    } 

ここでも、コンパイルは失敗しなければならない。私は次のようにREST呼び出しをしようとした場合

は、さらに行きます。 もう一度これが私にgetUserName()を使用しようとした結果です。

特に、次のコード行はコンパイラを壊します。コンパイラはほかに他のヒントを与えていないnullポインタ例外を実行していることを考えると

LOGGER.info("responseOverlay: " + responseOverlay.getUserName()); 

<no source info>: <source info not available> 

私はどちらかのコンパイラのバグ、または何らかの形で非サポートしまった機能を取り扱っております疑うとそのAPIはまだ残っています。しかし同時に、オーバーレイがGWTの中核部分であると想定しているので、私は驚くでしょう。これはちょうどうまくいくはずです。だから私は目にしていないコードにいくつかのバグがある可能性が高いです。

QUOTE FULLコンパイルエラー:

[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で問題が発生して他の誰ですか、私は知りませんその間違いのいくつかの並べ替えを作っています。

親切に、 良いポインタがありがとうございます。

答えて

2
public final native String getUserName(); /* 
              * { return userName; } 
              */ 

これは有効なJSNI(getHashedPassword()と同じ問題)です。これを書くための正しい方法は

public final native String getUserName() /*-{ 
    return userName; 
}-*/; 

だろうあなたは/*-{で始まり、}-*/;で終わり、とのJavadocテーストわたってるしき*秒を持っていなければなりません。

しかし、JSとして、それは意味をなさないので、コンパイルする間、あなたが望むものではありません。 JavaがないようにJSが暗黙のthisを持っていないので、メソッドの本体は

return this.userName; 

をお読みください。

一見すると、残りは大丈夫ですが、合法的なJSNIがなければ、コンパイラはそれを受け入れることができません。

+0

パーフェクト。 私は今晩それを試します。 問題についての私の無知を告白します。 私は通常のPOJOから始まり、コメントとともにEclipseから自動生成されたゲッターをスライスし始めました。今私は、セミコロンが最後に来ることは恣意的ではないことを知っています。 多くのthnks。 – 99Sono

+0

正常に動作します。ありがとう。 – 99Sono

関連する問題