1515
1616import javax .xml .bind .JAXBException ;
1717
18- import net .authorize .Environment ;
19- import net .authorize .api .contract .v1 .ANetApiRequest ;
20- import net .authorize .api .contract .v1 .ANetApiResponse ;
21-
2218import org .apache .commons .logging .Log ;
2319import org .apache .commons .logging .LogFactory ;
2420import org .apache .http .client .methods .HttpPost ;
2521import org .apache .http .entity .StringEntity ;
2622import org .apache .http .params .CoreProtocolPNames ;
23+ import org .apache .http .params .HttpConnectionParams ;
24+
25+ import net .authorize .Environment ;
26+ import net .authorize .api .contract .v1 .ANetApiRequest ;
27+ import net .authorize .api .contract .v1 .ANetApiResponse ;
2728
2829/**
2930 * Helper methods for http calls
@@ -34,6 +35,15 @@ public final class HttpUtility {
3435
3536 private static Log logger = LogFactory .getLog (HttpUtility .class );
3637
38+ static int httpConnectionTimeout = Environment .getIntProperty (Constants .HTTP_CONNECTION_TIME_OUT );
39+ static int httpReadTimeout = Environment .getIntProperty (Constants .HTTP_READ_TIME_OUT );
40+
41+ static {
42+
43+ httpConnectionTimeout = (httpConnectionTimeout == 0 ? Constants .HTTP_CONNECTION_TIME_OUT_DEFAULT_VALUE : httpConnectionTimeout );
44+ httpReadTimeout = (httpReadTimeout == 0 ? Constants .HTTP_READ_TIME_OUT_DEFAULT_VALUE : httpReadTimeout );
45+ }
46+
3747 /**
3848 * Default C'tor, cannot be instantiated
3949 */
@@ -60,7 +70,13 @@ static HttpPost createPostRequest(Environment env, ANetApiRequest request) throw
6070 logger .debug (String .format ("MerchantInfo->LoginId/TransactionKey: '%s':'%s'" , request .getMerchantAuthentication ().getName (), request .getMerchantAuthentication ().getTransactionKey () ));
6171 logger .debug (String .format ("Posting request to Url: '%s'" , postUrl ));
6272 httpPost = new HttpPost (postUrl );
63- httpPost .getParams ().setBooleanParameter (CoreProtocolPNames .USE_EXPECT_CONTINUE , false );
73+ httpPost .getParams ().setBooleanParameter (CoreProtocolPNames .USE_EXPECT_CONTINUE , false );
74+
75+ //set the tcp connection timeout
76+ httpPost .getParams ().setIntParameter (HttpConnectionParams .CONNECTION_TIMEOUT , httpConnectionTimeout );
77+ //set the time out on read-data request
78+ httpPost .getParams ().setIntParameter (HttpConnectionParams .SO_TIMEOUT , httpReadTimeout );
79+
6480 httpPost .setHeader ("Content-Type" , "text/xml; charset=utf-8" );
6581
6682 String xmlRequest = XmlUtility .getXml (request );
0 commit comments