Skip to content

Commit 16d1175

Browse files
committed
Merge branch 'future' of https://github.com/Mayuri-Kumar93/cybersource-sdk-java into future
sync
2 parents 9d9a526 + a439f15 commit 16d1175

4 files changed

Lines changed: 218 additions & 9 deletions

File tree

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

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

4039

4140
/**
@@ -50,6 +49,7 @@ abstract public class Connection {
5049
final LoggerWrapper logger;
5150

5251
/**
52+
* Constructor.
5353
* It initializes three arguments MerchantConfig, DocumentBuilder and Logger
5454
* Any class extending this class must implement three argument constructor
5555
* @param mc
@@ -63,6 +63,14 @@ protected Connection(MerchantConfig mc, DocumentBuilder builder,
6363
this.logger = logger;
6464
}
6565

66+
/**
67+
* Get connection instance based on properties
68+
* @param mc
69+
* @param builder
70+
* @param logger
71+
* @return Connection
72+
* @throws ClientException
73+
*/
6674
public static Connection getInstance(
6775
MerchantConfig mc, DocumentBuilder builder, LoggerWrapper logger) throws ClientException {
6876
if (mc.getUseHttpClient()) {
@@ -75,21 +83,54 @@ public static Connection getInstance(
7583
}
7684
}
7785

86+
/**
87+
* Abstract method to check is request sent or not
88+
* @return boolean
89+
*/
7890
abstract public boolean isRequestSent();
7991

92+
/**
93+
* Abstract method to release the connection related objects
94+
* @throws ClientException
95+
*/
8096
abstract public void release() throws ClientException;
8197

98+
/**
99+
* Abstract method to post request
100+
* @param request
101+
* @param requestSentTime
102+
* @throws IOException
103+
* @throws TransformerConfigurationException
104+
* @throws TransformerException
105+
* @throws MalformedURLException
106+
* @throws ProtocolException
107+
*/
82108
abstract void postDocument(Document request, long requestSentTime)
83109
throws IOException, TransformerConfigurationException,
84110
TransformerException, MalformedURLException,
85111
ProtocolException;
86112

113+
/**
114+
* Abstract method to get http response code
115+
* @return int
116+
* @throws IOException
117+
*/
87118
abstract int getHttpResponseCode()
88119
throws IOException;
89120

121+
/**
122+
* Abstract method to get response stream
123+
* @return InputStream
124+
* @throws IOException
125+
*/
90126
abstract InputStream getResponseStream()
91127
throws IOException;
92128

129+
/**
130+
* Abstract method to get response error stream
131+
* @return InputStram
132+
* @throws IOException
133+
*/
93134
abstract InputStream getResponseErrorStream()
94135
throws IOException;
95136

@@ -221,12 +262,15 @@ static ByteArrayOutputStream makeStream(Document doc)
221262

222263
return baos;
223264
}
224-
/*
225-
* Log Request and Response Headers
226-
*
227-
*/
228265

266+
/**
267+
* Log Request Headers
268+
*/
229269
abstract public void logRequestHeaders();
270+
271+
/**
272+
* Log Response Headers
273+
*/
230274
abstract public void logResponseHeaders();
231275
}
232276

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

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,25 @@
4949
public class HttpClientConnection extends Connection {
5050
private PostMethod postMethod = null;
5151

52+
/**
53+
* Constructor.
54+
* @param mc
55+
* @param builder
56+
* @param logger
57+
*/
5258
HttpClientConnection(
5359
MerchantConfig mc, DocumentBuilder builder, LoggerWrapper logger) {
5460
super(mc, builder, logger);
5561
logger.log(Logger.LT_INFO, "Using HttpClient for connections.");
5662
}
5763

64+
/**
65+
* Post request by httpclient connection
66+
* @param request
67+
* @param requestSentTime
68+
* @throws IOException
69+
* @throws TransformerException
70+
*/
5871
/* (non-Javadoc)
5972
* @see com.cybersource.ws.client.Connection#postDocument(org.w3c.dom.Document)
6073
*/
@@ -87,13 +100,20 @@ void postDocument(Document request, long requestSentTime)
87100
httpClient.executeMethod(postMethod);
88101
}
89102

103+
/**
104+
* Method to check is request sent or not
105+
* @return boolean
106+
*/
90107
/* (non-Javadoc)
91108
* @see com.cybersource.ws.client.Connection#isRequestSent()
92109
*/
93110
public boolean isRequestSent() {
94111
return postMethod != null && postMethod.isRequestSent();
95112
}
96113

114+
/**
115+
* Method to release the http connections
116+
*/
97117
/* (non-Javadoc)
98118
* @see com.cybersource.ws.client.Connection#release()
99119
*/
@@ -104,13 +124,22 @@ public void release() {
104124
}
105125
}
106126

127+
/**
128+
* Method to get http response code
129+
* @return int
130+
*/
107131
/* (non-Javadoc)
108132
* @see com.cybersource.ws.client.Connection#getHttpResponseCode()
109133
*/
110134
int getHttpResponseCode(){
111135
return postMethod != null ? postMethod.getStatusCode() : -1;
112136
}
113137

