X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fjcalderonzumba%2Fgastonjs%2Fexamples%2Fjava%2FGastonJSClient.java;fp=vendor%2Fjcalderonzumba%2Fgastonjs%2Fexamples%2Fjava%2FGastonJSClient.java;h=c923d709a3825c25396a511276cf98e185624b89;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/jcalderonzumba/gastonjs/examples/java/GastonJSClient.java b/vendor/jcalderonzumba/gastonjs/examples/java/GastonJSClient.java new file mode 100644 index 000000000..c923d709a --- /dev/null +++ b/vendor/jcalderonzumba/gastonjs/examples/java/GastonJSClient.java @@ -0,0 +1,48 @@ +import java.io.InputStream; +import java.lang.System; + +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.commons.io.IOUtils; +import org.apache.http.impl.client.CloseableHttpClient; + +public class GastonJSClient{ + + public static void main(String[] args) throws Exception{ + // write your code here + String visitPage = "{\n" + + " \"name\": \"visit\",\n" + + " \"args\":[\n" + + " \"http://www.google.es\"\n" + + " ]\n" + + "}"; + String renderPage = "{\"name\":\"render\",\"args\":[\"/Users/juan/Downloads/page_image.png\",true,null]}"; + CloseableHttpClient httpClient = HttpClientBuilder.create().build(); + try { + //Do the visit + HttpPost request = new HttpPost("http://127.0.0.1:8510/v1/api"); + StringEntity params = new StringEntity(visitPage); + request.addHeader("content-type", "application/json"); + request.setEntity(params); + HttpResponse response = httpClient.execute(request); + InputStream body = response.getEntity().getContent(); + String myString = IOUtils.toString(body, "UTF-8"); + System.out.println(myString); + //Do the page print + params = new StringEntity(renderPage); + request.setEntity(params); + response = httpClient.execute(request); + body = response.getEntity().getContent(); + myString = IOUtils.toString(body, "UTF-8"); + System.out.println(myString); + // handle response here... + } catch (Exception ex) { + // handle exception here + System.out.println(ex.toString()); + } finally { + httpClient.close(); + } + } +} \ No newline at end of file