Quantcast
Channel: SmartClient Forums
Viewing all articles
Browse latest Browse all 4756

Sending RPCRequest as json from java client

$
0
0
Hi,

I am sending a RPCRequest to the server as shown below. It works fine except when I add the the statement to setContentType to json as shown below. In this case the getParameter statement in the server returns null. I am trying to set up the servlet to accept json requests.

I am using SmartGWT Pro 5.0p.

Client side code:

Code:

HashMap<String, String> h = new HashMap<String, String>();
h.put("caller", "login");
h.put("uid", uid);
h.put("password", password);

RPCRequest req = new RPCRequest();
req.setParams(h);
req.setActionURL(dataUrl);
req.setContentType("application/json");  // works fine without this line of code
               
RPCManager.sendRequest(req, new RPCCallback() {
...

});

Server code is a servlet:

Code:

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// getParameter returns null when contentType is set to 'json' in client request.
// when contentType is not explicitly set (left as x-www-form-urlencoded) then getParameter call
// returns value as expected
    String caller = request.getParameter("caller");
}

In dev console, the request looks like this

Code:

{
    "actionURL":"http://127.0.0.1:8888/appname/sc/Login",
    "showPrompt":false,
    "transport":"xmlHttpRequest",
    "promptStyle":"cursor",
    "params":{
        "caller":"login",
        "password":"passwd",
        "uid":"bc",
        "isc_tnum":0
    },
    "contentType":"application/json"
}


Viewing all articles
Browse latest Browse all 4756

Trending Articles