use of org.neo4j.ogm.drivers.http.request.HttpRequestException in project neo4j-ogm by neo4j.
the class HttpDriver method newTransactionUrl.
private String newTransactionUrl(Transaction.Type type) {
String url = transactionEndpoint(configuration.getURI());
LOGGER.debug("Thread: {}, POST {}", Thread.currentThread().getId(), url);
HttpPost request = new HttpPost(url);
request.setHeader("X-WRITE", type == Transaction.Type.READ_ONLY ? "0" : "1");
try (CloseableHttpResponse response = executeHttpRequest(request)) {
Header location = response.getHeaders("Location")[0];
return location.getValue();
} catch (IOException ioe) {
throw new HttpRequestException(request, ioe);
}
}
use of org.neo4j.ogm.drivers.http.request.HttpRequestException in project neo4j-ogm by neo4j.
the class HttpDriver method executeHttpRequest.
public CloseableHttpResponse executeHttpRequest(HttpRequestBase request) throws HttpRequestException {
try (CloseableHttpResponse response = HttpRequest.execute(httpClient(), request, configuration.getCredentials())) {
HttpEntity responseEntity = response.getEntity();
if (responseEntity != null) {
JsonNode responseNode = mapper.readTree(EntityUtils.toString(responseEntity));
LOGGER.debug("Response: {}", responseNode);
JsonNode errors = responseNode.findValue("errors");
if (errors.elements().hasNext()) {
JsonNode errorNode = errors.elements().next();
throw new CypherException(errorNode.findValue("code").asText(), errorNode.findValue("message").asText());
}
}
return response;
} catch (IOException ioe) {
throw new HttpRequestException(request, ioe);
} finally {
request.releaseConnection();
LOGGER.debug("Thread: {}, Connection released", Thread.currentThread().getId());
}
}
Aggregations