-
Notifications
You must be signed in to change notification settings - Fork 5
/
httpclient.js
58 lines (49 loc) · 2.14 KB
/
httpclient.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
var String = java.lang.String;
var entity = org.apache.http.HttpEntity;
var response = org.apache.http.client.methods.CloseableHttpResponse;
var httpGet = org.apache.http.client.methods.HttpGet;
var httpclient = org.apache.http.impl.client.CloseableHttpClient;
var client = org.apache.http.impl.client.HttpClient
var instream = java.io.InputStream;
var ex = java.io.IOException;
var content = java.lang.String;
var ioutil = org.apache.commons.io.IOUtils;
var httpClients = org.apache.http.impl.client.HttpClients;
var sys = java.lang.System;
var entityUtil = org.apache.http.util.EntityUtils;
httpclient = httpClients.createDefault();
httpGet = new org.apache.http.client.methods.HttpGet("http://www.google.com");//http://localhost:8764/api/apollo/connectors/jobs/google_news
try {
response = httpclient.execute(httpGet);
sys.out.println("Response: " + response.getStatusLine());
entity = response.getEntity();
//entityUtil.consume(entity);
if (entity != null) {
// instream = entity.getContent();
// sys.out.println("Available: "+ instream.available());
try {
// instream.read();
// content = ioutil.toString(instream, "UTF-8");
sys.out.println(new String(entityUtil.toByteArray(entity)));
// do something useful with the response
} catch (ex) {
// In case of an IOException the connection will be released
// back to the connection manager automatically
throw ex;
} finally {
// Closing the input stream will trigger connection release
// instream.close();
}
} else {
sys.out.println("entity was null");
}
} finally {
if(response !== null){
// response.close();
}
}