Hi,
I need to call a Restful web service from within smartgwt which expects/returns JSON.
So I need for example to send this request:
Request:
I tried the following:
But I get the following:
Transport error - HTTP code: 0 for URL: http://myWebServiceURL
In eclipse I see:
and
Any ideas?
I think maybe the RPCRequest is not being sent as RPC-JSON type, but how to change this?
Using smartgwt 6.1p power
I need to call a Restful web service from within smartgwt which expects/returns JSON.
So I need for example to send this request:
Request:
Code:
{"id":"ID","method":"authenticate","params":{"user":"ANDROID", "password":"PASSWORD", "client":"CLIENT"},"jsonrpc":"2.0"}
Code:
public void onModuleLoad() { final VLayout vlayout = new VLayout(); IButton but = new IButton("click me"); but.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { RPCRequest request = new RPCRequest(); request.setActionURL("http://myWebServiceURL"); request.setContentType("application/json"); request.setUseSimpleHttp(true); request.setHttpMethod("POST"); Map<String, String> params = new HashMap<String, String>(); params.put("id", "ID"); params.put("method", "authenticate"); params.put("params", "\"user\":\"ANDROID\",\"password\":\"PASSWORD\", \"client\":\"CLIENT\""); params.put("jsonrpc", "2.0"); request.setParams(params); RPCManager.sendRequest(request, new RPCCallback() { @Override public void execute(RPCResponse response, Object rawData,RPCRequest request) { String data = String.valueOf(rawData); System.out.println(data); } }); } }); vlayout.addMember(but); vlayout.setWidth100(); vlayout.setHeight100(); vlayout.draw(); }
Transport error - HTTP code: 0 for URL: http://myWebServiceURL
In eclipse I see:
Code:
16:45:16.746 [ERROR] [builtinds] 16:45:16.743:XRP9:WARN:RPCManager:xmlHttpRequest.getAllResponseHeaders() returned null com.smartgwt.client.core.JsObject$SGWT_WARN: 16:45:16.743:XRP9:WARN:RPCManager:xmlHttpRequest.getAllResponseHeaders() returned null at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:105) at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:72) at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172) at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:296) at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:551) at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:368) at java.lang.Thread.run(Thread.java:745)
Code:
16:45:16.993 [ERROR] [builtinds] 16:45:16.990:XRP9:WARN:RPCManager:Transport error - HTTP code: 0 for URL: http://myWebServiceURL - response: {operationId: "custom", clientContext: undef, internalClientContext: undef, context: Obj, transactionNum: 0, httpResponseCode: 0, httpResponseText: "", xmlHttpRequest: [object XMLHttpRequest], transport: "xmlHttpRequest", status: -90, clientOnly: undef, httpHeaders: null, isStructured: true, callbackArgs: null, results: Obj, data: "Transport error - HTTP code: 0 for URL: ..."[108]} com.smartgwt.client.core.JsObject$SGWT_WARN: 16:45:16.990:XRP9:WARN:RPCManager:Transport error - HTTP code: 0 for URL: http://myWebServiceURL - response: {operationId: "custom", clientContext: undef, internalClientContext: undef, context: Obj, transactionNum: 0, httpResponseCode: 0, httpResponseText: "", xmlHttpRequest: [object XMLHttpRequest], transport: "xmlHttpRequest", status: -90, clientOnly: undef, httpHeaders: null, isStructured: true, callbackArgs: null, results: Obj, data: "Transport error - HTTP code: 0 for URL: ..."[108]} at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:105) at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:72) at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172) at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:296) at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:551) at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:368) at java.lang.Thread.run(Thread.java:745)
Any ideas?
I think maybe the RPCRequest is not being sent as RPC-JSON type, but how to change this?
Using smartgwt 6.1p power
Comment