Skip to content

Commit ac5c802

Browse files
committed
Separate out connection and socket timeout prop and removing httpclient3.1 jar
1 parent 40e71d0 commit ac5c802

17 files changed

Lines changed: 368 additions & 309 deletions

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,19 +232,18 @@ Retry Pattern allows to retry sending a failed request and it will only work wit
232232
The XML Security project is aimed at providing implementation of security standards for XML,supports XML-Signature Syntax and Processing,XML Encryption Syntax and Processing, and supports XML Digital Signature APIs.
233233
4. org.apache.commons:commons-lang3:3.4
234234
Apache Commons Lang, a package of Java utility classes for the classes that are in java.lang's hierarchy, or are considered to be so standard as to justify existence in java.lang.
235-
5. commons-httpclient:commons-httpclient:3.1
236-
Provides a framework by which new request types (methods) or HTTP extensions can be created easily.
237-
6. commons-logging:commons-logging:jar:1.1.1
235+
5. commons-logging:commons-logging:jar:1.1.1
238236
This is getting downloaded as compile time dependency of wss4j:1.6.19.Apache Commons Logging is a thin adapter allowing configurable bridging to other, well known logging systems.
239-
7. org.slf4j:slf4j-api:1.7.21 and org.slf4j:slf4j-jcl:1.7.21
237+
6. org.slf4j:slf4j-api:1.7.21 and org.slf4j:slf4j-jcl:1.7.21
240238
slf4j-api is getting used as a dependency for wss4j. Modified to latest version.
241-
8. junit:junit:4.13.1
239+
7. junit:junit:4.13.1
242240
JUnit is a unit testing framework for Java.
243-
9. org.mockito:mockito-all:1.10.19
241+
8. org.mockito:mockito-all:1.10.19
244242
Mock objects library for java
245-
10. org.apache.httpcomponents:httpclient:4.5.11
243+
9. org.apache.httpcomponents:httpclient:4.5.11
246244
Provides reusable components for client-side authentication, HTTP state management, and HTTP connection management. It is used for poolinghttpclientconnectionmanager feature.
247-
245+
10. org.apache.httpcomponents:httpcore:4.4.13
246+
Provides low level HTTP transport components that can be used to build custom client and server side HTTP services with a minimal footprint.
248247

249248
## Changes
250249
_______________________________

java/pom.xml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -243,18 +243,7 @@
243243
</exclusion>
244244
</exclusions>
245245
</dependency>
246-
<dependency>
247-
<groupId>commons-httpclient</groupId>
248-
<artifactId>commons-httpclient</artifactId>
249-
<version>3.1</version>
250-
<exclusions>
251-
<exclusion>
252-
<groupId>commons-logging</groupId>
253-
<artifactId>commons-logging</artifactId>
254-
</exclusion>
255-
</exclusions>
256-
</dependency>
257-
<dependency>
246+
<dependency>
258247
<groupId>org.bouncycastle</groupId>
259248
<artifactId>bcprov-jdk15on</artifactId>
260249
<version>1.61</version>

java/src/main/java/com/cybersource/ws/client/ConnectionHelper.java

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818

1919
package com.cybersource.ws.client;
2020

21+
import org.apache.http.HttpHost;
22+
import org.apache.http.auth.AuthScope;
23+
import org.apache.http.auth.UsernamePasswordCredentials;
24+
import org.apache.http.client.CredentialsProvider;
25+
import org.apache.http.client.config.AuthSchemes;
26+
import org.apache.http.client.config.RequestConfig;
27+
import org.apache.http.impl.client.BasicCredentialsProvider;
28+
import org.apache.http.impl.client.HttpClientBuilder;
29+
import org.apache.http.impl.client.ProxyAuthenticationStrategy;
30+
import org.apache.http.impl.conn.DefaultProxyRoutePlanner;
2131
import org.bouncycastle.util.encoders.Base64;
2232

2333
import java.io.IOException;
@@ -26,6 +36,7 @@
2636
import java.net.Proxy;
2737
import java.net.URL;
2838
import java.nio.charset.Charset;
39+
import java.util.Collections;
2940

3041
/**
3142
* Helps in creating the Proxy and adding Proxy credentials to JDKHttpURLConnection.
@@ -45,12 +56,11 @@ public static boolean getDefaultUseHttpClient() {
4556
/**
4657
* Sets the timeout for HTTP Request
4758
* @param con - HttpURLConnection
48-
* @param timeout - timeout integer value
59+
* @param mc - MerchantConfig
4960
*/
50-
public static void setTimeout(HttpURLConnection con, int timeout) {
51-
int timeoutInMS = timeout * 1000;
52-
con.setConnectTimeout(timeoutInMS);
53-
con.setReadTimeout(timeoutInMS);
61+
public static void setTimeout(HttpURLConnection con, MerchantConfig mc) {
62+
con.setConnectTimeout(mc.getConnectionTimeoutMs());
63+
con.setReadTimeout(mc.getSocketTimeoutMs());
5464
}
5565

5666
/**
@@ -108,4 +118,30 @@ private static void addProxyCredentials(
108118

109119
}
110120
}
121+
122+
/**
123+
* Set proxy by using proxy credentials to create httpclient
124+
*
125+
* @param httpClientBuilder
126+
* @param requestConfigBuilder
127+
* @param merchantConfig
128+
*/
129+
public static void setProxy(HttpClientBuilder httpClientBuilder, RequestConfig.Builder requestConfigBuilder, MerchantConfig merchantConfig) {
130+
if (merchantConfig.getProxyHost() != null) {
131+
HttpHost proxy = new HttpHost(merchantConfig.getProxyHost(), merchantConfig.getProxyPort());
132+
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
133+
httpClientBuilder.setRoutePlanner(routePlanner);
134+
135+
if (merchantConfig.getProxyUser() != null) {
136+
httpClientBuilder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy());
137+
requestConfigBuilder.setProxyPreferredAuthSchemes(Collections.singletonList(AuthSchemes.BASIC));
138+
139+
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
140+
credentialsProvider.setCredentials(AuthScope.ANY,
141+
new UsernamePasswordCredentials(merchantConfig.getProxyUser(), merchantConfig.getProxyPassword()));
142+
143+
httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
144+
}
145+
}
146+
}
111147
}

0 commit comments

Comments
 (0)