Re: [OPEN-ILS-DEV] Help:opensrf over http using java
On Mon, Mar 28, 2011 at 12:51 PM, chiwe123...@gmail.com chiragahuja.n...@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: erick...@esilibrary.com | web: http://esilibrary.com
Re: [OPEN-ILS-DEV] Help:opensrf over http using java
thanks Bill, this is what , I was about to ask, creating JSON from Java Using opensrf library. On Wed, Mar 30, 2011 at 2:43 AM, Bill Erickson erick...@esilibrary.comwrote: On Mon, Mar 28, 2011 at 12:51 PM, chiwe123...@gmail.com chiragahuja.n...@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: erick...@esilibrary.com | web: http://esilibrary.com -- Himanshu Singh (m3th0d) IT-BHU Play Hard !! Go Pro
Re: [OPEN-ILS-DEV] Help:opensrf over http using java
Hi, What you are describing is basically correct. For further reference, see the login() function at http://svn.open-ils.org/trac/ILS/browser/trunk/Open-ILS/src/java/org/open_ils/util/Utils.java#L11 For your purposes, you would change the ClientSession.atomicRequest() calls (which communicate via XMPP) to analogous HTTP requests. As you've probably discovered, there is no gateway/translator code in Java yet, so the HTTP handling would be new code. Hope this helps. -b On Sat, Mar 26, 2011 at 1:44 AM, chiwe123...@gmail.com chiragahuja.n...@gmail.com wrote: *Forgot to put my information over previous mail..* I want to login through a java application Is my Approach correct?? First I will create json object in java which is like this ( but I don’t know how to use curl –H over here as it is a command line tool ) curl -H X-OpenSRF-service: open-ils.auth --data 'osrf-msg= [ { __c : osrfMessage, __p : { threadTrace : 0, payload : { __c : osrfMethod,__p : { params : [admin], method : open-ils.auth.authenticate.init } }, locale : en-US, type : REQUEST } } ] and then send it to url=*http://192.168.56.102/osrf-http-translator *(192.168.56.102 is the ip address of virtual machine because I’m accessing virtual machine services from host machine in which java application is running) *Response* [ { __c : osrfMessage, __p : { threadTrace : 0, payload : { __c : osrfResult, __p : { status : OK, content : “6ba0510ab42e028e57755bf0151655ed” statusCode : 200 } }, locale : en-US, type : RESULT } }, { __c : osrfMessage, __p : { threadTrace : 0, payload : { __c : osrfConnectStatus, __p : { status : Request Complete, statusCode : 205 } }, locale : en-US, type : STATUS } } ] From response I take out 6ba0510ab42e028e57755bf0151655ed and md5hash of “open-ils” which I’ll use in next request *Next Request* curl -H X-OpenSRF-service: open-ils.auth --data 'osrf-msg= [ { __c : osrfMessage, __p : { threadTrace : 0, payload : { __c : osrfMethod, __p : { params : { “username”: admin “Password”: 92df31e9869a256203560124ea5319ec type: opac },method : open-ils.auth.authenticate.complete } }, locale : en-US, type : REQUEST } } ] And then the response... please help me with this. *Chirag Ahuja (irc name :chirag)* -- Bill Erickson | VP, Software Development Integration | Equinox Software, Inc. / Your Library's Guide to Open Source | phone: 877-OPEN-ILS (673-6457) | email: erick...@esilibrary.com | web: http://esilibrary.com
Re: [OPEN-ILS-DEV] Help:opensrf over http using java
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)
[OPEN-ILS-DEV] Help:opensrf over http using java
I want to login through a java application Is my Approach correct?? First I will create json object in java which is like this ( but I don’t know how to use curl –H over here as it is a command line tool ) curl -H X-OpenSRF-service: open-ils.auth --data 'osrf-msg= [ { __c : osrfMessage, __p : { threadTrace : 0, payload : { __c : osrfMethod,__p : { params : [admin], method : open-ils.auth.authenticate.init } }, locale : en-US, type : REQUEST } } ] and then send it to url=*http://192.168.56.102/osrf-http-translator *(192.168.56.102 is the ip address of virtual machine because I’m accessing virtual machine services from host machine in which java application is running) *Response* [ { __c : osrfMessage, __p : { threadTrace : 0, payload : { __c : osrfResult, __p : { status : OK, content : “6ba0510ab42e028e57755bf0151655ed” statusCode : 200 } }, locale : en-US, type : RESULT } }, { __c : osrfMessage, __p : { threadTrace : 0, payload : { __c : osrfConnectStatus, __p : { status : Request Complete, statusCode : 205 } }, locale : en-US, type : STATUS } } ] From response I take out 6ba0510ab42e028e57755bf0151655ed and md5hash of “open-ils” which I’ll use in next request *Next Request* curl -H X-OpenSRF-service: open-ils.auth --data 'osrf-msg= [ { __c : osrfMessage, __p : { threadTrace : 0, payload : { __c : osrfMethod, __p : { params : { “username”: admin “Password”: 92df31e9869a256203560124ea5319ec type: opac },method : open-ils.auth.authenticate.complete } }, locale : en-US, type : REQUEST } } ] And then the response
[OPEN-ILS-DEV] Help:opensrf over http using java
*Forgot to put my information over previous mail..* I want to login through a java application Is my Approach correct?? First I will create json object in java which is like this ( but I don’t know how to use curl –H over here as it is a command line tool ) curl -H X-OpenSRF-service: open-ils.auth --data 'osrf-msg= [ { __c : osrfMessage, __p : { threadTrace : 0, payload : { __c : osrfMethod,__p : { params : [admin], method : open-ils.auth.authenticate.init } }, locale : en-US, type : REQUEST } } ] and then send it to url=*http://192.168.56.102/osrf-http-translator *(192.168.56.102 is the ip address of virtual machine because I’m accessing virtual machine services from host machine in which java application is running) *Response* [ { __c : osrfMessage, __p : { threadTrace : 0, payload : { __c : osrfResult, __p : { status : OK, content : “6ba0510ab42e028e57755bf0151655ed” statusCode : 200 } }, locale : en-US, type : RESULT } }, { __c : osrfMessage, __p : { threadTrace : 0, payload : { __c : osrfConnectStatus, __p : { status : Request Complete, statusCode : 205 } }, locale : en-US, type : STATUS } } ] From response I take out 6ba0510ab42e028e57755bf0151655ed and md5hash of “open-ils” which I’ll use in next request *Next Request* curl -H X-OpenSRF-service: open-ils.auth --data 'osrf-msg= [ { __c : osrfMessage, __p : { threadTrace : 0, payload : { __c : osrfMethod, __p : { params : { “username”: admin “Password”: 92df31e9869a256203560124ea5319ec type: opac },method : open-ils.auth.authenticate.complete } }, locale : en-US, type : REQUEST } } ] And then the response... please help me with this. *Chirag Ahuja (irc name :chirag)*