java - IOException: Internal Server Error when trying to consume rest service -


i want create restful web service in java using jersey api , consume in android application. got this question on talks java client whereas have android client.

my service looks this:

@path("/no") public class checknumber {  @post @produces("application/json") @consumes("application/json") public string getdetails(@pathparam("cno") string cno) {     string cardno="";     try {         jsonobject jsonobj = new jsonobject(cno);         cardno=jsonobj.getstring("cardno");     } catch (parseexception e1) {         e1.printstacktrace();     }     //do     return "somevalue";    } } 

now comes client side:

public class mainactivity extends activity {      jsonobject json = new jsonobject();     string wsdl = "http://192.168.1.105:8080/restdemo/check/no/";      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         new requesttask().execute("1234567890");      }      class requesttask extends asynctask<string, string, string> {          @override         protected string doinbackground(string... uri) {         httpclient httpclient = new defaulthttpclient();         httpresponse response;          string add = "{\"cardno\":\"" + uri[0] + "\"}";         httppost postmethod = new httppost(wsdl);         string responsestring = null;         try {             postmethod.addheader("content-type", "application/json");             httpentity entity = new stringentity(add);             postmethod.setentity(entity);             response = httpclient.execute(postmethod);                 statusline statusline = response.getstatusline();                 if (statusline.getstatuscode() == httpstatus.sc_ok) {                     bytearrayoutputstream out = new                             bytearrayoutputstream();                     response.getentity().writeto(out);                     out.close();                     responsestring = out.tostring();                 } else {                     response.getentity().getcontent().close();                     throw new ioexception(statusline.getreasonphrase());                 }             } catch (clientprotocolexception e) {                 e.printstacktrace();             } catch (ioexception e) {                 e.printstacktrace();             } catch (exception e) {                 e.printstacktrace();             }             return responsestring;         }          @override         protected void onpostexecute(string result) {             super.onpostexecute(result);         }     } } 

i'm starting rest web services. created sample rest service consumes string , returns string , used service in android app.

but when try pass json string using post method. it's giving following errorin log:

java.io.ioexception: internal server error @ com.example.restclient.mainactivity$requesttask.doinbackground(mainactivity.java:85) 

where mainactivity.java:85 throw new ioexception(statusline.getreasonphrase()); implies statusline.getstatuscode() not returning httpstatus.sc_ok. instead it's returning status code = 500.

any appreciated.

it see server side log understand better.

try creating entity utf8 , set content-type in string entity rather in postmethod

stringentity stringentity = new stringentity(myjsondocstr, http.utf_8); stringentity.setcontenttype("application/json"); 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -