问题
由于 GSON (GWT JSON-RPC) 遇到的几个问题,我想切换到 Resty-GWT。下面的例子展示了我的旧设置,下面是我的转移尝试。
数据
这是从我设置的代理发送的 JSON 数据:
{"id": 1, "result": ["Planets", "Stars"], "error": null}
ControlService.java - 我如何拨打电话(使用 GSON)
进行异步调用的类:
import com.google.gwtjsonrpc.common.AsyncCallback;
import com.google.gwtjsonrpc.common.RemoteJsonService;
import com.google.gwtjsonrpc.common.RpcImpl;
@RpcImpl(version=RpcImpl.Version.V2_0,transport=RpcImpl.Transport.HTTP_POST)
public interface ControlService extends RemoteJsonService
{
public void connectedNames( String [] Names, AsyncCallback<String[]> callback ); //FirstExample
}
创建面板.java
这是实际调用和接收数据的类:
import com.google.gwtjsonrpc.common.AsyncCallback;
public class createPanel implements ChangeHandler{
public mainPanel(){
//Some code setting up the panels
service_ = GWT.create(ControlService.class);
((ServiceDefTarget) service_).setServiceEntryPoint("http://localhost:3900/services/ControlProxy.py"); //Directs GWT to the proxy
service_.connectedNames( new String[0], new AsyncCallback<String[]>() {
public void onSuccess( String[] result)
{
//I now play with the data
}
public void onFailure(Throwable why)
{
myList_.addItem( "Server error!" );
}
});
}
}
那么我该如何使用RestyGWT呢?
我的尝试:
测试服务.java
import javax.ws.rs.Path;
import org.fusesource.restygwt.client.MethodCallback;
import org.fusesource.restygwt.client.RestService;
@Path("http://localhost:3900/services/ControlProxy.py")
@POST
public interface testService extends RestService {
public void connectedNames( String [] Names, MethodCallback<String[]> callback );
}
testCreatePanel.java
public class createPanel implements ChangeHandler{
public mainPanel(){
//Some code setting up the panels
service_ = GWT.create(testService.class);
testService.connectedNames(cbcNames, callback);//how to extract data from this
}