Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use flow context for asynchronic http client #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.cisco.oss.foundation.http.apache;

import com.cisco.oss.foundation.flowcontext.FlowContext;
import com.cisco.oss.foundation.flowcontext.FlowContextFactory;
import com.cisco.oss.foundation.http.AbstractHttpClient;
import com.cisco.oss.foundation.http.ClientException;
import com.cisco.oss.foundation.http.HttpRequest;
Expand Down Expand Up @@ -390,7 +392,9 @@ public void execute(HttpRequest request, ResponseCallback responseCallback, Load

HttpHost httpHost = new HttpHost(requestUri.getHost(),requestUri.getPort(),requestUri.getScheme());

httpAsyncClient.execute(httpHost, httpRequest, new FoundationFutureCallBack(this,request, responseCallback, serverProxy, loadBalancerStrategy, apiName));
FlowContext flowContext = FlowContextFactory.getFlowContext();

httpAsyncClient.execute(httpHost, httpRequest, new FoundationFutureCallBack(this,request, responseCallback, serverProxy, loadBalancerStrategy, apiName, flowContext.getUniqueId()));

}

Expand All @@ -416,20 +420,23 @@ private static class FoundationFutureCallBack implements FutureCallback<org.apac
private String apiName;
private HttpRequest request;
private ApacheHttpClient apacheHttpClient;
private String flowContext;


private FoundationFutureCallBack(ApacheHttpClient apacheHttpClient, HttpRequest request, ResponseCallback<ApacheHttpResponse> responseCallback, InternalServerProxy serverProxy, LoadBalancerStrategy loadBalancerStrategy, String apiName) {
private FoundationFutureCallBack(ApacheHttpClient apacheHttpClient, HttpRequest request, ResponseCallback<ApacheHttpResponse> responseCallback, InternalServerProxy serverProxy, LoadBalancerStrategy loadBalancerStrategy, String apiName, String flowContext) {
this.responseCallback = responseCallback;
this.apacheHttpClient = apacheHttpClient;
this.serverProxy = serverProxy;
this.loadBalancerStrategy = loadBalancerStrategy;
this.apiName = apiName;
this.request = request;
this.flowContext = flowContext;
}

@Override
public void completed(org.apache.http.HttpResponse response) {

FlowContextFactory.deserializeNativeFlowContext(flowContext);

serverProxy.setCurrentNumberOfAttempts(0);
serverProxy.setFailedAttemptTimeStamp(0);

Expand All @@ -444,7 +451,8 @@ public void completed(org.apache.http.HttpResponse response) {

@Override
public void failed(Exception ex) {

FlowContextFactory.deserializeNativeFlowContext(flowContext);

try {
loadBalancerStrategy.handleException(apiName, serverProxy, ex);
} catch (Exception e) {
Expand All @@ -462,6 +470,7 @@ public void failed(Exception ex) {

@Override
public void cancelled() {
FlowContextFactory.deserializeNativeFlowContext(flowContext);
responseCallback.cancelled();
}
}
Expand Down