public HttpResponse makeRequestAndGetResponse(String url, Map<String, String> headers) { HttpResponse response = null; try { HttpGet getRequest = new HttpGet(url); // add all headers for (Entry<String, String> header : headers.entrySet()) { getRequest.addHeader(header.getKey(), header.getValue()); } response = httpClient.execute(getRequest); getRequest.reset(); } catch (Exception e) { throw new RuntimeException(e); } return response; }
private String sendInfoRequests() { HttpGet infoGet = new HttpGet(authorIp + "/libs/cq/core/productinfo.json"); String resultJson = ""; try (CloseableHttpResponse infoResponse = httpClient.execute(infoGet)) { resultJson = EntityUtils.toString(infoResponse.getEntity()); } catch (IOException e) { LOG.error("Can't get aem version", e); } finally { infoGet.reset(); } return resultJson; }
final CloseableHttpClient httpclient = HttpClients.createDefault(); final HttpGet request = new HttpGet("http://any-url"); try (CloseableHttpResponse response = httpclient.execute(request)) { final int status = response.getStatusLine().getStatusCode(); if (status == 200) { final InputStream is = response.getEntity().getContent(); } else { throw new IOException("Got " + status + " from server!"); } } finally { request.reset(); }
public static void transferResponse(HttpClient client, String uri, OutputStream out) throws HttpException, IOException { HttpGet request = new HttpGet(uri); try { HttpResponse response = client.execute(request); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) throw new HttpException("Invalid response code " + response.getStatusLine().getStatusCode() + ", reason=" + response.getStatusLine().getReasonPhrase() + " for uri " + uri); InputStream in = response.getEntity().getContent(); if (in == null) return; StreamUtils.transfer(in, out); } finally { request.reset(); } }
public String getServerProtocol() throws IOException, RepositoryException, UnauthorizedException { checkServerURL(); HttpGet method = new HttpGet(Protocol.getProtocolLocation(serverURL)); try { return EntityUtils.toString(executeOK(method).getEntity()); } catch (RepositoryException e) { throw e; } catch (RDF4JException e) { throw new RepositoryException(e); } finally { method.reset(); } }
public String getServerProtocol() throws IOException, RepositoryException, UnauthorizedException { checkServerURL(); HttpGet method = new HttpGet(Protocol.getProtocolLocation(serverURL)); try { return EntityUtils.toString(executeOK(method).getEntity()); } catch (RepositoryException e) { throw e; } catch (RDF4JException e) { throw new RepositoryException(e); } finally { method.reset(); } }
public String getNamespace(String prefix) throws IOException, RepositoryException, UnauthorizedException { checkRepositoryURL(); HttpGet method = new HttpGet(Protocol.getNamespacePrefixLocation(getQueryURL(), prefix)); try { HttpResponse response = execute(method); int code = response.getStatusLine().getStatusCode(); if (code == HttpURLConnection.HTTP_OK || code == HttpURLConnection.HTTP_NOT_AUTHORITATIVE) { return EntityUtils.toString(response.getEntity()); } else { EntityUtils.consume(response.getEntity()); return null; } } catch (RepositoryException e) { throw e; } catch (RDF4JException e) { throw new RepositoryException(e); } finally { method.reset(); } }
public String getServerProtocol() throws IOException, RepositoryException, UnauthorizedException { checkServerURL(); HttpGet method = new HttpGet(Protocol.getProtocolLocation(serverURL)); try { return EntityUtils.toString(executeOK(method).getEntity()); } catch (RepositoryException e) { throw e; } catch (RDF4JException e) { throw new RepositoryException(e); } finally { method.reset(); } }
public String getNamespace(String prefix) throws IOException, RepositoryException, UnauthorizedException { checkRepositoryURL(); HttpGet method = new HttpGet(Protocol.getNamespacePrefixLocation(getQueryURL(), prefix)); try { HttpResponse response = execute(method); int code = response.getStatusLine().getStatusCode(); if (code == HttpURLConnection.HTTP_OK || code == HttpURLConnection.HTTP_NOT_AUTHORITATIVE) { return EntityUtils.toString(response.getEntity()); } else { EntityUtils.consume(response.getEntity()); return null; } } catch (RepositoryException e) { throw e; } catch (RDF4JException e) { throw new RepositoryException(e); } finally { method.reset(); } }
public String getNamespace(String prefix) throws IOException, RepositoryException, UnauthorizedException { checkRepositoryURL(); HttpGet method = new HttpGet(Protocol.getNamespacePrefixLocation(getQueryURL(), prefix)); try { HttpResponse response = execute(method); int code = response.getStatusLine().getStatusCode(); if (code == HttpURLConnection.HTTP_OK || code == HttpURLConnection.HTTP_NOT_AUTHORITATIVE) { return EntityUtils.toString(response.getEntity()); } else { EntityUtils.consume(response.getEntity()); return null; } } catch (RepositoryException e) { throw e; } catch (RDF4JException e) { throw new RepositoryException(e); } finally { method.reset(); } }
public void getRepositoryList(TupleQueryResultHandler handler) throws IOException, TupleQueryResultHandlerException, RepositoryException, UnauthorizedException, QueryInterruptedException { checkServerURL(); HttpGet method = new HttpGet(Protocol.getRepositoriesLocation(serverURL)); try { getTupleQueryResult(method, handler); } catch (MalformedQueryException e) { // This shouldn't happen as no queries are involved logger.warn("Server reported unexpected malfored query error", e); throw new RepositoryException(e.getMessage(), e); } finally { method.reset(); } }
public void getRepositoryList(TupleQueryResultHandler handler) throws IOException, TupleQueryResultHandlerException, RepositoryException, UnauthorizedException, QueryInterruptedException { checkServerURL(); HttpGet method = new HttpGet(Protocol.getRepositoriesLocation(serverURL)); try { getTupleQueryResult(method, handler); } catch (MalformedQueryException e) { // This shouldn't happen as no queries are involved logger.warn("Server reported unexpected malfored query error", e); throw new RepositoryException(e.getMessage(), e); } finally { method.reset(); } }
public void getRepositoryList(TupleQueryResultHandler handler) throws IOException, TupleQueryResultHandlerException, RepositoryException, UnauthorizedException, QueryInterruptedException { checkServerURL(); HttpGet method = new HttpGet(Protocol.getRepositoriesLocation(serverURL)); try { getTupleQueryResult(method, handler); } catch (MalformedQueryException e) { // This shouldn't happen as no queries are involved logger.warn("Server reported unexpected malfored query error", e); throw new RepositoryException(e.getMessage(), e); } finally { method.reset(); } }
public void getNamespaces(TupleQueryResultHandler handler) throws IOException, TupleQueryResultHandlerException, RepositoryException, UnauthorizedException, QueryInterruptedException { checkRepositoryURL(); HttpGet method = new HttpGet(Protocol.getNamespacesLocation(getQueryURL())); try { getTupleQueryResult(method, handler); } catch (MalformedQueryException e) { logger.warn("Server reported unexpected malfored query error", e); throw new RepositoryException(e.getMessage(), e); } finally { method.reset(); } }
public void getNamespaces(TupleQueryResultHandler handler) throws IOException, TupleQueryResultHandlerException, RepositoryException, UnauthorizedException, QueryInterruptedException { checkRepositoryURL(); HttpGet method = new HttpGet(Protocol.getNamespacesLocation(getQueryURL())); try { getTupleQueryResult(method, handler); } catch (MalformedQueryException e) { logger.warn("Server reported unexpected malfored query error", e); throw new RepositoryException(e.getMessage(), e); } finally { method.reset(); } }
public void getContextIDs(TupleQueryResultHandler handler) throws IOException, TupleQueryResultHandlerException, RepositoryException, UnauthorizedException, QueryInterruptedException { checkRepositoryURL(); HttpGet method = new HttpGet(Protocol.getContextsLocation(getQueryURL())); try { getTupleQueryResult(method, handler); } catch (MalformedQueryException e) { logger.warn("Server reported unexpected malfored query error", e); throw new RepositoryException(e.getMessage(), e); } finally { method.reset(); } }
public void getContextIDs(TupleQueryResultHandler handler) throws IOException, TupleQueryResultHandlerException, RepositoryException, UnauthorizedException, QueryInterruptedException { checkRepositoryURL(); HttpGet method = new HttpGet(Protocol.getContextsLocation(getQueryURL())); try { getTupleQueryResult(method, handler); } catch (MalformedQueryException e) { logger.warn("Server reported unexpected malfored query error", e); throw new RepositoryException(e.getMessage(), e); } finally { method.reset(); } }
public void getNamespaces(TupleQueryResultHandler handler) throws IOException, TupleQueryResultHandlerException, RepositoryException, UnauthorizedException, QueryInterruptedException { checkRepositoryURL(); HttpGet method = new HttpGet(Protocol.getNamespacesLocation(getQueryURL())); try { getTupleQueryResult(method, handler); } catch (MalformedQueryException e) { logger.warn("Server reported unexpected malfored query error", e); throw new RepositoryException(e.getMessage(), e); } finally { method.reset(); } }
public void getContextIDs(TupleQueryResultHandler handler) throws IOException, TupleQueryResultHandlerException, RepositoryException, UnauthorizedException, QueryInterruptedException { checkRepositoryURL(); HttpGet method = new HttpGet(Protocol.getContextsLocation(getQueryURL())); try { getTupleQueryResult(method, handler); } catch (MalformedQueryException e) { logger.warn("Server reported unexpected malfored query error", e); throw new RepositoryException(e.getMessage(), e); } finally { method.reset(); } }
httpGet.reset();