package edu.kit.ksri.paperfinder.scholar.http;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.impl.client.CloseableHttpClient;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Logger;

/**
 * Created by janscheurenbrand on 10.08.14.
 */
public class Response {
    static Logger logger = Logger.getLogger(Response.class.toString());
    private int statusCode;
    private String responseBody;

    public Response(Request request) {
        logger.info(String.format("Initializing Response"));
        HttpRequestBase requestBase = request.getRequest();
        CloseableHttpClient client = HttpClientFactory.getHttpClient();

        try {
            logger.info("Executing Response");
            CloseableHttpResponse response = client.execute(requestBase);

            try {
                this.statusCode = response.getStatusLine().getStatusCode();
                logger.info(String.format("Executed Response. Status Code %s", this.statusCode));
                BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
                StringBuilder result = new StringBuilder();
                String line = "";
                while ((line = rd.readLine()) != null) {
                    result.append(line);
                }
                this.responseBody = result.toString();
                //logger.info("Response Content:");
                //logger.info(this.responseBody);
            } finally {
                response.close();
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public String getResponseBody() {
        return responseBody;
    }

    public boolean wasSuccessful() {
        return (this.statusCode >= 200) && (this.statusCode < 400);
    }
}

@@ -212,16 +212,57 @@
 pClient;
+%0Aimport org.apache.http.util.EntityUtils;
 %0A%0Aimport
@@ -1287,254 +1287,69 @@
     
-StringBuilder result = new StringBuilder();%0A                String line = %22%22;%0A                while ((line = rd.readLine()) != null) %7B%0A                    result.append(line);%0A                %7D%0A                this.responseBody = result.toString(
+this.responseBody = EntityUtils.toString(response.getEntity()
 );%0A 
@@ -1355,34 +1355,32 @@
                 
-//
 logger.info(%22Res
@@ -1417,10 +1417,8 @@
     
-//
 logg

Refactor Response entity parsing