Skip to content

Commit a558cd3

Browse files
authored
Merge pull request #59 from CyberSource/future
Future
2 parents e82d340 + 32cefb3 commit a558cd3

34 files changed

+618
-551
lines changed

README.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#CyberSource Simple Order API for Java
22

3-
[![Build Status](https://travis-ci.org/CyberSource/cybersource-sdk-java.png?branch=master)]
3+
[![Build Status](https://travis-ci.org/CyberSource/cybersource-sdk-java.png?branch=future)]
44
(https://travis-ci.org/CyberSource/cybersource-sdk-java)
55

66
##Package Managers
@@ -11,7 +11,7 @@ To install the cybersource-sdk-java from central repository,add dependency to yo
1111
<dependency>
1212
<groupId>com.cybersource</groupId>
1313
<artifactId>cybersource-sdk-java</artifactId>
14-
<version>6.2.3</version>
14+
<version>6.2.4</version>
1515
</dependency>
1616
````
1717
Run mvn install, to install dependency
@@ -20,7 +20,7 @@ To install the cybersource-sdk-java from central repository,add dependency to yo
2020
Add the dependency to your build.gradle
2121
````
2222
dependencies {
23-
compile 'com.cybersource:cybersource-sdk-java:6.2.3'
23+
compile 'com.cybersource:cybersource-sdk-java:6.2.4'
2424
}
2525
````
2626
##Requirements
@@ -85,8 +85,12 @@ You do not need to download and build the source to use the SDK but if you want
8585
By default, it is set to true.
8686
8787
h. "serverURL" config parameter will take precedence over sendToProduction and sendToAkamai config parameters. By default the "serverURL" configuration is commented out.
88+
89+
i. "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.
90+
Set integer values for config parameter numberOfRetries & retryInterval. Retry Interval is time delay for next retry in seconds. number of retry parameter should be set between
91+
1 to 5 any other value will throw an Error Message. Refer to the "Retry Pattern" section below.
8892
89-
i. Please refer to the accompanying documentation for the other optional properties that you may wish to specify.
93+
j. Please refer to the accompanying documentation for the other optional properties that you may wish to specify.
9094

9195

9296
4. Build this project using Maven.
@@ -175,6 +179,15 @@ We have two ways to test, One is using maven tool and other is to download the z
175179
Cryptography Algorithms
176180
CyberSource utilizes the following algorithms for this implementation. While others may work, the following are validated and recommended. SSL is used for transport security even with encrypted messages. CyberSource asymmetric keys are RSA 2048 keys and therefore your cryptography API should support 2048 bit RSA keys and signatures create with them. The messages are encrypted with a temporary derived key which is used per message. This derived key is AES 256 bit and utilizes CBC blocking mode for encryption. The derived key is encrypted with the recipient ( CyberSource ) public key. The key exchange algorithm used is RSA-OAEP.
177181

182+
##RETRY PATTERN
183+
184+
Retry Pattern Allows to retry sending a failed request and it will only work with useHttpClient=true, allowRetry flag enables the retry mechanism.
185+
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
186+
in the config parameter 'numberOfRetries'.
187+
188+
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.
189+
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.
190+
178191
##Third Party jars
179192
1.) org.apache.ws.security.wss4j:1.6.19
180193
The Apache WSS4J project provides a Java implementation of the primary security standards for Web Services, namely the OASIS Web Services Security (WS-Security) specifications
@@ -197,14 +210,11 @@ We have two ways to test, One is using maven tool and other is to download the z
197210
6.) commons-logging:commons-logging:jar:1.1.1
198211
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
199212
systems.
200-
201-
7.) org.slf4j:slf4j-api:1.7.21 and org.slf4j:slf4j-jcl:1.7.21 .
202-
slf4j-api is getting used as a dependency for wss4j. Modified to latest version.
203213

204-
8.) junit:junit:4.12
214+
7.) junit:junit:4.12
205215
JUnit is a unit testing framework for Java.
206216

207-
9.) org.mockito:mockito-all:1.10.19
217+
8.) org.mockito:mockito-all:1.10.19
208218
Mock objects library for java
209219

210220
##Documentation

