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

Bill Erickson erickson at esilibrary.com
Tue Mar 29 17:13:29 EDT 2011


On Mon, Mar 28, 2011 at 12:51 PM, chiwe123456 at gmail.com <
chiragahuja.nsit at gmail.com> wrote:

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

Correct, it's not complete.  There is no OpenSRF translator or gateway class
in Java.  However, it does implement most of the basics for OpenSRF object
handling and serialization.


>
> 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();
>
>
[snip...]

It's not necessary to build the JSON by hand.  You can create an
org.opensrf.Message object, pass in a Java Map or Java Array (or string,
number, boolean, etc.  See [1] for options) as the payload object.  Then,
simply calling toString() on the Message will generate the JSON for you.

-b

[1]
http://svn.open-ils.org/trac/OpenSRF/browser/trunk/src/java/org/opensrf/util/JSONWriter.java


-- 
Bill Erickson
| VP, Software Development & Integration
| Equinox Software, Inc. / Your Library's Guide to Open Source
| phone: 877-OPEN-ILS (673-6457)
| email: erickson at esilibrary.com
| web: http://esilibrary.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://libmail.georgialibraries.org/pipermail/open-ils-dev/attachments/20110329/74d9c340/attachment.htm 


More information about the Open-ils-dev mailing list