Skip to content

Commit ec956a1

Browse files
authored
Merge pull request #140 from Mayuri-Kumar93/future
Code changes for performance improvements and other minor fixes
2 parents 01ea0b0 + 338ceee commit ec956a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2629
-773
lines changed

README.md

Lines changed: 103 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,53 @@ You do not need to download and build the source to use the SDK but if you want
5959
- Set `sendToAkamai` config parameter with toggle value "true/false" to turn on/off routing requests through Akamai to Cybersource. By default, it is set to true.
6060
- `serverURL` config parameter will take precedence over `sendToProduction` and `sendToAkamai` config parameters. By default the `serverURL` configuration is commented out.
6161
- If `enableJdkcert` parameter is set to true, certificates will be read from the JKS file specified at keysDirectory location. The JKS file should be of the same name as specified in keyFilename.
62-
- To know how to convert p12 to JKS refer the JKS creation section of this document.
63-
- If 'enableCacert' property parameter is set to true, certificates will be read from the cacerts file specified at keysDirectory location.If keysDirectory path is not set,certificate will be loaded from Java Installation cacerts file. The cacerts file should be of the same name as specified in keyFilename.
62+
- To know how to convert p12 to JKS refer the JKS creation section of this document.
63+
- If 'enableCacert' property parameter is set to true, certificates will be read from the cacerts file specified at keysDirectory location.
64+
- If keysDirectory path is not set,certificate will be loaded from Java Installation cacerts file. The cacerts file should be of the same name as specified in keyFilename.
6465
- If `certificateCacheEnabled` parameter is set to false (default is true), the p12 certificate of a merchant will be reloaded from filesystem every time a transaction is made
65-
- `allowRetry` config parameter will only work for HttpClient. Set `allowRetry` config parameter to "true" to enable retry mechanism and set merchant specific values for the retry.
66-
- Set integer values for config parameter `numberOfRetries` *and* `retryInterval`. Retry Interval is time delay for next retry in seconds.
67-
- Number of retry parameter should be set between 1 to 5. Any other value will throw an Error Message.
66+
- If `useHttpClient` parameter is set to true (default is false), then simple HttpClientConnection will be enabled
67+
- If `useHttpClientWithConnectionPool` parameter is set to true (default is false), then poolingHttpClientConnection will be enabled. In case of poolingHttpConnection,
68+
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.
69+
- Below properties are specific to poolinghttpclient connection, If it is not added in properties file, it will throw config exception.
70+
71+
Note : Sample values used in properties files are based on our testing application factors such as TPS, CPU, JVM, OS etc.
72+
Before using these values in actual real time application, please consider all real time factors.
73+
- `maxConnections` Specifies the maximum number of concurrent, active HTTP connections allowed by the resource instance to be opened with the target service.
74+
There is no default value. For applications that create many long-lived connections, increase the value of this parameter.
75+
- `defaultMaxConnectionsPerRoute` the maximum number of connections per (any) route.
76+
- `maxConnectionsPerRoute` Specifies the maximum number of concurrent, active HTTP connections allowed by the resource instance to the same host or route.
77+
In SDK, all above config does same functionality and the same value can be given to these configs as we have only one route.
78+
79+
Note: This number cannot be greater than Maximum Total Connections and every connection created here also counts into Maximum Total Connections.
80+
- `connectionRequestTimeoutMs` Time taken in milliseconds to get connection request from the pool. If it times out, it will throw error as Timeout waiting for connection from pool
81+
- `connectionTimeoutMs` Specifies the number of milliseconds to wait while a connection is being established.
82+
- `socketTimeoutMs` Specifies the time waiting for data – after establishing the connection; maximum time of inactivity between two data packets.
83+
- `evictThreadSleepTimeMs` Specifies time duration in milliseconds between "sweeps" by the "idle connection" evictor thread.
84+
This thread will check if any idle/expired/stale connections are available in pool and evict it.
85+
- `maxKeepAliveTimeMs` Specifies the time duration in milliseconds that a connection can be idle before it is evicted from the pool.
86+
- `staleConnectionCheckEnabled` It determines whether the stale connection check is to be used. Disabling the stale connection check can result in slight performance improvement
87+
at the risk of getting an I/O error, when executing a request over a connection that has been closed at the server side. By default it is set to true, which means it is enabled.
88+
- `validateAfterInactivityMs` By default it is set to 0. This value can be set if in case you decide to disable staleConnectionCheckEnabled to get slight better performance.
89+
We recommended a value of 2000ms.
90+
- `enabledShutdownHook` We should close the connection manager, http client and idle connection cleaner thread when application get shutdown both abruptly and gracefully.
91+
If `enabledShutdownHook` is true, then JVM runtime addShutdownHook method will be initialized. Shutdown Hooks are a special construct that allows developers to plug in a piece of
92+
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.
93+
` private void addShutdownHook() {
94+
Runtime.getRuntime().addShutdownHook(this.createShutdownHookThread());
95+
}`
96+
createShutdownHookThread method will call static shutdown api to close connectionManager, httpClient and IdleCleanerThread. By default this is enabled when useHttpClientWithConnectionPool is true.
97+
- `allowRetry` config parameter will only work for HttpClient and PoolingHttpClient.
98+
Set `allowRetry` config parameter to "true" to enable retry mechanism and set merchant specific values for the retry.
99+
- Set integer values and long values for config parameter `numberOfRetries` *and* `retryInterval` respectively. Retry Interval is time delay for next retry in milliSeconds.
100+
- Number of retry parameter should be set between 1 to 5. By default the value for numberOfRetries will be 3. Any other value will throw an Error Message.
68101
- Refer to the [Retry Pattern](README.md#retry-pattern) section below.
69102
- Please refer to the accompanying documentation for the other optional properties that you may wish to specify.
70103
- Set customHttpClassEnabled to true to make use of Custom Http Library.
71104
- Enter the custom class name in customHttpClass field. Provide the full package name along with the class name.
72105
example customHttpClass= <packagename.customHttpClass>
73106
- The custom HTTP Class must have a three argument constructor which accepts MerchantConfig, DocumentBuilder and LoggerWrapper as argument. Then it should call the constructor of the parent class.
107+
- `merchantConfigCacheEnabled` If this property is set to true (default value is false) it will cache the merchantConfig object based on keyAlias/merchantID
108+
-If cache enabled is true, for single merchant id, if you change any properties after first initialization, it will not reflect.
74109
- Build this project using Maven.
75110
- `mvn clean` - Cleans the Project
76111
- `mvn install` - Builds the project and creates a jar file of client SDK. Includes running all unit tests and integration tests
@@ -138,7 +173,15 @@ keytool -list -v -keystore <Your_keystore_name>`
138173
- The first entry should contain a chain of two certificates - `CyberSourceCertAuth` and <Merchant_ID> with alias name <Merchant_ID>
139174
- Second entry should be for `CyberSource_SJC_US` certificate with alias name as CyberSource_SJC_US
140175

141-
176+
## PoolingHttpClient
177+
PoolingHttpClient is built using the apache's PoolingHttpClientConnectionManager class. It comes with retry functionality which is very much needed in case if
178+
SDK receives an I/O error/exception, when executing a request over a connection that has been closed at the server side. However there might be some cases when
179+
transaction has reached server and similar or some other exception has occurred. We are considering `merchantTransactionIdentifier` as idempotent key, specially
180+
in case of auth service(`ccAuthService`). Hence if you want to use PoolingHttpClient, for auth service(`ccAuthService`) merchantTransactionIdentifier field is
181+
mandatory in the payload for both nvp and xml. The value of the merchant transaction ID must be unique for 60 days.
182+
183+
To get more information related to connection pooling please refer wiki.
184+
142185
## Message Level Encryption
143186
CyberSource supports Message Level Encryption (MLE) for Simple Order API. Message level encryption conforms to the SOAP Security 1.0 specification published by the OASIS standards group.
144187

@@ -156,10 +199,10 @@ CyberSource supports Message Level Encryption (MLE) for Simple Order API. Messag
156199

157200
## Retry Pattern
158201

159-
Retry Pattern allows to retry sending a failed request and it will only work with `useHttpClient=true`. `allowRetry` flag enables the retry mechanism.
202+
Retry Pattern allows to retry sending a failed request and it will only work with `useHttpClient=true` or `useHttpClientWithConnectionPool. `allowRetry` flag enables the retry mechanism.
160203
- Set the value of `allowRetry` parameter to "TRUE/FALSE". Then the system will retry the failed request as many times as configured by the merchant in the config parameter 'numberOfRetries'.
161-
- numberOfRetries parameter value should be set between 0 to 5. By default the value for numberOfRetries will be 5. User can set a delay in between the retry attempts.
162-
- Config parameter for this property is 'retryInterval' in `cybs.property` file. The default value for 'retryInterval' parameter is 5 which means a delay of 5 seconds.
204+
- numberOfRetries parameter value should be set between 0 to 5. By default the value for numberOfRetries will be 3. User can set a delay in between the retry attempts.
205+
- Config parameter for this property is 'retryInterval' in `cybs.property` file. The default value for 'retryInterval' parameter is 1000 which means a delay of 1000 milliSeconds.
163206

164207
## Third Party jars
165208
1. org.apache.ws.security.wss4j:1.6.19
@@ -180,12 +223,27 @@ Retry Pattern allows to retry sending a failed request and it will only work wit
180223
JUnit is a unit testing framework for Java.
181224
9. org.mockito:mockito-all:1.10.19
182225
Mock objects library for java
226+
10. org.apache.httpcomponents:httpclient:4.5.11
227+
Provides reusable components for client-side authentication, HTTP state management, and HTTP connection management. It is used for poolinghttpclientconnectionmanager feature.
228+
183229

184230
## Changes
185231

186-
Version Cybersource-sdk-java 6.2.9 (APR,2020)
232+
Version Cybersource-sdk-java 6.2.10 (MAY,2020)
187233
_______________________________
188234

235+
1)Added PoolingHttpClientConnection implementation
236+
237+
2)MerchantConfig Object Caching based on KeyAlias/Merchant Id
238+
239+
3)Changed retry interval from second to millisecond
240+
241+
4)Added one more request header "v-c-client-computetime" to calculate time taken to send request to Cybersource
242+
243+
5)Added troubleshooting section in README.
244+
245+
Version Cybersource-sdk-java 6.2.9 (APR,2020)
246+
_______________________________
189247
1)Corrected request header name
190248