java/pom.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -201,16 +201,6 @@
201201
<artifactId>wss4j</artifactId>
202202
<version>1.6.19</version>
203203
</dependency>
204-
<dependency>
205-
<groupId>org.slf4j</groupId>
206-
<artifactId>slf4j-api</artifactId>
207-
<version>1.7.21</version>
208-
</dependency>
209-
<dependency>
210-
<groupId>org.slf4j</groupId>
211-
<artifactId>slf4j-jcl</artifactId>
212-
<version>1.7.21</version>
213-
</dependency>
214204
<dependency>
215205
<groupId>org.apache.commons</groupId>
216206
<artifactId>commons-lang3</artifactId>

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

Lines changed: 0 additions & 30 deletions
This file was deleted.

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

Lines changed: 0 additions & 62 deletions
This file was deleted.

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

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,10 @@ public static Map runTransaction(
118118

119119
con = Connection.getInstance(mc, builder, logger);
120120
Document wrappedReply = con.post(signedDoc);
121-
122-
return (soapUnwrap(wrappedReply, mc, logger));
121+
Map<String, String> replyMap = soapUnwrap(wrappedReply, mc, logger);
122+
logger.log(Logger.LT_INFO, "Client, End of runTransaction Call ",false);
123+
124+
return replyMap;
123125
} catch (IOException e) {
124126
throw new ClientException(
125127
e, con != null && con.isRequestSent(), logger);
@@ -178,51 +180,50 @@ private static Document soapWrapAndSign(
178180
boolean logSignedData = mc.getLogSignedData();
179181
if (!logSignedData) {
180182
logger.log(
181-
Logger.LT_REQUEST,
182-
mapToString(request, true, PCI.REQUEST));
183+
Logger.LT_REQUEST,
184+
"UUID > "+(mc.getUniqueKey()).toString() + "\n" +
185+
"Input request is" + "\n" +
186+
"======================================= \n"
187+
+ mapToString(request, true, PCI.REQUEST));
188+
}
189+
190+
Document wrappedDoc = soapWrap(request, mc, builder,logger);
191+
logger.log(Logger.LT_INFO, "Client, End of soapWrap ",true);
192+
193+
Document resultDocument = null;
194+
SecurityUtil.loadMerchantP12File(mc,logger);
195+
logger.log(Logger.LT_INFO, "Client, End of loadMerchantP12File ", true);
196+
197+
// sign Document object
198+
resultDocument = SecurityUtil.createSignedDoc(wrappedDoc, mc.getMerchantID(), mc.getKeyPassword(), logger);
199+
logger.log(Logger.LT_INFO, "Client, End of createSignedDoc ", true);
200+
201+
if ( mc.getUseSignAndEncrypted() ) {
202+
// Encrypt signed Document
203+
resultDocument = SecurityUtil.handleMessageCreation(resultDocument, mc.getMerchantID(), logger);
204+
logger.log(Logger.LT_INFO, "Client, End of handleMessageCreation ", true);
183205
}
206+
if (logSignedData) {
207+
logger.log(Logger.LT_REQUEST,Utility.nodeToString(resultDocument, PCI.REQUEST));
208+
//logger.log(Logger.LT_REQUEST,XMLUtils.PrettyDocumentToString(resultDocument));
209+
}
210+
211+
return resultDocument ;
212+
}
184213

