3434import java .util .List ;
3535
3636import static com .cybersource .ws .client .Utility .*;
37+
3738/**
3839 * Class creates pooling http client connection flow. It maintains a pool of
3940 * http client connections and is able to service connection requests
@@ -50,6 +51,7 @@ public class PoolingHttpClientConnection extends Connection {
5051
5152 /**
5253 * Constructor.
54+ *
5355 * @param mc
5456 * @param builder
5557 * @param logger
@@ -63,6 +65,7 @@ public class PoolingHttpClientConnection extends Connection {
6365
6466 /**
6567 * Initialize pooling connection manager with max connections based on properties
68+ *
6669 * @param merchantConfig
6770 * @throws ClientException
6871 */
@@ -82,7 +85,7 @@ private void initializeConnectionManager(MerchantConfig merchantConfig) throws C
8285 connectionManager .setMaxPerRoute (new HttpRoute (httpHost ), merchantConfig .getMaxConnectionsPerRoute ());
8386 initHttpClient (merchantConfig , connectionManager );
8487 startStaleConnectionMonitorThread (merchantConfig , connectionManager );
85- if (merchantConfig .isShutdownHookEnabled ()) {
88+ if (merchantConfig .isShutdownHookEnabled ()) {
8689 addShutdownHook ();
8790 }
8891 } catch (Exception e ) {
@@ -96,6 +99,7 @@ private void initializeConnectionManager(MerchantConfig merchantConfig) throws C
9699
97100 /**
98101 * Initialize Http Client
102+ *
99103 * @param merchantConfig
100104 * @param poolingHttpClientConnManager
101105 */
@@ -119,6 +123,7 @@ protected void initHttpClient(MerchantConfig merchantConfig, PoolingHttpClientCo
119123
120124 /**
121125 * Initialize thread to clean Idle/Stale/Expired connections
126+ *
122127 * @param merchantConfig
123128 * @param poolingHttpClientConnManager
124129 */
@@ -131,6 +136,7 @@ private void startStaleConnectionMonitorThread(MerchantConfig merchantConfig, Po
131136
132137 /**
133138 * Method to post the request using http pool connection
139+ *
134140 * @param request
135141 * @param requestSentTime
136142 * @throws IOException
@@ -154,6 +160,7 @@ void postDocument(Document request, long requestSentTime) throws IOException, Tr
154160
155161 /**
156162 * Method to check whether request sent or not
163+ *
157164 * @return boolean
158165 */
159166 @ Override
@@ -170,6 +177,7 @@ private void addShutdownHook() {
170177
171178 /**
172179 * Thread which calls shutdown method
180+ *
173181 * @return
174182 */
175183 private Thread createShutdownHookThread () {
@@ -187,6 +195,7 @@ public void run() {
187195 /**
188196 * Method to close the httpClient, connectionManager, staleMonitorThread
189197 * when application got shutdown
198+ *
190199 * @throws IOException
191200 */
192201 public static void onShutdown () throws IOException {
@@ -204,12 +213,13 @@ public static void onShutdown() throws IOException {
204213
205214 /**
206215 * Method to close httpResponse
216+ *
207217 * @throws ClientException
208218 */
209219 @ Override
210220 public void release () throws ClientException {
211221 try {
212- if (httpResponse != null ) {
222+ if (httpResponse != null ) {
213223 EntityUtils .consume (httpResponse .getEntity ());
214224 httpResponse .close ();
215225 }
@@ -220,6 +230,7 @@ public void release() throws ClientException {
220230
221231 /**
222232 * Method to get http response code
233+ *
223234 * @return int
224235 */
225236 @ Override
@@ -229,6 +240,7 @@ int getHttpResponseCode() {
229240
230241 /**
231242 * Method to get response stream
243+ *
232244 * @return InputStream
233245 * @throws IOException
234246 */
@@ -239,6 +251,7 @@ InputStream getResponseStream() throws IOException {
239251
240252 /**
241253 * Method to get response error stream
254+ *
242255 * @return InputStream
243256 * @throws IOException
244257 */
@@ -252,7 +265,7 @@ InputStream getResponseErrorStream() throws IOException {
252265 */
253266 @ Override
254267 public void logRequestHeaders () {
255- if (mc .getEnableLog () && httpPost != null ) {
268+ if (mc .getEnableLog () && httpPost != null ) {
256269 List <Header > reqHeaders = Arrays .asList (httpPost .getAllHeaders ());
257270 logger .log (Logger .LT_INFO , "Request Headers: " + reqHeaders );
258271 }
@@ -264,7 +277,7 @@ public void logRequestHeaders() {
264277 */
265278 @ Override
266279 public void logResponseHeaders () {
267- if (mc .getEnableLog () && httpResponse != null ) {
280+ if (mc .getEnableLog () && httpResponse != null ) {
268281 Header responseTimeHeader = httpResponse .getFirstHeader (RESPONSE_TIME_REPLY );
269282 if (responseTimeHeader != null && StringUtils .isNotBlank (responseTimeHeader .getValue ())) {
270283 long resIAT = getResponseIssuedAtTimeInSecs (responseTimeHeader .getValue ());
@@ -279,6 +292,7 @@ public void logResponseHeaders() {
279292
280293 /**
281294 * Conver Document to String
295+ *
282296 * @param request
283297 * @return
284298 * @throws IOException
@@ -309,12 +323,17 @@ public boolean retryRequest(IOException exception, int executionCount, HttpConte
309323 return false ;
310324 }
311325
326+ HttpClientContext httpClientContext = HttpClientContext .adapt (httpContext );
327+ if (!httpClientContext .isRequestSent () && exception instanceof NoHttpResponseException ) {
328+ System .out .println ("retrying as it NoHttpResponseException and request is not sent" );
329+ return true ;
330+ }
331+
312332 if (exception instanceof NoHttpResponseException ) {
333+ System .out .println ("not retrying as it is NoHttpResponseException and request is sent" );
313334 return false ;
314335 }
315336
316- HttpClientContext httpClientContext = HttpClientContext .adapt (httpContext );
317-
318337 if (!httpClientContext .isRequestSent ()) {
319338 try {
320339 Thread .sleep (retryWaitInterval );
@@ -330,6 +349,7 @@ public boolean retryRequest(IOException exception, int executionCount, HttpConte
330349
331350 /**
332351 * Set proxy by using proxy credentials to create httpclient
352+ *
333353 * @param httpClientBuilder
334354 * @param requestConfigBuilder
335355 * @param merchantConfig
0 commit comments