0

Or what is the best way to archive this on GWT.

Please post some code of how to call a simple service with parameters using RequestFactory.

UPDATE:

Thomas, i have updated my code with your suggestions.

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

        }
    });

This code fails with:

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)
Eduard Wirch
  • 9,785
  • 9
  • 61
  • 73

1 Answers1

1

Cat should be a ValueProxy annotated with @JsonRpcProxy:

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

Also, I'm not sure the @JsonRpcWireName is required, as its value is the same as the method name.

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • Looks like you're missing the `INSTANCE.initialize(eventBus)` call before using your `RequestFactory`. – Thomas Broyer May 06 '12 at 23:55
  • Thanks Thomas. I was missing the EventBus... now the call is done but.. read the update please! O:-) – Eduardo Guardiola May 07 '12 at 07:34
  • OK, so, actually, the `@JsonRpcWireName` is needed (otherwise it'll use the same obfuscated name as with _standard RF_). As for the endpoint, `/gwtRequest` is the default URL for the `DefaultRequestTransport`. – Thomas Broyer May 07 '12 at 08:01
  • Many Thanks. I'm now trying one Request but i'm getting ' java.lang.AssertionError: java.lang.String is not an EntityProxy type'. The documentation says that String or List may be used too. – Eduardo Guardiola May 07 '12 at 09:39
  • Apparently, with the JSON-RPC dialect, the return type must be a `BaseProxy`: http://code.google.com/p/google-web-toolkit/source/browse/tags/2.4.0/user/src/com/google/web/bindery/requestfactory/shared/impl/AbstractRequestContext.java#231 Feel free to file bugs against GWT, and provide patches if you can. – Thomas Broyer May 07 '12 at 10:06
  • ohh what a pity! Yes, it seems i should to file a bug. :-( Many Many thanks for your help. – Eduardo Guardiola May 07 '12 at 10:21
  • For reference: see also http://code.google.com/p/google-web-toolkit/issues/detail?id=6891 – Thomas Broyer May 07 '12 at 12:33
  • I know. I have posted a workaround in that issue. At the moment i'm wrapping Collections and primitives in a ValueProxy :-/ – Eduardo Guardiola May 07 '12 at 13:13
  • i have filed a bug report: http://code.google.com/p/google-web-toolkit/issues/detail?id=7358&thanks=7358&ts=1336418314 – Eduardo Guardiola May 07 '12 at 20:14