Search in sources :

Example 1 with ParseException

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();
    }
}
Also used : HttpEntity(org.apache.http.HttpEntity) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) JsonValue(org.eclipse.json.provisonnal.com.eclipsesource.json.JsonValue) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) IOException(java.io.IOException) ParseException(org.eclipse.json.provisonnal.com.eclipsesource.json.ParseException) StatusLine(org.apache.http.StatusLine) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) ParseException(org.eclipse.json.provisonnal.com.eclipsesource.json.ParseException)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 HttpEntity (org.apache.http.HttpEntity)1 HttpResponse (org.apache.http.HttpResponse)1 StatusLine (org.apache.http.StatusLine)1 HttpClient (org.apache.http.client.HttpClient)1 HttpGet (org.apache.http.client.methods.HttpGet)1 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)1 JsonValue (org.eclipse.json.provisonnal.com.eclipsesource.json.JsonValue)1 ParseException (org.eclipse.json.provisonnal.com.eclipsesource.json.ParseException)1