Skip to content

Commit bd6eede

Browse files
committed
sync
2 parents 0f94195 + 7b9af39 commit bd6eede

6 files changed

Lines changed: 50 additions & 30 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ You do not need to download and build the source to use the SDK but if you want
6666
- If `useHttpClientWithConnectionPool` parameter is set to true (default is false), then poolingHttpClientConnection will be enabled
6767
- In case of poolingHttpConnection, we are initializing connection manager and httpclient once, If any change in value in between the application is running, it will not reflect. need to restart it.
6868
- Refer to the [PoolingHttpClient Shutdown](README.md#poolinghttpclientshutdown) section below.
69+
- If`enabledShutdownHook` is true (default is true), enables JVM runtime shutdown hook and execute our shutdown api. This is applicable only when useHttpClientWithConnectionPool is true.
6970
- Below properties are specific to poolinghttpclient connection, If it is not added in properties file, it will throw config exception.
7071
Note : Below default values used in properties files are based on our testing application factors such as TPS, CPU, JVM, OS etc
7172
Before using these values in actual real time application, please consider all real time factors. Refer this link for more detailed explanation.
@@ -166,7 +167,7 @@ try {
166167

167168
## PoolingHttpClientShutdown
168169
In case of PoolingHttpClient Connection, we need to close the connection manager, http client and idle connection cleaner thread when application got shutdown abruptly or gracefully.
169-
JVM runtime addShutdownHook method will be initialized.
170+
If `enabledShutdownHook` is true, then JVM runtime addShutdownHook method will be initialized.
170171
Shutdown Hooks are a special construct that allows developers to plug in a piece of code to be executed when the JVM is shutting down. This comes in handy in cases where we need to do special clean up operations in case the VM is shutting down.
171172
private void addShutdownHook() {
172173
Runtime.getRuntime().addShutdownHook(this.createShutdownHookThread());
@@ -227,6 +228,7 @@ _______________________________
227228
2)Added PoolingHttpClientConnection implementation
228229
3)Changed retry interval from second to millisecond
229230
4)Added one more request header "v-c-client-computetime" to calculate time taken to send request to cybersource
231+
230232

231233
Version Cybersource-sdk-java 6.2.9 (APR,2020)
232234
_______________________________

java/src/test/java/com/cybersource/ws/client/PoolingHttpClientConnectionIT.java

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public class PoolingHttpClientConnectionIT {
5151
}
5252
}
5353

