|
4 | 4 | import java.io.IOException; |
5 | 5 | import java.io.InputStream; |
6 | 6 | import java.io.InputStreamReader; |
7 | | -import java.io.UnsupportedEncodingException; |
8 | | -import java.net.URI; |
9 | | -import java.net.URLDecoder; |
10 | 7 | import java.security.KeyStore; |
11 | | -import java.util.Arrays; |
12 | | -import java.util.HashMap; |
13 | | -import java.util.Map; |
14 | 8 |
|
15 | 9 | import javax.net.ssl.SSLContext; |
16 | 10 | import javax.net.ssl.TrustManagerFactory; |
17 | 11 |
|
18 | 12 | import org.apache.commons.logging.Log; |
19 | 13 | import org.apache.commons.logging.LogFactory; |
20 | | -import org.apache.http.HttpEntity; |
21 | 14 | import org.apache.http.HttpHost; |
22 | | -import org.apache.http.HttpResponse; |
23 | 15 | import org.apache.http.auth.AuthScope; |
24 | 16 | import org.apache.http.auth.Credentials; |
25 | 17 | import org.apache.http.auth.UsernamePasswordCredentials; |
26 | 18 | import org.apache.http.client.CredentialsProvider; |
27 | 19 | import org.apache.http.client.config.RequestConfig; |
28 | | -import org.apache.http.client.methods.HttpPost; |
29 | | -import org.apache.http.conn.params.ConnRoutePNames; |
30 | 20 | import org.apache.http.conn.socket.LayeredConnectionSocketFactory; |
31 | 21 | import org.apache.http.conn.ssl.SSLConnectionSocketFactory; |
32 | | -import org.apache.http.entity.StringEntity; |
33 | 22 | import org.apache.http.impl.client.BasicCredentialsProvider; |
34 | 23 | import org.apache.http.impl.client.CloseableHttpClient; |
35 | | -import org.apache.http.impl.client.DefaultHttpClient; |
36 | 24 | import org.apache.http.impl.client.HttpClientBuilder; |
37 | 25 | import org.apache.http.impl.client.HttpClients; |
38 | 26 | import org.apache.http.impl.client.LaxRedirectStrategy; |
39 | | -import org.apache.http.impl.conn.DefaultProxyRoutePlanner; |
40 | | -import org.apache.http.params.CoreProtocolPNames; |
41 | | -import org.apache.http.params.HttpConnectionParams; |
42 | | -import org.apache.http.protocol.HTTP; |
43 | 27 |
|
44 | 28 | import net.authorize.Environment; |
45 | | -import net.authorize.ResponseField; |
46 | | -import net.authorize.Transaction; |
47 | 29 |
|
48 | 30 | /** |
49 | 31 | * Transportation object used to facilitate the communication with the |
@@ -73,141 +55,8 @@ public class HttpClient { |
73 | 55 | httpReadTimeout = (httpReadTimeout == 0 ? Constants.HTTP_READ_TIME_OUT_DEFAULT_VALUE : httpReadTimeout); |
74 | 56 | } |
75 | 57 |
|
76 | | - /** |
77 | | - * Creates the http post object for an environment and transaction container. |
78 | | - * |
79 | | - * @param env |
80 | | - * @param transaction |
81 | | - * @return HttpPost object |
82 | | - * |
83 | | - * @throws Exception |
84 | | - */ |
85 | | - @Deprecated |
86 | | - private static HttpPost createHttpPost(Environment env, Transaction transaction) throws Exception { |
87 | | - URI postUrl; |
88 | | - HttpPost httpPost = null; |
89 | | - |
90 | | - /* |
91 | | - * if(transaction instanceof net.authorize.aim.Transaction || transaction |
92 | | - * instanceof net.authorize.sim.Transaction) { |
93 | | - * |
94 | | - * if(transaction instanceof net.authorize.aim.Transaction && |
95 | | - * ((net.authorize.aim.Transaction)transaction).isCardPresent()) { |
96 | | - */ |
97 | | - |
98 | | - postUrl = new URI(env.getCardPresentUrl() + "/gateway/transact.dll"); |
99 | | - /* } else { */ |
100 | | - postUrl = new URI(env.getBaseUrl() + "/gateway/transact.dll"); |
101 | | - /* } */ |
102 | | - |
103 | | - httpPost = new HttpPost(postUrl); |
104 | | - |
105 | | - httpPost.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); |
106 | | - |
107 | | - // set the tcp connection timeout |
108 | | - httpPost.getParams().setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, httpConnectionTimeout); |
109 | | - // set the time out on read-data request |
110 | | - httpPost.getParams().setIntParameter(HttpConnectionParams.SO_TIMEOUT, httpReadTimeout); |
111 | | - |
112 | | - httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); |
113 | | - httpPost.setEntity(new StringEntity(transaction.toNVPString(), HTTP.UTF_8)); |
114 | | - /* |
115 | | - * } else if (transaction instanceof net.authorize.arb.Transaction || |
116 | | - * transaction instanceof net.authorize.cim.Transaction || transaction |
117 | | - * instanceof net.authorize.reporting.Transaction) { |
118 | | - */ |
119 | | - |
120 | | - postUrl = new URI(env.getXmlBaseUrl() + "/xml/v1/request.api"); |
121 | | - httpPost = new HttpPost(postUrl); |
122 | | - httpPost.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); |
123 | | - |
124 | | - // set the TCP connection timeout |
125 | | - httpPost.getParams().setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, httpConnectionTimeout); |
126 | | - // set the time out on read-data request |
127 | | - httpPost.getParams().setIntParameter(HttpConnectionParams.SO_TIMEOUT, httpReadTimeout); |
128 | | - |
129 | | - httpPost.setHeader("Content-Type", "text/xml; charset=utf-8"); |
130 | | - httpPost.setEntity(new StringEntity(transaction.toXMLString(), HTTP.UTF_8)); |
131 | | - /* } */ |
132 | 58 |
|
133 | | - return httpPost; |
134 | | - } |
135 | | - |
136 | | - /** |
137 | | - * Creates a response map for a given response string and transaction container. |
138 | | - * |
139 | | - * @param transaction |
140 | | - * @param responseString |
141 | | - * @return container map containing semi-processed data after request was posted |
142 | | - * @throws UnsupportedEncodingException |
143 | | - */ |
144 | | - /* @Deprecated */ |
145 | | - /* |
146 | | - * private static Map<ResponseField, String> createResponseMap(Transaction |
147 | | - * transaction, String responseString) throws UnsupportedEncodingException { |
148 | | - * |
149 | | - * Map<ResponseField, String> responseMap = null; |
150 | | - * |
151 | | - * // aim/sim if(transaction instanceof net.authorize.aim.Transaction || |
152 | | - * transaction instanceof net.authorize.sim.Transaction) { |
153 | | - * |
154 | | - * String decodedResponseData = URLDecoder.decode(responseString, HTTP.UTF_8); |
155 | | - * |
156 | | - * |
157 | | - * responseMap = ResponseParser.parseResponseString(decodedResponseData); } |
158 | | - * |
159 | | - * return responseMap; } |
160 | | - */ |
161 | | - |
162 | | - /** |
163 | | - * Executes a Transaction against a given Environment. |
164 | | - * |
165 | | - * @param environment |
166 | | - * @param transaction |
167 | | - * @return container map containing semi-processed data after request was posted |
168 | | - */ |
169 | | - /* @Deprecated */ |
170 | | - /* |
171 | | - * public static Map<ResponseField, String> execute(Environment environment, |
172 | | - * Transaction transaction) { Map<ResponseField, String> responseMap = new |
173 | | - * HashMap<ResponseField, String>(); |
174 | | - * |
175 | | - * if(environment != null && transaction != null) { try { CloseableHttpClient |
176 | | - * httpClient = getHttpsClient(); |
177 | | - * |
178 | | - * // create the HTTP POST object HttpPost httpPost = |
179 | | - * createHttpPost(environment, transaction); |
180 | | - * |
181 | | - * // execute the request HttpResponse httpResponse = |
182 | | - * httpClient.execute(httpPost); String rawResponseString; if(httpResponse != |
183 | | - * null && httpResponse.getStatusLine().getStatusCode() == 200) { HttpEntity |
184 | | - * entity = httpResponse.getEntity(); |
185 | | - * |
186 | | - * // get the raw data being received InputStream instream = |
187 | | - * entity.getContent(); rawResponseString = convertStreamToString(instream); } |
188 | | - * // handle HTTP errors else { StringBuilder responseBuilder = new |
189 | | - * StringBuilder(); |
190 | | - * responseBuilder.append(3).append(net.authorize.aim.Transaction. |
191 | | - * TRANSACTION_FIELD_DELIMITER); |
192 | | - * responseBuilder.append(3).append(net.authorize.aim.Transaction. |
193 | | - * TRANSACTION_FIELD_DELIMITER); |
194 | | - * responseBuilder.append(22).append(net.authorize.aim.Transaction. |
195 | | - * TRANSACTION_FIELD_DELIMITER); responseBuilder.append(httpResponse != null ? |
196 | | - * httpResponse.getStatusLine().getReasonPhrase() : " "); rawResponseString = |
197 | | - * responseBuilder.toString(); } |
198 | | - * |
199 | | - * httpClient.getConnectionManager().shutdown(); |
200 | | - * |
201 | | - * String cleanResponseString = |
202 | | - * XmlUtility.descapeStringForXml(rawResponseString); |
203 | | - * |
204 | | - * responseMap = HttpClient.createResponseMap(transaction, cleanResponseString); |
205 | | - * } catch (Exception e) { LogHelper.warn(logger, |
206 | | - * "Exception getting response: '%s': '%s', '%s'", e.getMessage(), e.getCause(), |
207 | | - * Arrays.toString(e.getStackTrace())); } } |
208 | | - * |
209 | | - * return responseMap; } |
210 | | - */ |
| 59 | + |
211 | 60 |
|
212 | 61 | /** |
213 | 62 | * Converts a response inputstream into a string. |
@@ -247,71 +96,7 @@ public static String convertStreamToString(InputStream is) { |
247 | 96 | return sb.toString(); |
248 | 97 | } |
249 | 98 |
|
250 | | - /** |
251 | | - * Executes a Transaction against a given Environment. |
252 | | - * |
253 | | - * @param environment |
254 | | - * @param transaction |
255 | | - * @return BasicXmlDocument containing semi-processed data after request was |
256 | | - * posted |
257 | | - */ |
258 | | - /* |
259 | | - * @Deprecated public static BasicXmlDocument executeXML(Environment |
260 | | - * environment, Transaction transaction) { BasicXmlDocument response = new |
261 | | - * BasicXmlDocument(); |
262 | | - * |
263 | | - * if(environment != null && transaction != null) { try { CloseableHttpClient |
264 | | - * httpClient = getHttpsClient(); |
265 | | - * |
266 | | - * // create the HTTP POST object HttpPost httpPost = |
267 | | - * createHttpPost(environment, transaction); |
268 | | - * |
269 | | - * // execute the request HttpResponse httpResponse = |
270 | | - * httpClient.execute(httpPost); String rawResponseString; if(httpResponse != |
271 | | - * null && httpResponse.getStatusLine().getStatusCode() == 200) { HttpEntity |
272 | | - * entity = httpResponse.getEntity(); |
273 | | - * |
274 | | - * // get the raw data being received InputStream instream = |
275 | | - * entity.getContent(); rawResponseString = convertStreamToString(instream); } |
276 | | - * else { StringBuilder responseBuilder = new StringBuilder(); if(transaction |
277 | | - * instanceof net.authorize.arb.Transaction || transaction instanceof |
278 | | - * net.authorize.cim.Transaction || transaction instanceof |
279 | | - * net.authorize.reporting.Transaction) { |
280 | | - * |
281 | | - * responseBuilder.append("<?xml version=\"1.0\" ?>"); |
282 | | - * responseBuilder.append("<messages><resultCode>Error</resultCode>"); |
283 | | - * responseBuilder.append("<message><code>E00001</code>"); |
284 | | - * responseBuilder.append("<text>"); responseBuilder.append(httpResponse != |
285 | | - * null?httpResponse.getStatusLine().getReasonPhrase():""); |
286 | | - * responseBuilder.append("</text></message></messages>"); } else { |
287 | | - * responseBuilder.append("<?xml version=\"1.0\" ?>"); |
288 | | - * responseBuilder.append("<response>"); |
289 | | - * responseBuilder.append("<ResponseCode>3</ResponseCode>"); |
290 | | - * responseBuilder.append( |
291 | | - * "<Errors><Error><ErrorCode>22</ErrorCode><ErrorText><![CDATA["); |
292 | | - * responseBuilder.append(httpResponse != |
293 | | - * null?httpResponse.getStatusLine().getReasonPhrase():""); |
294 | | - * responseBuilder.append("]]></ErrorText></Error></Errors></response>"); } |
295 | | - * |
296 | | - * rawResponseString = responseBuilder.toString(); } |
297 | | - * |
298 | | - * |
299 | | - * httpClient.getConnectionManager().shutdown(); |
300 | | - * |
301 | | - * if(rawResponseString == null) return null; |
302 | | - * |
303 | | - * |
304 | | - * int mark = rawResponseString.indexOf("<?xml"); if(mark == -1){ return null; } |
305 | | - * |
306 | | - * response.parseString(rawResponseString.substring(mark,rawResponseString. |
307 | | - * length())); if(response.IsAccessible() == false){ return null; } } catch |
308 | | - * (Exception e) { LogHelper.warn(logger, |
309 | | - * "Exception getting response: '%s': '%s', '%s'", e.getMessage(), e.getCause(), |
310 | | - * Arrays.toString(e.getStackTrace())); } } |
311 | | - * |
312 | | - * return response; } |
313 | | - */ |
314 | | - |
| 99 | + |
315 | 100 | /** |
316 | 101 | * @return returns an SSL context with TLSv1.2 protocol instance to be used in |
317 | 102 | * the call |
|
0 commit comments