Skip to content

Commit 7c2045e

Browse files
committed
added sysout for debugging
1 parent 266a4ac commit 7c2045e

9 files changed

Lines changed: 74 additions & 105 deletions

File tree

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

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,19 @@
1919
package com.cybersource.ws.client;
2020

2121

22-
import org.apache.ws.security.util.XMLUtils;
2322
import org.w3c.dom.Document;
2423
import org.w3c.dom.Node;
2524
import org.w3c.dom.Text;
2625
import org.xml.sax.InputSource;
2726
import org.xml.sax.SAXException;
2827

29-
import javax.security.cert.X509Certificate;
3028
import javax.xml.parsers.DocumentBuilder;
3129
import javax.xml.parsers.ParserConfigurationException;
32-
33-
import java.io.File;
34-
import java.io.FileInputStream;
3530
import java.io.IOException;
3631
import java.io.StringReader;
3732
import java.lang.reflect.InvocationTargetException;
38-
import java.security.KeyStore;
39-
import java.security.cert.PKIXParameters;
40-
import java.security.cert.TrustAnchor;
4133
import java.text.MessageFormat;
4234
import java.util.HashMap;
43-
import java.util.Iterator;
4435
import java.util.Map;
4536
import java.util.Properties;
4637

@@ -49,8 +40,6 @@
4940
* form of a Map object.
5041
*/
5142
public class Client {
52-
private static final String HEADER_FORMAT = "{0}={1}";
53-
5443
private static final String SOAP_ENVELOPE1 = "<soap:Envelope xmlns:soap=\"" +
5544
"http://schemas.xmlsoap.org/soap/envelope/\">\n<soap:Body id=\"body1\">\n" +
5645
"<nvpRequest xmlns=\"{0}\">\n{1}</nvpRequest>" +
@@ -99,8 +88,6 @@ public static Map runTransaction(
9988
MerchantConfig mc;
10089
LoggerWrapper logger = null;
10190
Connection con = null;
102-
103-
10491
try {
10592
setVersionInformation(request);
10693

@@ -229,16 +216,16 @@ private static Document soapWrapAndSign(
229216
+ mapToString(request, true, PCI.REQUEST));
230217
}
231218

232-
Document wrappedDoc = soapWrap(request, mc, builder,logger);
219+
Document wrappedDoc = soapWrap(request, mc, builder);
233220
logger.log(Logger.LT_INFO, "Client, End of soapWrap ",true);
234221

235-
Document resultDocument = null;
222+
Document resultDocument;
236223

237224
SecurityUtil.loadMerchantP12File(mc,logger);
238225
logger.log(Logger.LT_INFO, "Client, End of loading Merchant Certificates ", true);
239226

240227
// sign Document object
241-
resultDocument = SecurityUtil.createSignedDoc(wrappedDoc, mc.getMerchantID(), mc.getKeyPassword(), logger);
228+
resultDocument = SecurityUtil.createSignedDoc(wrappedDoc, mc.getKeyAlias(), mc.getKeyPassword(), logger);
242229
logger.log(Logger.LT_INFO, "Client, End of createSignedDoc ", true);
243230

244231
if ( mc.getUseSignAndEncrypted() ) {
@@ -254,7 +241,7 @@ private static Document soapWrapAndSign(
254241
return resultDocument ;
255242
}
256243

257-
private static Document soapWrap(Map request, MerchantConfig mc, DocumentBuilder builder, LoggerWrapper logger) throws SAXException, IOException{
244+
private static Document soapWrap(Map request, MerchantConfig mc, DocumentBuilder builder) throws SAXException, IOException{
258245
// wrap in SOAP envelope
259246
Object[] arguments
260247
= {mc.getEffectiveNamespaceURI(),

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.net.HttpURLConnection;
3636
import java.net.MalformedURLException;
3737
import java.net.ProtocolException;
38+
import java.util.concurrent.TimeUnit;
3839

3940

4041
/**
@@ -123,7 +124,7 @@ public Document post(Document request)
123124
private void checkForFault()
124125
throws FaultException, ClientException {
125126
try {
126-
logger.log(Logger.LT_INFO, "Reading response...");
127+
logger.log(Logger.LT_INFO, "waiting for response...");
127128
int responseCode = getHttpResponseCode();
128129
logResponseHeaders();
129130
// if successful, there's nothing left to do here.
@@ -192,7 +193,10 @@ private void checkForFault()
192193
private Document parseReceivedDocument()
193194
throws IOException, SAXException {
194195
logger.log(Logger.LT_INFO, "Parsing response...");
195-
return builder.parse(getResponseStream());
196+
long startTime = System.nanoTime();
197+
Document document = builder.parse(getResponseStream());
198+
System.out.println("Connection.parseReceivedDocument time taken to parse the response is " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime) + " ms");
199+
return document;
196200
}
197201

198202
/**

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,16 @@
2626
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
2727
import org.apache.commons.httpclient.params.HttpMethodParams;
2828
import org.w3c.dom.Document;
29+
2930
import javax.xml.parsers.DocumentBuilder;
3031
import javax.xml.transform.TransformerConfigurationException;
3132
import javax.xml.transform.TransformerException;
3233
import java.io.ByteArrayOutputStream;
3334
import java.io.IOException;
3435
import java.io.InputStream;
35-
import java.net.MalformedURLException;
36-
import java.net.ProtocolException;
37-
import java.util.ArrayList;
38-
import java.util.List;
39-
import java.util.List;
40-
import org.apache.commons.httpclient.Header;
4136
import java.util.ArrayList;
4237
import java.util.Arrays;
38+
import java.util.List;
4339
/**
4440
* Class helps in posting the Request document for the Transaction using HttpClient.
4541
* Converts the document to String format and also helps in setting up the Proxy connections.
@@ -59,9 +55,7 @@ class HttpClientConnection extends Connection {
5955
* @see com.cybersource.ws.client.Connection#postDocument(org.w3c.dom.Document)
6056
*/
6157
void postDocument(Document request)
62-
throws IOException, TransformerConfigurationException,
63-
TransformerException, MalformedURLException,
64-
ProtocolException {
58+
throws IOException, TransformerException {
6559

6660
/*
6761
* SimpleHttpConnectionManager(boolean alwaysClose) :
@@ -108,8 +102,7 @@ public void release() {
108102
/* (non-Javadoc)
109103
* @see com.cybersource.ws.client.Connection#getHttpResponseCode()
110104
*/
111-
int getHttpResponseCode()
112-
throws IOException {
105+
int getHttpResponseCode(){
113106
return postMethod != null ? postMethod.getStatusCode() : -1;
114107
}
115108

@@ -225,7 +218,6 @@ public boolean retryMethod(
225218
Thread.sleep(retryWaitInterval);
226219
logger.log( Logger.LT_INFO+" Retrying Request -- ",mc.getUniqueKey().toString()+ " Retry Count -- "+executionCount);
227220
} catch (InterruptedException e) {
228-
// TODO Auto-generated catch block
229221
e.printStackTrace();
230222
}
231223
return true;

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class Identity {
4343

4444
private char[] pswd;
4545

46-
private Logger logger = null;
46+
private Logger logger;
4747

4848
/**
4949
* Creates an Identity instance.this type of the instance can
@@ -56,18 +56,17 @@ public class Identity {
5656
public Identity(MerchantConfig merchantConfig,X509Certificate x509Certificate,Logger logger) throws SignException {
5757
this.merchantConfig = merchantConfig;
5858
this.x509Cert=x509Certificate;
59-
if(this.logger == null){
60-
this.logger=logger;
61-
}
59+
this.logger=logger;
60+
6261
if(merchantConfig.isJdkCertEnabled() || merchantConfig.isCacertEnabled()){
6362
setupJdkServerCerts();
6463
}
6564
else{
6665
setUpServer();
6766
}
6867
}
68+
6969
private void setupJdkServerCerts() throws SignException {
70-
7170
if (x509Cert != null) {
7271
String subjectDN = x509Cert.getSubjectDN().getName();
7372
if (subjectDN != null) {
@@ -82,7 +81,6 @@ else if (subjectDNrray.length == 2 && subjectDNrray[1].contains(SERVER_ALIAS)) {
8281
}else{
8382
throw new SignException("Exception while obtaining private key from KeyStore with alias, '" + merchantConfig.getKeyAlias() + "'");
8483
}
85-
8684
} else {
8785
throw new SignException("Exception while obtaining private key from KeyStore with alias, '" + merchantConfig.getKeyAlias() + "'");
8886
}
@@ -103,9 +101,8 @@ public Identity(MerchantConfig merchantConfig,X509Certificate x509Certificate, P
103101
this.merchantConfig = merchantConfig;
104102
this.x509Cert = x509Certificate;
105103
this.privateKey = privateKey;
106-
if(this.logger == null){
107-
this.logger=logger;
108-
}
104+
this.logger=logger;
105+
109106
try {
110107
this.lastModifiedDate=merchantConfig.getKeyFile().lastModified();
111108
} catch (ConfigException e) {
@@ -136,14 +133,14 @@ private void setUpMerchant() throws SignException {
136133
if (serialNumber == null && x509Cert != null) {
137134
String subjectDN = x509Cert.getSubjectDN().getName();
138135
if (subjectDN != null) {
139-
String subjectDNrray[] = subjectDN.split("SERIALNUMBER=");
136+
String[] subjectDNrray = subjectDN.split("SERIALNUMBER=");
140137
if (subjectDNrray.length != 2) {
141138
throw new SignException("Exception while obtaining private key from KeyStore with alias, '" + merchantConfig.getKeyAlias() + "'");
142139
}
143140
name = merchantConfig.getMerchantID();
144141
pswd = merchantConfig.getKeyPassword().toCharArray();
145142
serialNumber = subjectDNrray[1];
146-
keyAlias = "serialNumber=" + serialNumber + ",CN=" + name;
143+
keyAlias = merchantConfig.getKeyAlias();
147144
} else {
148145
throw new SignException("Exception while obtaining private key from KeyStore with alias, '" + merchantConfig.getKeyAlias() + "'");
149146
}
@@ -155,7 +152,7 @@ private void setUpServer() throws SignException {
155152
if (serialNumber == null && x509Cert != null) {
156153
String subjectDN = x509Cert.getSubjectDN().getName();
157154
if (subjectDN != null) {
158-
String subjectDNrray[] = subjectDN.split("SERIALNUMBER=");
155+
String[] subjectDNrray = subjectDN.split("SERIALNUMBER=");
159156
if (subjectDNrray.length == 1 && subjectDNrray[0].contains("CyberSourceCertAuth")){
160157
name = keyAlias = "CyberSourceCertAuth";
161158
}

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

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,8 @@
2828
import java.io.InputStream;
2929
import java.io.OutputStream;
3030
import java.net.HttpURLConnection;
31-
import java.net.MalformedURLException;
32-
import java.net.ProtocolException;
3331
import java.net.URL;
34-
import java.util.HashMap;
35-
import java.util.List;
36-
import java.util.Map;
37-
import java.util.Map.Entry;
32+
import java.util.concurrent.TimeUnit;
3833

3934

4035
/**
@@ -54,26 +49,26 @@ class JDKHttpURLConnection extends Connection {
5449
}
5550

5651
void postDocument(Document request)
57-
throws IOException, TransformerConfigurationException,
58-
TransformerException, MalformedURLException,
59-
ProtocolException {
52+
throws IOException,
53+
TransformerException{
54+
long startTime = System.nanoTime();
6055
String serverURL = mc.getEffectiveServerURL();
6156
URL url = new URL(serverURL);
6257

6358
con = ConnectionHelper.openConnection(url, mc);
6459
con.setRequestProperty(Utility.ORIGIN_TIMESTAMP, String.valueOf(System.currentTimeMillis()));
65-
logRequestHeaders();
6660
con.setRequestMethod("POST");
6761
con.setDoOutput(true);
6862
ConnectionHelper.setTimeout(con, mc.getTimeout());
69-
63+
logRequestHeaders();
7064
OutputStream out = con.getOutputStream();
71-
byte[] requestBytes = documentToByteArray(request);
65+
byte[] requestBytes = documentToByteArray(request);
7266
logger.log(Logger.LT_INFO,
7367
"Sending " + requestBytes.length + " bytes to " + serverURL);
7468
out.write(requestBytes);
7569
out.close();
76-
70+
System.out.println(System.getProperty("http.maxConnections"));
71+
System.out.println("JDKHttpURLConnection.postDocument time taken is " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime) + " ms");
7772
_isRequestSent = true;
7873
}
7974

@@ -110,8 +105,7 @@ InputStream getResponseStream()
110105
/* (non-Javadoc)
111106
* @see com.cybersource.ws.client.Connection#getResponseErrorStream()
112107
*/
113-
InputStream getResponseErrorStream()
114-
throws IOException {
108+
InputStream getResponseErrorStream() {
115109
return con != null ? con.getErrorStream() : null;
116110
}
117111

0 commit comments

Comments
 (0)