54+
private String message= "pooling httpclient is disabled";
55+
5456
@Before
5557
public void start(){
5658
Properties merchantProperties = new Properties();
@@ -68,12 +70,15 @@ public void start(){
6870
builder = Utility.newDocumentBuilder();
6971
request = Utility.readRequest(merchantProperties, requestFilename);
7072
mc = new MerchantConfig(merchantProperties, null);
71-
String merchantID = mc.getMerchantID();
72-
String nsURI = mc.getEffectiveNamespaceURI();
73-
setMerchantID(request, merchantID, nsURI);
74-
logger = new LoggerWrapper(null, true, true, mc);
75-
76-
con = new PoolingHttpClientConnection(mc, builder, logger);
73+
if(mc.getUseHttpClientWithConnectionPool()) {
74+
String merchantID = mc.getMerchantID();
75+
String nsURI = mc.getEffectiveNamespaceURI();
76+
setMerchantID(request, merchantID, nsURI);
77+
logger = new LoggerWrapper(null, true, true, mc);
78+
con = new PoolingHttpClientConnection(mc, builder, logger);
79+
} else {
80+
Assert.assertEquals("pooling httpclient is disabled", message);
81+
}
7782
} catch (ParserConfigurationException e) {
7883
e.printStackTrace();
7984
} catch (ConfigException e) {
@@ -88,7 +93,11 @@ public void start(){
8893
*/
8994
@Test
9095
public void testGetInstance(){
91-
Assert.assertNotNull(con);
96+
if(mc.getUseHttpClientWithConnectionPool()) {
97+
Assert.assertNotNull(con);
98+
} else {
99+
Assert.assertNull(con);
100+
}
92101
}
93102

94103
/**
@@ -97,26 +106,30 @@ public void testGetInstance(){
97106
@Test
98107
public void testPostRequest(){
99108
try {
100-
Element requestMessage
101-
= Utility.getElement(
102-
request, "requestMessage", mc.getEffectiveNamespaceURI());
103-
Document wrappedDoc = builder.newDocument();
109+
if(mc.getUseHttpClientWithConnectionPool()) {
110+
Element requestMessage
111+
= Utility.getElement(
112+
request, "requestMessage", mc.getEffectiveNamespaceURI());
113+
Document wrappedDoc = builder.newDocument();
104114

105-
wrappedDoc.appendChild(
106-
wrappedDoc.importNode(soapEnvelope.getFirstChild(), true));
115+
wrappedDoc.appendChild(
116+
wrappedDoc.importNode(soapEnvelope.getFirstChild(), true));
107117

108-
if (requestMessage != null) {
109-
wrappedDoc.getFirstChild().getFirstChild().appendChild(
110-
wrappedDoc.importNode(requestMessage, true));
118+
if (requestMessage != null) {
119+
wrappedDoc.getFirstChild().getFirstChild().appendChild(
120+
wrappedDoc.importNode(requestMessage, true));
121+
}
122+
SecurityUtil.loadMerchantP12File(mc,logger);
123+
signedDoc = SecurityUtil.createSignedDoc(wrappedDoc, mc.getKeyAlias(), mc.getKeyPassword(), logger);
124+
Document wrappedReply = con.post(signedDoc, requestSentTime);
125+
Assert.assertNotNull(wrappedReply);
126+
//test the http response code
127+
Assert.assertEquals(200, con.getHttpResponseCode());
128+
//test the http request sent or not
129+
Assert.assertEquals(true, con.isRequestSent());
130+
} else {
131+
Assert.assertEquals("pooling httpclient is disabled", message);
111132
}
112-
SecurityUtil.loadMerchantP12File(mc,logger);
113-
signedDoc = SecurityUtil.createSignedDoc(wrappedDoc, mc.getKeyAlias(), mc.getKeyPassword(), logger);
114-
Document wrappedReply = con.post(signedDoc, requestSentTime);
115-
Assert.assertNotNull(wrappedReply);
116-
//test the http response code
117-
Assert.assertEquals(200, con.getHttpResponseCode());
118-
//test the http request sent or not
119-
Assert.assertEquals(true, con.isRequestSent());
120133

121134
} catch (ClientException e) {
122135
e.printStackTrace();

java/src/test/resources/test_cybs.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ targetAPIVersion=1.139
1111
# the serverURL config is commented out.
1212
sendToProduction=false
1313
sendToAkamai=false
14-
serverURL=http://ratelimiter.ic3.com:9198
14+
#serverURL=http://ratelimiter.ic3.com:9198
1515

1616

1717
#To enable HttpClientConnection
@@ -20,6 +20,7 @@ useHttpClient=false
2020
useHttpClientWithConnectionPool=false
2121
# Following configure parameters will only work with useHttpClientWithConnectionPool=true
2222
# Optional parameters, default values configured in application
23+
enabledShutdownHook=true
2324
maxConnections=200
2425
defaultMaxConnectionsPerRoute=200
2526
maxConnectionsPerRoute=200

samples/nvp/cybs.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ useHttpClient=false
2121
useHttpClientWithConnectionPool=false
2222
# Following configure parameters will only work with useHttpClientWithConnectionPool=true
2323
# Optional parameters, default values configured in application
24+
enabledShutdownHook=true
2425
maxConnections=200
2526
defaultMaxConnectionsPerRoute=200
2627
maxConnectionsPerRoute=200

samples/xml/cybs.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ useHttpClient=false
2121
useHttpClientWithConnectionPool=false
2222
# Following configure parameters will only work with useHttpClientWithConnectionPool=true
2323
# Optional parameters, default values configured in application
24+
enabledShutdownHook=true
2425
maxConnections=200
2526
defaultMaxConnectionsPerRoute=200
2627
maxConnectionsPerRoute=200

zip/README

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ Refer to our Developer's Guide for details <http://apps.cybersource.com/library/
7575

7676
l. If "useHttpClientWithConnectionPool" parameter is set to true (default is false), then poolingHttpClientConnection will be enabled.
7777
- In case of poolingHttpConnection, we are initializing connection manager and httpclient once, If any change in value in between the application is running, it will not reflect. need to restart it.
78+
79+
m. If "enabledShutdownHook" is set to true (default is true), enables JVM runtime shutdown hook and execute our shutdown api. This is applicable only when useHttpClientWithConnectionPool is true.
7880
- Refer to the "PoolingHttpClientShutdown" section below.
7981

80-
m. Below properties are specific to poolinghttpclient connection, If it is not added in properties file, it will throw config exception.
82+
n. Below properties are specific to poolinghttpclient connection, If it is not added in properties file, it will throw config exception.
8183
Note : Below default values used in properties files are based on our testing application factors such as TPS, CPU, JVM, OS etc
8284
Before using these values in actual real time application, please consider all real time factors. Refer this link for more detailed explanation.
8385
- `maxConnections` set the maximum number of total open connections. default value is 200
@@ -89,10 +91,10 @@ Refer to our Developer's Guide for details <http://apps.cybersource.com/library/
8991
- `evictThreadSleepTimeMs` amount of time in milliseconds between sweeps by the idle connection evictor thread. default value is 3000
9092
- `maxKeepAliveTimeMs` maximum amount of time in milliseconds that a connaection can be idle before it is evicted from the pool. default value is 30000
9193

92-
n. If "merchantConfigCacheEnabled" is set to true (default value is false) it will cache the merchantConfig object based on keyAlias/merchantID
94+
o. If "merchantConfigCacheEnabled" is set to true (default value is false) it will cache the merchantConfig object based on keyAlias/merchantID
9395
- If cache enabled is true, for single merchant id, if you change any properties after first initialization, it will not reflect.
9496

95-
o. Please refer to the accompanying documentation for the other optional properties that you may wish to specify.
97+
p. Please refer to the accompanying documentation for the other optional properties that you may wish to specify.
9698

9799
##Testing the Client
98100
1.) Unzip the downloaded zip file into a directory of your choice. It will create a directory called
@@ -148,7 +150,7 @@ try {
148150

149151
##PoolingHttpClientShutdown
150152
In case of PoolingHttpClient Connection, we need to close the connection manager, http client and idle connection cleaner thread when application got shutdown abruptly or gracefully.
151-
JVM runtime addshutdown hook method will be initialized.
153+
If "enabledShutdownHook" is true, then JVM runtime addShutdownHook method will be initialized.
152154
Shutdown Hooks are a special construct that allows developers to plug in a piece of code to be executed when the JVM is shutting down. This comes in handy in cases where we need to do special clean up operations in case the VM is shutting down.
153155
private void addShutdownHook() {
154156
Runtime.getRuntime().addShutdownHook(this.createShutdownHookThread());

0 commit comments

Comments
 (0)