Skip to content

Commit

Permalink
Merge pull request #78 from nicolasmoreau/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
nicolasmoreau authored Jan 12, 2018
2 parents 6a4ad32 + adf429e commit 5dd7927
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public QueryStoreResponse getResponse() {
} catch (InterruptedException e) {
log.debug(e);
result = new QueryStoreResponse(QueryStoreResponse.STATUS_ERROR, "", e.getMessage());
} catch (ExecutionException e) {
e.printStackTrace();
} catch (ExecutionException e) {
log.debug(e);
result = new QueryStoreResponse(QueryStoreResponse.STATUS_ERROR, "", e.getMessage());
}catch (NullPointerException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,18 @@ private QueryStoreResponse associateRequest(String token, String userIp) {
try {
String request = this.getRequest(token, this.getUserEmail(),
this.userIp);

// send request while no result or result is empty
while ((result == null || QueryStoreResponse.STATUS_EMPTY.equals(result.getStatus()))
&& count < Settings.QUERYSTORE_MAX_RETRY.getInt()) {
result = this.doRequest(request);
//if(result != null)
Thread.sleep(Settings.QUERYSTORE_RETRY_TIMER.getInt());
count++;
}

} catch (Exception e) {
log.debug(e);
new QueryStoreResponse(QueryStoreResponse.STATUS_ERROR, "", "Error while querying query store");

}
result = new QueryStoreResponse(QueryStoreResponse.STATUS_ERROR, "", "Error while querying query store");
}
return result;
}

Expand Down Expand Up @@ -125,17 +123,14 @@ private QueryStoreResponse doRequest(String requestString)
//SSLHandShakeException (IOException) occurs if missing certificate
HttpResponse response = httpClient.execute(request);
Integer statusCode = response.getStatusLine().getStatusCode();

if ( statusCode == 200) {
BufferedReader rd = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()));

String uuid;
while ((uuid = rd.readLine()) != null) {
result.append(uuid);
}
rd.close();

} else {
// empty response
if (statusCode == 204) {
Expand All @@ -150,7 +145,6 @@ else if (statusCode >= 400 && statusCode < 500) {
return new QueryStoreResponse(QueryStoreResponse.STATUS_ERROR, "", response.getStatusLine().getReasonPhrase());
}
}

// extract uuid from json response
return QueryStoreResponseReader.parseResponse(result.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,18 @@ public Map<String, QueryStoreProcessor> getQuerystoreProcessors() {
* @return
*/
public String getIpAdress() {
String ipAddress = ServletContexts.instance().getRequest()
// client and proxies IP are concatenated in this header field : client, proxy1, proxy2 ...
String ipAddresses = ServletContexts.instance().getRequest()
.getHeader("X-FORWARDED-FOR");
String clientAddress = "";

if (ipAddress == null) {
ipAddress = ServletContexts.instance().getRequest().getRemoteAddr();
if (ipAddresses == null) {
clientAddress = ServletContexts.instance().getRequest().getRemoteAddr();
}else{
// keep only original client ip
clientAddress = ipAddresses.split(",")[0];
}
return ipAddress;
return clientAddress;
}

}

0 comments on commit 5dd7927

Please sign in to comment.