POST request + body data

47 views
Skip to first unread message

Rodrigo Vega

unread,
May 7, 2011, 6:49:45 PM5/7/11
to jpoxy
Hi i'm trying jpoxy and look really well however i'm getting somep
problems, but i'm not sure about.... let me explain it.

If i send a post json call the json data is conained in the body of
the request, right? i can't find any way to get that data processed,
jpoxy always say that i'm not specifying the method name. This is my
call example:

dojo.require("dojox.rpc.Service");
dojo.require("dojox.rpc.JsonRPC");

function loader() {
echoService = new dojox.rpc.Service({
envelope : "JSON-RPC-2.0",
transport : "POST",
target : "/services/json",
contentType : "application/json",
services : {
order : {}
}
});
var deferred = echoService.order(2);
deferred.addCallback(function(result) {
alert("Test" + result);
});

}

dojo.addOnLoad(loader);

The body of the post looks like this:

{"id":0,"method":"order","params":[2],"jsonrpc":"2.0"}

Howver i took a look to the RPC class source code and looks like even
if i specify POST as http method your are trying to obtain everything
from the parameter json or data. I think the body of the response
should be also processed, i think this is the standard or i'm wrong?

Thanks ! Hope i can read your answer soon.

Best Regards!

Rodrigo Vega

unread,
May 7, 2011, 6:52:06 PM5/7/11
to jpoxy
i wanted to say "the body of the request should be also processed"

On May 7, 7:49 pm, Rodrigo Vega <rodrigo.vega.bs.as....@gmail.com>
wrote:

Rodrigo Vega

unread,
May 7, 2011, 7:16:56 PM5/7/11
to jpoxy
What do you think about something like this at RPC class?

private Response handleRequest(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException, JSONException,
IllegalAccessException, InvocationTargetException,
JSONRPCException, ClassNotFoundException,
IllegalArgumentException, InstantiationException,
NoSuchMethodException, FileUploadException {

Request request = new Request();
Response response = new Response();

if (req.getParameter("json") != null) {
request.parseJSON(req.getParameter("json"));
} else if (req.getParameter("data") != null) {
request.parseJSON(req.getParameter("data"));
} else if(req.getMethod().matches("POST") &&
req.getHeader("Content-Type") != null ) {
if(req.getHeader("Content-Type").matches(".*multipart/(form-
data|mixed).*")){
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new
ServletFileUpload(factory);
List<FileItem> items = upload.parseRequest(req);
if(items.size() > 0) {
request.parseJSON(items.get(0).getString());
} else {
BufferedReader br = new BufferedReader(req.getReader());
String buffer, body;
while ((buffer = br.readLine()) != null) {
body += buffer;
}
request.parseJSON(body);
}
}


....

On May 7, 7:52 pm, Rodrigo Vega <rodrigo.vega.bs.as....@gmail.com>

Wes Widner

unread,
May 8, 2011, 2:33:59 PM5/8/11
to jp...@googlegroups.com
That's an excellent idea Rodrigo! I implemented your suggestions with a few modifications in the latest revision 1.0.21. Take a look and let me know if it's what you had in mind.

-Wes

Rodrigo Vega

unread,
May 9, 2011, 5:56:16 AM5/9/11
to jpoxy
Awesome! I will take a look today! =)
Reply all
Reply to author
Forward
0 new messages