0

I'm a beginner with all this and I need to execute a docker command without using sudo in ubuntu to use the gcc compiler. In order to make that happen, a friend of mine wrote a script, in go lang, named http-to-shell and that is a program that listens as http server on http://localhost:4000, and executes commands on terminal and returns output to client as a json response.

I run the command

sudo go run http-to-shell.go 

and then on another tab i use commands like

curl -d command=ls http://localhost:4000

this works perfectly and then if I use

curl --data-urlencode "[email protected]" http://localhost:4000

it runs the docker command that is in command.txt and shows the output of the program on the previous tab where i run sudo go run.

Now, my main issue. Since I'm a beginner I have no idea how to run this from a jsp page from localhost:8080 in ubuntu.

I have been trying, I tried using the answer in Using curl command in java but the process builder doesn't work. I need to run this curl command and get json response to show the user the output of his code.

Please help me out here.

2
  • Don't curl, use a http library for java to do the call Commented Feb 1, 2015 at 17:13
  • Can you please elaborate a bit? @Leon Commented Feb 1, 2015 at 17:15

1 Answer 1

1

If you want to use the result of the json in your code then curl is probably not what you want. Curl is however pretty awesome if you want to do stuff from the command line, and yes there are Java curl bindings, but I'd personally use Apache HttpClient

Here is an example using HttpClient to do a REST call. http://www.mkyong.com/webservices/jax-rs/restful-java-client-with-apache-httpclient/

The example uses Spring for the dependencies, I am not sure what your use, so you may have to download the jar yourself and place it on your class path

Sign up to request clarification or add additional context in comments.

4 Comments

If it's not too much to ask, can you provide me with a sample on how to use it?
Hey. I found an answer on SOF in how to convert a php curl to java using httpurlconnection. I tried it but some how the command isn't being posted to the server. I set up another question stackoverflow.com/questions/28272134/… can you please check it and tell what am i doing wrong?
that link seems to be deleted

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.