138+
/**
139+
* Method to get response stream
140+
* @return InputStream
141+
* @throws IOException
142+
*/
114143
/* (non-Javadoc)
115144
* @see com.cybersource.ws.client.Connection#getResponseStream()
116145
*/
@@ -119,6 +148,11 @@ InputStream getResponseStream()
119148
return postMethod != null ? postMethod.getResponseBodyAsStream() : null;
120149
}
121150

151+
/**
152+
* Method to get response error stream
153+
* @return InputStream
154+
* @throws IOException
155+
*/
122156
/* (non-Javadoc)
123157
* @see com.cybersource.ws.client.Connection#getResponseErrorStream()
124158
*/
@@ -128,7 +162,7 @@ InputStream getResponseErrorStream()
128162
}
129163

130164
/**
131-
* Methos helps to set the timeout for HTTP request call.
165+
* Method helps to set the timeout for HTTP request call.
132166
* cybs.properties can be used to configure the timeout details.
133167
* @param httpClient
134168
* @param timeoutInMs
@@ -231,15 +265,21 @@ public boolean retryMethod(
231265
return false;
232266
}
233267
}
234-
268+
269+
/**
270+
* Log Request Headers
271+
*/
235272
@Override
236273
public void logRequestHeaders() {
237274
if(mc.getEnableLog() && postMethod!=null) {
238275
List<Header> reqheaders = Arrays.asList(postMethod.getRequestHeaders());
239276
logger.log(Logger.LT_INFO, "Request Headers: " + reqheaders);
240277
}
241278
}
242-
279+
280+
/**
281+
* Log Response Headers
282+
*/
243283
@Override
244284
public void logResponseHeaders() {
245285
if(mc.getEnableLog() && postMethod != null) {

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.io.OutputStream;
3131
import java.net.HttpURLConnection;
3232
import java.net.URL;
33-
import java.util.concurrent.TimeUnit;
3433

3534
import static com.cybersource.ws.client.Utility.*;
3635

@@ -45,12 +44,26 @@ public class JDKHttpURLConnection extends Connection {
4544
private boolean _isRequestSent = false;
4645
private HttpURLConnection con = null;
4746

47+
48+
/**
49+
* Constructor.
50+
* @param mc
51+
* @param builder
52+
* @param logger
53+
*/
4854
JDKHttpURLConnection(
4955
MerchantConfig mc, DocumentBuilder builder, LoggerWrapper logger) {
5056
super(mc, builder, logger);
5157
logger.log(Logger.LT_INFO, "Using JDKHttpURLConnection for connections.");
5258
}
5359

60+
/**
61+
* Post request by jdkHttpURL connection
62+
* @param request
63+
* @param requestSentTime
64+
* @throws IOException
65+
* @throws TransformerException
66+
*/
5467
void postDocument(Document request, long requestSentTime)
5568
throws IOException,
5669
TransformerException {
@@ -74,20 +87,32 @@ void postDocument(Document request, long requestSentTime)
7487
_isRequestSent = true;
7588
}
7689

90+
/**
91+
* Method to check is request sent or not
92+
* @return boolean
93+
*/
7794
/* (non-Javadoc)
7895
* @see com.cybersource.ws.client.Connection#isRequestSent()
7996
*/
8097
public boolean isRequestSent() {
8198
return _isRequestSent;
8299
}
83100

101+
/**
102+
* Method to release the connections
103+
*/
84104
/* (non-Javadoc)
85105
* @see com.cybersource.ws.client.Connection#release()
86106
*/
87107
public void release() {
88108
con = null;
89109
}
90110

111+
/**
112+
* Method to get http response code
113+
* @return int
114+
* @throws IOException
115+
*/
91116
/* (non-Javadoc)
92117
* @see com.cybersource.ws.client.Connection#getHttpResponseCode()
93118
*/
@@ -96,6 +121,11 @@ int getHttpResponseCode()
96121
return con != null ? con.getResponseCode() : -1;
97122
}
98123

124+
/**
125+
* Method to get response error stream
126+
* @return InputStram
127+
* @throws IOException
128+
*/
99129
/* (non-Javadoc)
100130
* @see com.cybersource.ws.client.Connection#getResponseStream()
101131
*/
@@ -104,6 +134,10 @@ InputStream getResponseStream()
104134
return con != null ? con.getInputStream() : null;
105135
}
106136

137+
/**
138+
* Method to get response error stream
139+
* @return InputStream
140+
*/
107141
/* (non-Javadoc)
108142
* @see com.cybersource.ws.client.Connection#getResponseErrorStream()
109143
*/
@@ -134,6 +168,9 @@ private static byte[] documentToByteArray(Document doc)
134168
}
135169
}
136170

171+
/**
172+
* Log Response Headers
173+
*/
137174
@Override
138175
public void logResponseHeaders() {
139176
if (mc.getEnableLog() && con != null) {
@@ -148,6 +185,9 @@ public void logResponseHeaders() {
148185
}
149186
}
150187

188+
/**
189+
* Log Request Headers
190+
*/
151191
@Override
152192
public void logRequestHeaders() {
153193
if (mc.getEnableLog() && con != null) {

0 commit comments

Comments
 (0)