2424import org .apache .http .conn .params .ConnRoutePNames ;
2525import org .apache .http .entity .StringEntity ;
2626import org .apache .http .impl .client .DefaultHttpClient ;
27+ import org .apache .http .params .BasicHttpParams ;
2728import org .apache .http .params .CoreProtocolPNames ;
29+ import org .apache .http .params .HttpConnectionParams ;
30+ import org .apache .http .params .HttpParams ;
2831import org .apache .http .protocol .HTTP ;
2932
33+
3034/**
3135 * Transportation object used to facilitate the communication with the respective gateway.
3236 *
@@ -40,7 +44,9 @@ public class HttpClient {
4044 static boolean UseProxy = Environment .getBooleanProperty (Constants .HTTPS_USE_PROXY );
4145 static String ProxyHost = Environment .getProperty (Constants .HTTPS_PROXY_HOST );
4246 static int ProxyPort = Environment .getIntProperty (Constants .HTTPS_PROXY_PORT );
43-
47+ static int httpConnectionTimeout = Environment .getIntProperty (Constants .HTTP_CONNECTION_TIME_OUT );
48+ static int httpReadTimeout = Environment .getIntProperty (Constants .HTTP_READ_TIME_OUT );
49+
4450 static {
4551 LogHelper .info (logger , "Use Proxy: '%s'" , UseProxy );
4652 }
@@ -71,17 +77,28 @@ private static HttpPost createHttpPost(Environment env, Transaction transaction)
7177 httpPost = new HttpPost (postUrl );
7278
7379 httpPost .getParams ().setBooleanParameter (CoreProtocolPNames .USE_EXPECT_CONTINUE , false );
80+
81+ //set the tcp connection timeout
82+ httpPost .getParams ().setIntParameter (HttpConnectionParams .CONNECTION_TIMEOUT , httpConnectionTimeout );
83+ //set the time out on read-data request
84+ httpPost .getParams ().setIntParameter (HttpConnectionParams .SO_TIMEOUT , httpReadTimeout );
85+
7486 httpPost .setHeader ("Content-Type" , "application/x-www-form-urlencoded; charset=utf-8" );
75-
7687 httpPost .setEntity (new StringEntity (transaction .toNVPString ()));
7788 } else if (transaction instanceof net .authorize .arb .Transaction ||
7889 transaction instanceof net .authorize .cim .Transaction ||
7990 transaction instanceof net .authorize .reporting .Transaction ) {
8091
8192 postUrl = new URI (env .getXmlBaseUrl () + "/xml/v1/request.api" );
8293 httpPost = new HttpPost (postUrl );
83- httpPost .getParams ().setBooleanParameter (CoreProtocolPNames .USE_EXPECT_CONTINUE , false );
84- httpPost .setHeader ("Content-Type" , "text/xml; charset=utf-8" );
94+ httpPost .getParams ().setBooleanParameter (CoreProtocolPNames .USE_EXPECT_CONTINUE , false );
95+
96+ //set the TCP connection timeout
97+ httpPost .getParams ().setIntParameter (HttpConnectionParams .CONNECTION_TIMEOUT , httpConnectionTimeout );
98+ //set the time out on read-data request
99+ httpPost .getParams ().setIntParameter (HttpConnectionParams .SO_TIMEOUT , httpReadTimeout );
100+
101+ httpPost .setHeader ("Content-Type" , "text/xml; charset=utf-8" );
85102 httpPost .setEntity (new StringEntity (transaction .toXMLString ()));
86103 }
87104
0 commit comments