[OPEN-ILS-DEV] Help:opensrf over http using java

chiwe123456@gmail.com chiragahuja.nsit at gmail.com
Mon Mar 28 12:51:52 EDT 2011


Is the java implementation of evergreen complete?..i heard that its not
complete yet so i opted a different method ...

I am actually working on android and sending post message to my virtual
machine on which evergreen is installed so i used apache http library..but i
am having some problem..

i am pasting the code written by me

can you please help me out with it..i have browsed over web and this method
for sending json object appeared best to me..

the above json written by me in previous mail is not correct so
for testing purpose i'm working on search books by barcode in which barcade
id is specified by user...

curl -H "X-OpenSRF-service: open-ils.search" --data 'osrf-msg=[{"__p"
: {"threadTrace" : 0, "payload" : { "__c" : "osrfMethod","__p" : {
"params" :"30007004981493","method" :
"open-ils.search.biblio.find_by_barcode"}},"type" : "REQUEST","locale"
: "en-US"},"__c" : "osrfMessage"} ]'
http://localhost/osrf-http-translator



HttpParams httpParams = new BasicHttpParams();

    HttpClient client = new DefaultHttpClient(httpParams);

    HttpPost httpost = new HttpPost("http://"+hostname+"/osrf-http-translator");

  httpost.setHeader("Accept", "application/json");
     httpost.setHeader("Content-type", "application/json");

    httpost.setHeader("X-OpenSRF-service", "open-ils.search");

    System.out.println("2");

    JSONObject data = new JSONObject();

    JSONObject _p = new JSONObject();

    JSONObject _p1 = new JSONObject();

    JSONObject osrfmsg = new JSONObject();

    HttpResponse response = null;
    try {

        _p.put("params",bookid);
                     //"30007004981493"

        _p.put("method","open-ils.search.biblio.find_by_barcode");

        JSONObject payload = new JSONObject();

        payload.put("_c", "osrfMethod");

        payload.put("_p", _p);

        _p1.put("threadTrace",0);

        _p1.put("payload", payload);

        _p1.put("locale","en-US" );

        _p1.put("type", "REQUEST");

        osrfmsg.put("_c","osrfMessage");

        osrfmsg.put("_p",_p1);

       // data.put("osrf-msg",osrfmsg);


    } catch (JSONException e) {

        // TODO Auto-generated catch block
        e.printStackTrace();

    }

          JSONArray osrfmsg2=new JSONArray();

    osrfmsg2.put(osrfmsg);

        httpost.getParams().setParameter("osrf-msg",osrfmsg2);

   response = client.execute(httpost);
BufferedReader reader = new BufferedReader(new
InputStreamReader(response.getEntity().getContent(), "UTF-8"));

StringBuilder builder = new StringBuilder();

        for (String line = null; (line = reader.readLine()) != null;)

        {     builder.append(line).append("\n"); }

        JSONTokener tokener = new JSONTokener(builder.toString());

        JSONArray finalResult = new JSONArray(tokener);


but i'm not able to extract json array from response ..but request
status is 200 ok.....

so either the json array in the request is not properly send..or their
might be some other problem..

thanks

Chirag ahuja
(irc name:chirag)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://libmail.georgialibraries.org/pipermail/open-ils-dev/attachments/20110328/5cd0d6b8/attachment.htm 


More information about the Open-ils-dev mailing list