1111import java .util .HashMap ;
1212import java .util .Map ;
1313
14- import net .authorize .Environment ;
15- import net .authorize .ResponseField ;
16- import net .authorize .Transaction ;
17-
1814import org .apache .commons .logging .Log ;
1915import org .apache .commons .logging .LogFactory ;
2016import org .apache .http .HttpEntity ;
2521import org .apache .http .entity .StringEntity ;
2622import org .apache .http .impl .client .DefaultHttpClient ;
2723import org .apache .http .params .CoreProtocolPNames ;
24+ import org .apache .http .params .HttpConnectionParams ;
2825import org .apache .http .protocol .HTTP ;
2926
27+ import net .authorize .Environment ;
28+ import net .authorize .ResponseField ;
29+ import net .authorize .Transaction ;
30+
31+
3032/**
3133 * Transportation object used to facilitate the communication with the respective gateway.
3234 *
@@ -40,9 +42,14 @@ public class HttpClient {
4042 static boolean UseProxy = Environment .getBooleanProperty (Constants .HTTPS_USE_PROXY );
4143 static String ProxyHost = Environment .getProperty (Constants .HTTPS_PROXY_HOST );
4244 static int ProxyPort = Environment .getIntProperty (Constants .HTTPS_PROXY_PORT );
43-
45+ static int httpConnectionTimeout = Environment .getIntProperty (Constants .HTTP_CONNECTION_TIME_OUT );
46+ static int httpReadTimeout = Environment .getIntProperty (Constants .HTTP_READ_TIME_OUT );
47+
4448 static {
4549 LogHelper .info (logger , "Use Proxy: '%s'" , UseProxy );
50+
51+ httpConnectionTimeout = (httpConnectionTimeout == 0 ? Constants .HTTP_CONNECTION_TIME_OUT_DEFAULT_VALUE : httpConnectionTimeout );
52+ httpReadTimeout = (httpReadTimeout == 0 ? Constants .HTTP_READ_TIME_OUT_DEFAULT_VALUE : httpReadTimeout );
4653 }
4754 /**
4855 * Creates the http post object for an environment and transaction container.
@@ -71,18 +78,29 @@ private static HttpPost createHttpPost(Environment env, Transaction transaction)
7178 httpPost = new HttpPost (postUrl );
7279
7380 httpPost .getParams ().setBooleanParameter (CoreProtocolPNames .USE_EXPECT_CONTINUE , false );
81+
82+ //set the tcp connection timeout
83+ httpPost .getParams ().setIntParameter (HttpConnectionParams .CONNECTION_TIMEOUT , httpConnectionTimeout );
84+ //set the time out on read-data request
85+ httpPost .getParams ().setIntParameter (HttpConnectionParams .SO_TIMEOUT , httpReadTimeout );
86+
7487 httpPost .setHeader ("Content-Type" , "application/x-www-form-urlencoded; charset=utf-8" );
75-
76- httpPost .setEntity (new StringEntity (transaction .toNVPString ()));
88+ httpPost .setEntity (new StringEntity (transaction .toNVPString (), HTTP .UTF_8 ));
7789 } else if (transaction instanceof net .authorize .arb .Transaction ||
7890 transaction instanceof net .authorize .cim .Transaction ||
7991 transaction instanceof net .authorize .reporting .Transaction ) {
8092
8193 postUrl = new URI (env .getXmlBaseUrl () + "/xml/v1/request.api" );
8294 httpPost = new HttpPost (postUrl );
83- httpPost .getParams ().setBooleanParameter (CoreProtocolPNames .USE_EXPECT_CONTINUE , false );
84- httpPost .setHeader ("Content-Type" , "text/xml; charset=utf-8" );
85- httpPost .setEntity (new StringEntity (transaction .toXMLString ()));
95+ httpPost .getParams ().setBooleanParameter (CoreProtocolPNames .USE_EXPECT_CONTINUE , false );
96+
97+ //set the TCP connection timeout
98+ httpPost .getParams ().setIntParameter (HttpConnectionParams .CONNECTION_TIMEOUT , httpConnectionTimeout );
99+ //set the time out on read-data request
100+ httpPost .getParams ().setIntParameter (HttpConnectionParams .SO_TIMEOUT , httpReadTimeout );
101+
102+ httpPost .setHeader ("Content-Type" , "text/xml; charset=utf-8" );
103+ httpPost .setEntity (new StringEntity (transaction .toXMLString (), HTTP .UTF_8 ));
86104 }
87105
88106 return httpPost ;
0 commit comments