use of org.eclipse.json.provisonnal.com.eclipsesource.json.ParseException in project webtools.sourceediting by eclipse.
the class HttpHelper method makeRequest.
public static JsonValue makeRequest(String url) throws IOException {
long startTime = 0;
HttpClient httpClient = new DefaultHttpClient();
try {
// Post JSON Tern doc
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity entity = httpResponse.getEntity();
InputStream in = entity.getContent();
// Check the status
StatusLine statusLine = httpResponse.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
// node.js server throws error
/*
* String message = IOUtils.toString(in); if
* (StringUtils.isEmpty(message)) { throw new
* TernException(statusLine.toString()); } throw new
* TernException(message);
*/
}
try {
JsonValue response = JsonValue.readFrom(new InputStreamReader(in));
return response;
} catch (ParseException e) {
throw new IOException(e);
}
} catch (Exception e) {
if (e instanceof IOException) {
throw (IOException) e;
}
throw new IOException(e);
} finally {
httpClient.getConnectionManager().shutdown();
}
}
Aggregations