191249
Version Cybersource-sdk-java 6.2.8 (FEB,2020)
@@ -250,8 +308,41 @@ Version Cybersource-sdk-java 6.1.0 (Feb 24,2016)
250308
_______________________________
251309
1) SHA256 changes which are required to signed the request with SHA256.
252310

311+
## Troubleshooting
312+
- If you get an exception **`java.lang.SecurityException: JCE cannot authenticate the provider BC`**. This could be because of
313+
many reasons. bcprov*.jar is a signed jar if java fails to validate the signature, it throws this exception. Make sure
314+
you run below java command to verify this signature.
315+
316+
`jarsigner -verify bcprov-jdk15on-1.61.jar`
317+
318+
when above command fails it says "jar is unsigned. (signatures missing or not parsable)", this could be because of many
319+
reasons. e.g
320+
321+
1) When we unpack it and include in our own jar file. Including bcprov*.jar separately in the CLASSPATH should solve this issue.
322+
2) May be changes in Oracle jar signer. If using Java SDK 1.6 or 1.7 with cybersource-sdk-java:6.2.7 and higher
323+
(ships with org.bouncycastle:bcprov-jdk15on:1.61). Upgrading version to bcprov-jdk15to18-1.63.jar should solve this issue.
324+
3) If you are using some old version of JBOSS and have copied bcprov*.jar under $JBOSS_HOME/server/default/lib/.
325+
copying bcprov*.jar in $JBOSS_HOME/server/default/lib/ instead of $JBOSS_HOME/server/servername/lib/ should solve this issue.
326+
327+
- If you get an exception **`exception decrypting data - java.security.InvalidKeyException: Illegal key size`**.
328+
It is recommended to download Unlimited Strength Jurisdiction Policy files from Oracle (US_export_policy.jar and local_policy.jar)
329+
for appropriate JAVA version. I meant if merchant are using java 6 then download these policy file only for java6.
330+
You need to copy security jars (US_export_policy.jar, local_policy.jar) in the $JAVA_HOME/jre/lib/security directory not in $JAVA_HOME/jre/lib/ext/).
331+
332+
- Put below block of code to handle the ClientException to print the complete stacktrace.
333+
334+
try{
335+
Client.runTransaction(requestMap, merchantProperties);
336+
}catch (ClientException e){
337+
e.getInnerException().printStackTrace();
338+
// or
339+
String stackTrace = Utility.getStackTrace(e.getInnerException() != null? e.getInnerException(): e);
340+
}
341+
342+
343+
253344
## Documentation
254-
- For more information about CyberSource services, see <http://www.cybersource.com/developers/documentation>.
255-
- For all other support needs, see <http://www.cybersource.com/support>.
345+
- For more information about CyberSource services, see <https://www.cybersource.com/en-us/support/technical-documentation.html>.
346+
- For all other support needs, see <https://support.cybersource.com/>.
256347

