Example usage for org.apache.http.client.methods HttpUriRequest getRequestLine

List of usage examples for org.apache.http.client.methods HttpUriRequest getRequestLine

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpUriRequest getRequestLine.

Prototype

RequestLine getRequestLine();

Source Link

Usage

From source file:org.agilespain.kitaos.service.RemoteExecutor.java

void execute(HttpUriRequest request, JsonHandler handler) throws HandlerException {
    try {// w w w .jav  a  2  s .  c o m
        final HttpResponse resp = mHttpClient.execute(request);
        final int status = resp.getStatusLine().getStatusCode();
        if (status != HttpStatus.SC_OK) {
            throw new HandlerException(
                    "Unexpected server response " + resp.getStatusLine() + " for " + request.getRequestLine());
        }

        final InputStream input = resp.getEntity().getContent();
        try {

            BufferedReader reader = new BufferedReader(new InputStreamReader(input));

            StringBuilder sb = new StringBuilder();
            String line = null;
            try {
                while ((line = reader.readLine()) != null) {
                    sb.append(line).append("\n");
                }
            } finally {
                try {
                    input.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            String jsonString = sb.toString();

            handler.parseAndApply(jsonString, mResolver);
            //            } catch (JSONException e) {
            //                throw new HandlerException("Malformed response for " + request.getRequestLine(), e);
        } finally {
            if (input != null)
                input.close();
        }
    } catch (HandlerException e) {
        throw e;
    } catch (IOException e) {
        throw new HandlerException("Problem reading remote response for " + request.getRequestLine(), e);
    }
}