java - Calling Jersey services from Android , unkown Exception -
i'm trying call web service made using jersey. tested services calling them console java app, , working fine.
when calling android, first gave me android.os.networkonmainthreadexception, searched , found out should use asynctask solve that,
the following code crashes when "response.getentity(string.class)" called while calling service, if return status ( response.getstatus()) instead of getentity, works fine. same thing doesnt work in case of post request. getentity() crashes on both
public string posttest(string arg){ log.d("service", "postregister1"); client = client.create(); webresource service=client.resource(getbaseuri()); log.d("service", "postregister2"); form form = new form(); form.add("arg", "lol"); int status; clientresponse response=null; try{ response = service.path("test").get(clientresponse.class); //post // response = service.path("post").path("test").post(clientresponse.class,from); log.d("service", "postregister3"); status = response.getstatus(); //comment out following if statement , code work fine, returning stats if(status == 200){ return response.getentity(string.class); } return string.valueof(response.getstatus()); } catch(clienthandlerexception e){ log.d("exception1",e.getmessage()+ " "); } catch(uniforminterfaceexception e){ log.d("exception2",e.getmessage()+ " "); } catch(exception e){ log.d("exception3",e.getmessage()+ " "); } return "exception"; } @override protected string doinbackground(string... params) { // todo auto-generated method stub log.d("doinback", params[0]); return posttest(params[0]); }
the code above code part of class:
public class service extends asynctask<string, void, string>{
and called like:
try { alert(new service().execute("lol").get(),view); } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (executionexception e) { // todo auto-generated catch block e.printstacktrace(); }
the alert method displays alert.
solved using library implementing async http client.
the tutorial followed can found here.
Comments
Post a Comment