else {
AsyncHttpClient asyncHttpClient = null;
try {
for (SourceFederatedQueryConfigPojo.FederatedQueryEndpointUrl request: endpoint.requests) {
asyncHttpClient = new AsyncHttpClient();
BoundRequestBuilder asyncRequest = null;
String postContent = null;
if (null != request.httpFields) {
postContent = request.httpFields.get("Content");
if (null == postContent)
postContent = request.httpFields.get("content");
}//TESTED (by hand, "http://httpbin.org/post", "httpFields": { "Content": "test" }
if (null == postContent) {
asyncRequest = asyncHttpClient.prepareGet(request.endPointUrl.replace("$1", entityValue));
}
else {
asyncRequest = asyncHttpClient.preparePost(request.endPointUrl.replace("$1", entityValue));
}//TESTED (by hand, "http://httpbin.org/post", "httpFields": { "Content": "test" }
if (null != request.urlParams) {
for (Map.Entry<String, String> keyValue: request.urlParams.entrySet()) {
asyncRequest = asyncRequest.addQueryParameter(keyValue.getKey(), keyValue.getValue().replace("$1", entityValue));
}
}//TESTED (1.5, 1.6, 3.*, 4.*)
if (null != request.httpFields) {
for (Map.Entry<String, String> keyValue: request.httpFields.entrySet()) {
if (!keyValue.getKey().equalsIgnoreCase("content")) {
asyncRequest = asyncRequest.addHeader(keyValue.getKey(), keyValue.getValue().replace("$1", entityValue));
}
}
}//TESTED (by hand, "http://httpbin.org/cookies", "httpFields": { "Cookie": "mycookie=test" }
if (null != postContent) {
asyncRequest = asyncRequest.setBody(postContent.replace("$1", entityValue));
}//TESTED (by hand, "http://httpbin.org/post", "httpFields": { "Content": "$1" }
// Common params:
FederatedRequest requestOverview = new FederatedRequest();
requestOverview.endpointInfo = endpoint;
requestOverview.communityIdStrs = communityIdStrs;
requestOverview.requestParameter = entityValue;
requestOverview.asyncClient = asyncHttpClient;
requestOverview.queryIndex = entityIndex;
requestOverview.mergeKey = endpoint.parentSource.getKey();
requestOverview.subRequest = request;
// Now check out the cache:
URI rawUri = asyncRequest.build().getRawURI();
String url = rawUri.toString();
if ((null == endpoint.parentSource.getOwnedByAdmin()) || !endpoint.parentSource.getOwnedByAdmin())
{
//TODO (INF-2798): Make this consistent with the how security is handled elsewhere
int port = rawUri.getPort();
if ((80 != port) && (443 != port) && (-1 != port)) {
_logger.error("Only admin can make requests on non-standard ports: " + url + ": " + port);
if (_testMode) {
asyncHttpClient.close();
throw new RuntimeException("Only admin can make requests on non-standard ports: " + url + ": " + port);
}
}
}//TESTED (by hand)
BasicDBObject cachedVal = this.getCache(url, endpoint);
requestOverview.cachedResult = cachedVal;
requestOverview.cachedDoc_expired = cachedDoc_expired;
if (null == cachedVal) {
requestOverview.responseFuture = asyncRequest.execute();
}
else {
//DEBUG
if (_DEBUG) _logger.debug("DEB: preQA6b: Cache: " + url + " , " + cachedVal);