Skip to content

Commit 7b90412

Browse files
authored
Merge pull request #56 from mahendya/future
Future
2 parents 616b651 + c679550 commit 7b90412

33 files changed

+566
-559
lines changed

README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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,11 @@ 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. Set allowRetry config parameter to "true/false" to enable retry mechanism. By default, allowRetry is set to true.
90+
Set integer values for config parameter numberOfRetries & retryInterval to configure the retry behavior. Refer to the "Retry Pattern" section below.
8891
89-
i. Please refer to the accompanying documentation for the other optional properties that you may wish to specify.
92+
j. Please refer to the accompanying documentation for the other optional properties that you may wish to specify.
9093

9194

9295
4. Build this project using Maven.
@@ -175,6 +178,13 @@ We have two ways to test, One is using maven tool and other is to download the z
175178
Cryptography Algorithms
176179
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.
177180

181+
##RETRY PATTERN
182+
183+
Retry Pattern Allows to retry sending a failed request. To Enable or disable retry mechanism set the allowRetry config parameter to "true or false".
184+
By default, allowRetry is set to true. The system will retry the failed request multiple times as configured in the config parameter 'numberOfRetries'.
185+
numberOfRetries (Number of retries) should be set between 1 to 3. By default numberOfRetries will be set to 1. User can set a delay in between the retry
186+
attempts using the config parameter 'retryInterval'. The default value for this parameter is 10 which means a delay of 10 seconds between the retry attempts.
187+
178188
##Third Party jars
179189
1.) org.apache.ws.security.wss4j:1.6.19
180190
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 +207,11 @@ We have two ways to test, One is using maven tool and other is to download the z
197207
6.) commons-logging:commons-logging:jar:1.1.1
198208
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
199209
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.
203210

204-
8.) junit:junit:4.12
211+
7.) junit:junit:4.12
205212
JUnit is a unit testing framework for Java.
206213

207-
9.) org.mockito:mockito-all:1.10.19
214+
8.) org.mockito:mockito-all:1.10.19
208215
Mock objects library for java
209216

210217
##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: 34 additions & 36 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);
@@ -181,48 +183,44 @@ private static Document soapWrapAndSign(
181183
Logger.LT_REQUEST,
182184
mapToString(request, true, PCI.REQUEST));
183185
}
186+
187+
Document wrappedDoc = soapWrap(request, mc, builder,logger);
188+
logger.log(Logger.LT_INFO, "Client, End of soapWrap ",true);
189+
190+
Document resultDocument = null;
191+
SecurityUtil.loadMerchantP12File(mc,logger);
192+
logger.log(Logger.LT_INFO, "Client, End of loadMerchantP12File ", true);
193+
194+
// sign Document object
195+
resultDocument = SecurityUtil.createSignedDoc(wrappedDoc, mc.getMerchantID(), mc.getKeyPassword(), logger);
196+
logger.log(Logger.LT_INFO, "Client, End of createSignedDoc ", true);
197+
198+
if ( mc.getUseSignAndEncrypted() ) {
199+
// Encrypt signed Document
200+
resultDocument = SecurityUtil.handleMessageCreation(resultDocument, mc.getMerchantID(), logger);
201+
logger.log(Logger.LT_INFO, "Client, End of handleMessageCreation ", true);
202+
}
203+
if (logSignedData) {
204+
logger.log(Logger.LT_REQUEST,Utility.nodeToString(resultDocument, PCI.REQUEST));
205+
//logger.log(Logger.LT_REQUEST,XMLUtils.PrettyDocumentToString(resultDocument));
206+
}
207+
208+
return resultDocument ;
209+
}
184210

185-
// wrap in SOAP envelope
211+
private static Document soapWrap(Map request, MerchantConfig mc, DocumentBuilder builder, LoggerWrapper logger) throws SAXException, IOException{
212+
// wrap in SOAP envelope
186213
Object[] arguments
187214
= {mc.getEffectiveNamespaceURI(),
188215
mapToString(request, false, PCI.REQUEST)};
189216
String xmlString = MessageFormat.format(SOAP_ENVELOPE1, arguments);
190-
// load XML string into a Document object
217+
// load XML string into a Document object
191218
StringReader sr = new StringReader( xmlString );
192219
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 ;
220+
sr.close();
221+
return wrappedDoc;
223222
}
224-
225-
223+
226224
/**
227225
* Extracts the content of the SOAP body from the given Document object
228226
* inside a SOAP envelope.

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

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,33 @@ abstract InputStream getResponseErrorStream()
9191
*/
9292
public Document post(Document request)
9393
throws ClientException, FaultException {
94-
try {
95-
postDocument(request);
96-
checkForFault();
97-
return (parseReceivedDocument());
98-
} catch (IOException e) {
99-
throw new ClientException(e, isRequestSent(), logger);
100-
} catch (TransformerConfigurationException e) {
101-
throw new ClientException(e, isRequestSent(), logger);
102-
} catch (TransformerException e) {
103-
throw new ClientException(e, isRequestSent(), logger);
104-
} catch (SAXException e) {
105-
throw new ClientException(e, isRequestSent(), logger);
106-
}
107-
108-
}
94+
for (int i=0; i<=mc.getNumberOfRetries(); i++) {
95+
try {
96+
postDocument(request);
97+
break;
98+
} catch (IOException e) {
99+
logger.log(Logger.LT_INFO, "Attempt to post document failed. Number of retry attempts made " + i);
100+
if(i==mc.getNumberOfRetries()) throw new ClientException(e, isRequestSent(), logger);
101+
try {
102+
Thread.sleep((long) mc.getRetryInterval());
103+
}catch (InterruptedException ex) {
104+
logger.log(Logger.LT_INFO, "Waiting for the next attempt to made after " +mc.getRetryInterval() );
105+
}
106+
} catch (TransformerConfigurationException e) {
107+
throw new ClientException(e, isRequestSent(), logger);
108+
} catch (TransformerException e) {
109+
throw new ClientException(e, isRequestSent(), logger);
110+
}
111+
112+
}
113+
checkForFault();
114+
try {
115+
return parseReceivedDocument();
116+
}catch (IOException e) {
117+
throw new ClientException(e, isRequestSent(), logger);
118+
}catch (SAXException e) {
119+
throw new ClientException(e, isRequestSent(), logger);
120+
}}
109121

110122
/**
111123
* Validate the Http response for any faults returned from the server.

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)