185-
// wrap in SOAP envelope
214+
private static Document soapWrap(Map request, MerchantConfig mc, DocumentBuilder builder, LoggerWrapper logger) throws SAXException, IOException{
215+
// wrap in SOAP envelope
186216
Object[] arguments
187217
= {mc.getEffectiveNamespaceURI(),
188218
mapToString(request, false, PCI.REQUEST)};
189219
String xmlString = MessageFormat.format(SOAP_ENVELOPE1, arguments);
190-
// load XML string into a Document object
220+
// load XML string into a Document object
191221
StringReader sr = new StringReader( xmlString );
192222
Document wrappedDoc = builder.parse( new InputSource( sr ) );
193-
sr.close();
194-
195-
Document resultDocument = null;
196-
long timeNow = System.currentTimeMillis();
197-
logger.log(Logger.LT_INFO, "Client, Start of getInstance Call, Timer Start in ms " + timeNow + "For merchant " + mc.getMerchantID());
198-
199-
SignedAndEncryptedMessageHandler handler = SignedAndEncryptedMessageHandler.getInstance(mc,logger);
200-
201-
long endTime = System.currentTimeMillis();
202-
logger.log(Logger.LT_INFO, "Client, End of getInstance Call, time taken in ms " + (endTime-timeNow) + "For merchant " + mc.getMerchantID());
203-
204-
// 3/7/2016 change to support encrypted messages as well as signed - jeaton
205-
if ( !mc.getUseSignAndEncrypted() ) {
206-
// sign Document object
207-
logger.log(Logger.LT_INFO, "Signing request...");
208-
resultDocument = handler.createSignedDoc(wrappedDoc,mc.getMerchantID(),mc.getKeyPassword(),null);
209-
if (logSignedData) {
210-
logger.log(Logger.LT_REQUEST,
211-
Utility.nodeToString(resultDocument, PCI.REQUEST));
212-
}
213-
} else {
214-
logger.log(Logger.LT_INFO, "Signing and encrypting request...");
215-
resultDocument = handler.handleMessageCreation(wrappedDoc,mc.getMerchantID(),mc.getKeyPassword());
216-
if (logSignedData) {
217-
logger.log(Logger.LT_REQUEST,XMLUtils.PrettyDocumentToString(resultDocument));
218-
}
219-
}
220-
221-
//System.out.println(XMLUtils.PrettyDocumentToString(resultDocument));
222-
return resultDocument ;
223+
sr.close();
224+
return wrappedDoc;
223225
}
224-
225-
226+
226227
/**
227228
* Extracts the content of the SOAP body from the given Document object
228229
* inside a SOAP envelope.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public Document post(Document request)
107107

108108
}
109109

110+
110111
/**
111112
* Validate the Http response for any faults returned from the server.
112113
* @throws FaultException

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ private static String documentToString(Document doc)
189189
*/
190190
private class MyRetryHandler implements HttpMethodRetryHandler {
191191

192-
//
192+
long retryWaitInterval=mc.getRetryInterval();
193+
int maxRetries= mc.getNumberOfRetries();
194+
193195
// I copied this code from
194196
// http://jakarta.apache.org/commons/httpclient/exception-handling.html#HTTP%20transport%20safety
195197
// and changed the NoHttpResponseException case to
@@ -198,7 +200,7 @@ public boolean retryMethod(
198200
final HttpMethod method,
199201
final IOException exception,
200202
int executionCount) {
201-
if (executionCount > 5) {
203+
if (executionCount > maxRetries) {
202204
// Do not retry if over max retry count
203205
return false;
204206
}
@@ -210,6 +212,13 @@ public boolean retryMethod(
210212
if (!method.isRequestSent()) {
211213
// Retry if the request has not been sent fully or
212214
// if it's OK to retry methods that have been sent
215+
try {
216+
Thread.sleep(retryWaitInterval);
217+
logger.log( Logger.LT_INFO+" Retrying Request -- ",mc.getUniqueKey().toString()+ " Retry Count -- "+executionCount);
218+
} catch (InterruptedException e) {
219+
// TODO Auto-generated catch block
220+
e.printStackTrace();
221+
}
213222
return true;
214223
}
215224
// otherwise do not retry

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@
2222
public class Identity {
2323

2424
//Our p12 files do not contain an alias as a normal name, its the common name and serial number
25-
private String name = null;
25+
private String name;
2626

2727
// we need to create alias for our keystores, it looks like "serialNumber=4032987129910179089277,CN=jasoneatoncorp"
28-
private String keyAlias = null;
28+
private String keyAlias;
2929

3030
// for an unknown reason the serial number of the certificate is set incorrectly, we must parse it from DN
31-
private String serialNumber = null;
31+
private String serialNumber;
3232

33-
private X509Certificate x509Cert =null;
33+
private X509Certificate x509Cert;
3434

35-
private PrivateKey privateKey = null;
35+
private PrivateKey privateKey;
3636

37-
private MerchantConfig merchantConfig = null;
37+
private MerchantConfig merchantConfig;
3838

3939
private static final String SERVER_ALIAS = "CyberSource_SJC_US";
4040

0 commit comments

Comments
 (0)