2012-05-06 19 views
0

またはこれをGWTにアーカイブするにはどうすればよいでしょうか。RequestFactoryを使用してJSON-RPCサービスを呼び出す方法

RequestFactoryを使用してパラメータを持つ簡単なサービスを呼び出す方法のコードを投稿してください。

更新日:

トーマス、あなたの提案で自分のコードを更新しました。このコードはで失敗

public interface MyRequestFactory extends RequestFactory { 
    MyRequestFactory INSTANCE = GWT.create(MyRequestFactory.class); 

    MyRequestContext myRequestContest(); 
} 

@JsonRpcService 
public interface MyRequestContext extends RequestContext { 

    UserFullFormattedName userFullFormattedName(); 

    @JsonRpcWireName(value = "GetUserFullFormattedName") 
    public interface UserFullFormattedName extends Request<String> { 
    } 
} 

public static EventBus EVENT_BUS = GWT.create(SimpleEventBus.class); 

public void onModuleLoad() { 

    DefaultRequestTransport requestTransport = new DefaultRequestTransport(); 
    requestTransport.setRequestUrl("../services/service.ashx"); 

    MyRequestFactory.INSTANCE.initialize(EVENT_BUS, requestTransport); 

    MyRequestFactory.INSTANCE.myRequestContext().userFullFormattedName().fire(new Receiver<String>() { 

     @Override 
     public void onSuccess(String response) { 
      System.out.println(response); 

     } 
    }); 

11:37:49.722 [ERROR] [modules] Uncaught exception escaped 
java.lang.AssertionError: java.lang.String is not an EntityProxy type 
    at com.google.web.bindery.requestfactory.shared.impl.IdFactory.asEntityProxy(IdFactory.java:66) 
    at com.google.web.bindery.requestfactory.shared.impl.IdFactory.createId(IdFactory.java:229) 
    at com.google.web.bindery.requestfactory.shared.impl.IdFactory.allocateId(IdFactory.java:41) 
    at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext$JsonRpcPayloadDialect.processPayload(AbstractRequestContext.java:251) 
    at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext$5.onTransportSuccess(AbstractRequestContext.java:1108) 
    at com.google.web.bindery.requestfactory.gwt.client.DefaultRequestTransport$1.onResponseReceived(DefaultRequestTransport.java:136) 
    at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287) 
    at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:395) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) 
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) 
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172) 
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337) 
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218) 
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136) 
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561) 
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269) 
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91) 
    at com.google.gwt.core.client.impl.Impl.apply(Impl.java) 
    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) 
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) 
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172) 
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292) 
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546) 
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363) 
    at java.lang.Thread.run(Unknown Source) 
+0

あなたがしようとしていることが不可能なだけでなく、意味をなさない。 –

+0

絶対に間違っています! –

+0

エドゥアルド、あなたが試したこととあなたがそれを持っていた問題を分かち合うことができますか? –

答えて

1

Cat@JsonRpcProxyで注釈を付けValueProxy次のようになります。

@JsonRpcProxy 
interface Cat extends ValueProxy { 
    String getName(); 
    String getId(); 
} 

そのようまた、私は、@JsonRpcWireNameが必要とされるかわかりません値はメソッド名と同じです。

+0

トーマス最新のコードと問題を教えてください。 :-) –

+0

'RequestFactory'を使う前に' INSTANCE.initialize(eventBus) 'コールがないようです。 –

+0

ありがとうThomas。私はEventBusを見逃していました...今は電話が終わっていますが、アップデートを読んでください! O :-) –

関連する問題