257348

java/pom.xml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,21 @@
8787
</executions>
8888
</plugin>
8989
<plugin>
90+
<groupId>org.apache.maven.plugins</groupId>
9091
<artifactId>maven-javadoc-plugin</artifactId>
91-
<version>2.10.1</version>
92+
<version>3.2.0</version>
9293
<executions>
9394
<execution>
9495
<id>attach-javadocs</id>
9596
<phase>package</phase>
9697
<goals><goal>jar</goal></goals>
9798
</execution>
9899
</executions>
100+
<configuration>
101+
<additionalOptions>
102+
<additionalOption>-Xdoclint:none</additionalOption>
103+
</additionalOptions>
104+
</configuration>
99105
</plugin>
100106
<plugin>
101107
<artifactId>maven-jar-plugin</artifactId>
@@ -139,6 +145,20 @@
139145
<target>1.6</target>
140146
</configuration>
141147
</plugin>
148+
<plugin>
149+
<groupId>org.apache.maven.plugins</groupId>
150+
<artifactId>maven-surefire-plugin</artifactId>
151+
<version>2.4.3</version>
152+
<configuration>
153+
<argLine>-Dfile.encoding=ISO-8859-1</argLine>
154+
<includes>
155+
<include>**/*Test.java</include>
156+
</includes>
157+
<excludes>
158+
<exclude>**/*SystemTest.java</exclude>
159+
</excludes>
160+
</configuration>
161+
</plugin>
142162
<plugin>
143163
<groupId>org.codehaus.mojo</groupId>
144164
<artifactId>exec-maven-plugin</artifactId>
@@ -190,6 +210,17 @@
190210
<artifactId>xmlsec</artifactId>
191211
<version>1.5.6</version>
192212
</dependency>
213+
<dependency>
214+
<groupId>org.apache.httpcomponents</groupId>
215+
<artifactId>httpclient</artifactId>
216+
<version>4.5.11</version>
217+
<exclusions>
218+
<exclusion>
219+
<groupId>commons-logging</groupId>
220+
<artifactId>commons-logging</artifactId>
221+
</exclusion>
222+
</exclusions>
223+
</dependency>
193224
<dependency>
194225
<groupId>commons-httpclient</groupId>
195226
<artifactId>commons-httpclient</artifactId>
@@ -216,7 +247,7 @@
216247
<artifactId>opensaml</artifactId>
217248
</exclusion>
218249
</exclusions>
219-
</dependency>
250+
</dependency>
220251
<dependency>
221252
<groupId>org.apache.commons</groupId>
222253
<artifactId>commons-lang3</artifactId>

0 commit comments

Comments
 (0)