Search in sources :

Example 1 with JsonProcessingService

use of uk.ac.ebi.spot.goci.ui.service.JsonProcessingService in project goci by EBISPOT.

the class SolrSearchController method dispatchDownloadSearch.

private void dispatchDownloadSearch(String searchString, OutputStream outputStream, boolean efo, String facet, boolean ancestry) throws IOException {
    getLog().trace(searchString);
    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpGet httpGet = new HttpGet(searchString);
    if (System.getProperty("http.proxyHost") != null) {
        HttpHost proxy;
        if (System.getProperty("http.proxyPort") != null) {
            proxy = new HttpHost(System.getProperty("http.proxyHost"), Integer.parseInt(System.getProperty("http.proxyPort")));
        } else {
            proxy = new HttpHost(System.getProperty("http.proxyHost"));
        }
        httpGet.setConfig(RequestConfig.custom().setProxy(proxy).build());
    }
    String file = null;
    try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
        getLog().debug("Received HTTP response: " + response.getStatusLine().toString());
        HttpEntity entity = response.getEntity();
        BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
        String output;
        while ((output = br.readLine()) != null) {
            JsonProcessingService jsonProcessor = new JsonProcessingService(output, efo, facet, ancestry);
            file = jsonProcessor.processJson();
        }
        EntityUtils.consume(entity);
    }
    if (file == null) {
        //TO DO throw exception here and add error handler
        file = "Some error occurred during your request. Please try again or contact the GWAS Catalog team for assistance";
    }
    PrintWriter outputWriter = new PrintWriter(outputStream);
    outputWriter.write(file);
    outputWriter.flush();
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpEntity(org.apache.http.HttpEntity) InputStreamReader(java.io.InputStreamReader) HttpHost(org.apache.http.HttpHost) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) BufferedReader(java.io.BufferedReader) JsonProcessingService(uk.ac.ebi.spot.goci.ui.service.JsonProcessingService) PrintWriter(java.io.PrintWriter)

Aggregations

BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 HttpEntity (org.apache.http.HttpEntity)1 HttpHost (org.apache.http.HttpHost)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 JsonProcessingService (uk.ac.ebi.spot.goci.ui.service.JsonProcessingService)1