Skip to content

Commit 15e0d3f

Browse files
author
Sunny Raj Rathod
authored
Merge pull request #131 from AuthorizeNet/future
Future
2 parents 10b7be2 + c37e1ca commit 15e0d3f

6 files changed

Lines changed: 64 additions & 11 deletions

File tree

.classpath

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<classpathentry kind="src" path="resources"/>
55
<classpathentry kind="src" path="src/test/java"/>
66
<classpathentry kind="lib" path="lib/commons-logging-1.1.1.jar"/>
7-
<classpathentry kind="lib" path="lib/httpclient-4.0.1.jar"/>
8-
<classpathentry kind="lib" path="lib/httpcore-4.0.1.jar"/>
7+
<classpathentry kind="lib" path="lib/httpclient-4.5.3.jar"/>
8+
<classpathentry kind="lib" path="lib/httpcore-4.4.6.jar"/>
99
<classpathentry kind="lib" path="lib/junit-4.8.2.jar"/>
1010
<classpathentry kind="lib" path="lib/log4j-1.2.16.jar"/>
1111
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>

src/main/java/net/authorize/aim/Result.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class Result<T> extends net.authorize.Result<T> {
1717
private ResponseCode responseCode;
1818
private ResponseReasonCode reasonResponseCode;
1919
private String responseText;
20+
private String transactionId;
2021

2122
private Result() { }
2223

@@ -29,8 +30,11 @@ public static <T> Result<T> createResult(T object, Map<ResponseField, String> re
2930
}
3031

3132
String responseCodeStr = responseMap.get(ResponseField.RESPONSE_CODE);
33+
34+
result.transactionId = responseMap.get(ResponseField.TRANSACTION_ID);
35+
3236
result.responseCode = responseCodeStr!=null && !"".equals(responseCodeStr)?
33-
ResponseCode.findByResponseCode(Integer.parseInt(responseCodeStr)):
37+
ResponseCode.findByResponseCode(Double.valueOf(responseCodeStr).intValue()):
3438
ResponseCode.ERROR;
3539

3640
String responseReasonCodeStr = responseMap.get(ResponseField.RESPONSE_REASON_CODE);
@@ -58,6 +62,10 @@ public String getResponseText() {
5862
return responseText;
5963
}
6064

65+
public String getTransactionId() {
66+
return transactionId;
67+
}
68+
6169
public boolean isApproved() {
6270
return ResponseCode.APPROVED.equals(this.responseCode);
6371
}

src/main/java/net/authorize/api/controller/GetCustomerProfileController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ protected void validateRequest() {
1616
GetCustomerProfileRequest request = this.getApiRequest();
1717

1818
//validate required fields
19-
if ( null == request.getCustomerProfileId()) throw new NullPointerException("CustomerProfileId cannot be null");
20-
19+
2120
//validate not-required fields
2221
//creditCardOne.setCardCode("");
2322
}

src/main/java/net/authorize/sim/Result.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static Result createResult(String apiLoginId, String merchantMD5Key, Map<
6969
}
7070

7171
result.responseCode = responseCodeStr!=null && !"".equals(responseCodeStr)?
72-
ResponseCode.findByResponseCode(Integer.parseInt(responseCodeStr)):
72+
ResponseCode.findByResponseCode(Double.valueOf(responseCodeStr).intValue()):
7373
ResponseCode.UNKNOWN;
7474
result.reasonResponseCode = responseReasonCodeStr!=null && !"".equals(responseReasonCodeStr)?
7575
ResponseReasonCode.findByReasonCode(Integer.parseInt(responseReasonCodeStr)):

src/main/java/net/authorize/util/HttpCallTask.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ public ANetApiResponse call() throws Exception {
6363
ANetApiResponse response = null;
6464
StringBuilder buffer = new StringBuilder();
6565

66-
DefaultHttpClient httpCaller = null;
66+
org.apache.http.client.HttpClient httpCaller = null;
6767

6868
try {
6969
HttpPost httppost = HttpUtility.createPostRequest(this.env, this.request);
70-
httpCaller = new DefaultHttpClient();
70+
httpCaller = HttpClient.getHttpsClient();
7171
HttpClient.setProxyIfRequested(httpCaller);
7272
HttpResponse httpResponse = httpCaller.execute(httppost);
7373

src/main/java/net/authorize/util/HttpClient.java

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,28 @@
77
import java.io.UnsupportedEncodingException;
88
import java.net.URI;
99
import java.net.URLDecoder;
10+
import java.security.KeyStore;
1011
import java.util.Arrays;
1112
import java.util.HashMap;
1213
import java.util.Map;
1314

15+
import javax.net.ssl.SSLContext;
16+
import javax.net.ssl.TrustManagerFactory;
17+
1418
import org.apache.commons.logging.Log;
1519
import org.apache.commons.logging.LogFactory;
1620
import org.apache.http.HttpEntity;
1721
import org.apache.http.HttpHost;
1822
import org.apache.http.HttpResponse;
23+
import org.apache.http.client.config.RequestConfig;
1924
import org.apache.http.client.methods.HttpPost;
2025
import org.apache.http.conn.params.ConnRoutePNames;
26+
import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
27+
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
2128
import org.apache.http.entity.StringEntity;
2229
import org.apache.http.impl.client.DefaultHttpClient;
30+
import org.apache.http.impl.client.HttpClients;
31+
import org.apache.http.impl.client.LaxRedirectStrategy;
2332
import org.apache.http.params.CoreProtocolPNames;
2433
import org.apache.http.params.HttpConnectionParams;
2534
import org.apache.http.protocol.HTTP;
@@ -144,7 +153,7 @@ public static Map<ResponseField, String> execute(Environment environment, Transa
144153

145154
if(environment != null && transaction != null) {
146155
try {
147-
DefaultHttpClient httpClient = new DefaultHttpClient();
156+
org.apache.http.client.HttpClient httpClient = getHttpsClient();
148157

149158
setProxyIfRequested(httpClient);
150159

@@ -234,7 +243,7 @@ public static BasicXmlDocument executeXML(Environment environment, Transaction t
234243

235244
if(environment != null && transaction != null) {
236245
try {
237-
DefaultHttpClient httpClient = new DefaultHttpClient();
246+
org.apache.http.client.HttpClient httpClient = getHttpsClient();
238247

239248
setProxyIfRequested(httpClient);
240249

@@ -302,7 +311,7 @@ public static BasicXmlDocument executeXML(Environment environment, Transaction t
302311
* if proxy use is requested, set http-client appropriately
303312
* @param httpClient the client to add proxy values to
304313
*/
305-
public static void setProxyIfRequested(DefaultHttpClient httpClient) {
314+
public static void setProxyIfRequested(org.apache.http.client.HttpClient httpClient) {
306315
if ( UseProxy)
307316
{
308317
if ( !proxySet) {
@@ -313,4 +322,41 @@ public static void setProxyIfRequested(DefaultHttpClient httpClient) {
313322
httpClient.getParams().setParameter( ConnRoutePNames.DEFAULT_PROXY, proxyHttpHost);
314323
}
315324
}
325+
326+
/**
327+
* @return returns an SSL context with TLSv1.2 protocol instance to be used in the call
328+
*/
329+
private static SSLContext getSSLContext() {
330+
try {
331+
final SSLContext sc = SSLContext.getInstance("TLSv1.2");
332+
final TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
333+
trustManagerFactory.init((KeyStore) null);
334+
sc.init(null, trustManagerFactory.getTrustManagers(), new java.security.SecureRandom());
335+
return sc;
336+
}
337+
catch (Exception e) {
338+
e.printStackTrace();
339+
return null;
340+
}
341+
}
342+
343+
/**
344+
* Returns a HTTPClient instance which enforce TLSv1.2 protocol for all the calls
345+
* @return org.apache.http.client.HttpClient instance
346+
* @throws Exception
347+
*/
348+
static org.apache.http.client.HttpClient getHttpsClient() throws Exception {
349+
SSLContext sslcontext = getSSLContext();
350+
try {
351+
LayeredConnectionSocketFactory sslSocketFactory = new org.apache.http.conn.ssl.SSLConnectionSocketFactory(sslcontext, SSLConnectionSocketFactory.STRICT_HOSTNAME_VERIFIER);
352+
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(httpConnectionTimeout).build();
353+
return HttpClients.custom()
354+
.setSSLSocketFactory(sslSocketFactory)
355+
.setDefaultRequestConfig(requestConfig)
356+
.setRedirectStrategy(new LaxRedirectStrategy())
357+
.build();
358+
} catch (Exception e) {
359+
return null;
360+
}
361+
}
316362
}

0 commit comments

Comments
 (0)