admin-announcements

Announcements from the Clojurians Admin Team (@U11BV7MTK @U077BEWNQ @U050TNB9F @U0ETXRFEW @U04V70XH6 @U8MJBRSR5 and others)
2015-10-14T12:43:41.000232Z

hi I am new to clojure, and I got a question I have not being able to find a definitive answer on google I work with a big java desktop application, where I have managed to embedd jython to provide a scripting framework it works well, but I hate java scientific libraries, jython cannot use numpy and Co. I got interested in Inchanter instead. Now I am wondering if I can also embedd clojure into the java app in the same way as I did for jython. What I do with jython, is on java, I create an interpreter, set paths to different modules I need dynamically then I put a 2D matrix (a list of lists) into the interpreter and then I load the script I want and execute a function that will always be in every script by convention, and which takes that 2D matrix I put into the interpreter the function returns another 2D matrix, which then I can recover from java side and cast to java types and then some other small things like redirecting jython stdout and stderr to java so that I can print nicely on the java app, etc Would it be possible with clojure? Somehow I got the feeling it is not designed for this purpose.

2015-10-14T13:15:27.000235Z

Hi @sidrero you should be able to use core.matrix for most of what you need. It supports conversions to / from various different matrix representations

2015-10-14T13:16:16.000236Z

core.matrix is roughly equivalent to numpy in terms of scope, most of the same functionality is there too

nnbosko 2015-10-14T20:25:17.000246Z

I have a small question regarding clj-http. How can I emulate a curl post that does this? curl -X POST 'https://website.com/endpoint' -d 'request_body={ ... }'

2015-10-14T20:43:00.000247Z

@nnbosko: this should do it

(require '[cheshire.core :as json])
(require '[clj-http.client :as http])
(http/post "<https://website.com/endpoint>" {:body (json/encode {...})})
there are a lot of excellent examples in the readme on github https://github.com/dakrone/clj-http

nnbosko 2015-10-14T20:44:40.000249Z

Sorry, I should have been more specific. The issue isn't that per se, I know more or less how to deal with clj-http, the issue is specifically sending 'request_body = { ... }' as data

nnbosko 2015-10-14T20:45:45.000250Z

Not request body as a json parameter itself, but request_body={ "api_key" : "xxxxxx", "name" : "xxxxx" etc }

nnbosko 2015-10-14T20:48:21.000251Z

hence -d 'request_body={...}'

nnbosko 2015-10-14T20:48:50.000253Z

Am I clear, @oliy?

2015-10-14T20:49:49.000254Z

so the body is "request_body={...}"?

nnbosko 2015-10-14T20:50:51.000255Z

I wouldn't say that, because doing (http/post "website" {:body "request_body={...}"}) fails

2015-10-14T20:53:30.000256Z

then i'm afraid the finer points of what curl is doing there is lost on me!

gusbicalho 2015-10-14T20:54:32.000257Z

@nnbosko: "I wouldn't say that, because doing (http/post "website" {:body "request_body={...}"}) fails" fails how?

nnbosko 2015-10-14T20:54:58.000258Z

It says request_body is empty

nnbosko 2015-10-14T20:57:54.000259Z

More specifically this is the body of the request I'm getting from the server

nnbosko 2015-10-14T20:58:13.000260Z

:body "{\"status\":\"ERROR\",\"status_code\":\"BP-DPAR-1\",\"status_message\":\"request_body is empty\"}"

gusbicalho 2015-10-14T21:43:50.000261Z

I think it's something on your server side. I tried here and (client/post "<http://localhost:5000>" {:body "request_body={...}"}) works fine, the server gets the string "request_body={...}"

nullptr 2015-10-14T21:44:58.000262Z

what’s the content-type header on the POST?

nullptr 2015-10-14T21:46:24.000263Z

typically you need to set application/x-www-form-urlencoded to get standard parsing behaviors to work, this is often automatic

gusbicalho 2015-10-14T21:49:26.000264Z

yeah, if it works with curl but doesn't work with clj-http, it's probably a matter of the default content-type being different for each one, which causes the server to misunderstand the body