11/*
2- * Copyright 2003-2014 CyberSource Corporation
3- *
4- * THE SOFTWARE AND THE DOCUMENTATION ARE PROVIDED ON AN "AS IS" AND "AS
5- * AVAILABLE" BASIS WITH NO WARRANTY. YOU AGREE THAT YOUR USE OF THE SOFTWARE AND THE
6- * DOCUMENTATION IS AT YOUR SOLE RISK AND YOU ARE SOLELY RESPONSIBLE FOR ANY DAMAGE TO YOUR
7- * COMPUTER SYSTEM OR OTHER DEVICE OR LOSS OF DATA THAT RESULTS FROM SUCH USE. TO THE FULLEST
8- * EXTENT PERMISSIBLE UNDER APPLICABLE LAW, CYBERSOURCE AND ITS AFFILIATES EXPRESSLY DISCLAIM ALL
9- * WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, WITH RESPECT TO THE SOFTWARE AND THE
10- * DOCUMENTATION, INCLUDING ALL WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
11- * SATISFACTORY QUALITY, ACCURACY, TITLE AND NON-INFRINGEMENT, AND ANY WARRANTIES THAT MAY ARISE
12- * OUT OF COURSE OF PERFORMANCE, COURSE OF DEALING OR USAGE OF TRADE. NEITHER CYBERSOURCE NOR
13- * ITS AFFILIATES WARRANT THAT THE FUNCTIONS OR INFORMATION CONTAINED IN THE SOFTWARE OR THE
14- * DOCUMENTATION WILL MEET ANY REQUIREMENTS OR NEEDS YOU MAY HAVE, OR THAT THE SOFTWARE OR
15- * DOCUMENTATION WILL OPERATE ERROR FREE, OR THAT THE SOFTWARE OR DOCUMENTATION IS COMPATIBLE
16- * WITH ANY PARTICULAR OPERATING SYSTEM.
17- */
2+ * Copyright 2003-2014 CyberSource Corporation
3+ *
4+ * THE SOFTWARE AND THE DOCUMENTATION ARE PROVIDED ON AN "AS IS" AND "AS
5+ * AVAILABLE" BASIS WITH NO WARRANTY. YOU AGREE THAT YOUR USE OF THE SOFTWARE AND THE
6+ * DOCUMENTATION IS AT YOUR SOLE RISK AND YOU ARE SOLELY RESPONSIBLE FOR ANY DAMAGE TO YOUR
7+ * COMPUTER SYSTEM OR OTHER DEVICE OR LOSS OF DATA THAT RESULTS FROM SUCH USE. TO THE FULLEST
8+ * EXTENT PERMISSIBLE UNDER APPLICABLE LAW, CYBERSOURCE AND ITS AFFILIATES EXPRESSLY DISCLAIM ALL
9+ * WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, WITH RESPECT TO THE SOFTWARE AND THE
10+ * DOCUMENTATION, INCLUDING ALL WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
11+ * SATISFACTORY QUALITY, ACCURACY, TITLE AND NON-INFRINGEMENT, AND ANY WARRANTIES THAT MAY ARISE
12+ * OUT OF COURSE OF PERFORMANCE, COURSE OF DEALING OR USAGE OF TRADE. NEITHER CYBERSOURCE NOR
13+ * ITS AFFILIATES WARRANT THAT THE FUNCTIONS OR INFORMATION CONTAINED IN THE SOFTWARE OR THE
14+ * DOCUMENTATION WILL MEET ANY REQUIREMENTS OR NEEDS YOU MAY HAVE, OR THAT THE SOFTWARE OR
15+ * DOCUMENTATION WILL OPERATE ERROR FREE, OR THAT THE SOFTWARE OR DOCUMENTATION IS COMPATIBLE
16+ * WITH ANY PARTICULAR OPERATING SYSTEM.
17+ */
1818
1919package com .cybersource .ws .client ;
2020
3838
3939
4040/**
41- * Connection class is a factory class for creating an instance for HttpClientConnection or
41+ * It is a factory class for creating an instance for HttpClientConnection or
4242 * JDKHttpURLConnection or PoolingHttpClientConnection.
43- *
44- * @author sunagara
4543 */
4644abstract public class Connection {
4745 final MerchantConfig mc ;
4846 private final DocumentBuilder builder ;
4947 final LoggerWrapper logger ;
50-
51- /**
52- * Constructor.
53- * It initializes three arguments MerchantConfig, DocumentBuilder and Logger
54- * Any class extending this class must implement three argument constructor
55- * @param mc
56- * @param builder
57- * @param logger
58- */
59- protected Connection (MerchantConfig mc , DocumentBuilder builder ,
60- LoggerWrapper logger ) {
48+
49+ /**
50+ * It initializes three arguments MerchantConfig, DocumentBuilder and Logger
51+ * Any class extending this class must implement three argument constructor
52+ *
53+ * @param mc
54+ * @param builder
55+ * @param logger
56+ */
57+ protected Connection (MerchantConfig mc , DocumentBuilder builder ,
58+ LoggerWrapper logger ) {
6159 this .mc = mc ;
6260 this .builder = builder ;
6361 this .logger = logger ;
6462 }
6563
6664 /**
6765 * Get connection instance based on properties
66+ *
6867 * @param mc
6968 * @param builder
7069 * @param logger
@@ -73,30 +72,33 @@ protected Connection(MerchantConfig mc, DocumentBuilder builder,
7372 */
7473 public static Connection getInstance (
7574 MerchantConfig mc , DocumentBuilder builder , LoggerWrapper logger ) throws ClientException {
76- if (mc .getUseHttpClient ()) {
77- return new HttpClientConnection (mc , builder , logger );
78- } else if (mc .getUseHttpClientWithConnectionPool ()) {
75+ if (mc .getUseHttpClientWithConnectionPool ()) {
7976 return new PoolingHttpClientConnection (mc , builder , logger );
77+ } else if (mc .getUseHttpClient ()) {
78+ return new HttpClientConnection (mc , builder , logger );
8079 } else {
8180 // HttpClient is not set in properties file then JDKHttpURLConnection class instance.
8281 return new JDKHttpURLConnection (mc , builder , logger );
8382 }
8483 }
8584
8685 /**
87- * Abstract method to check is request sent or not
86+ * method to check is request sent or not
87+ *
8888 * @return boolean
8989 */
9090 abstract public boolean isRequestSent ();
9191
9292 /**
93- * Abstract method to release the connection related objects
93+ * method to release the connection related objects
94+ *
9495 * @throws ClientException
9596 */
9697 abstract public void release () throws ClientException ;
9798
9899 /**
99- * Abstract method to post request
100+ * method to post request
101+ *
100102 * @param request
101103 * @param startTime
102104 * @throws IOException
@@ -111,23 +113,20 @@ abstract void postDocument(Document request, long startTime)
111113 ProtocolException ;
112114
113115 /**
114- * Abstract method to get http response code
115116 * @return int
116117 * @throws IOException
117118 */
118119 abstract int getHttpResponseCode ()
119120 throws IOException ;
120121
121122 /**
122- * Abstract method to get response stream
123123 * @return InputStream
124124 * @throws IOException
125125 */
126126 abstract InputStream getResponseStream ()
127127 throws IOException ;
128128
129129 /**
130- * Abstract method to get response error stream
131130 * @return InputStram
132131 * @throws IOException
133132 */
@@ -136,6 +135,7 @@ abstract InputStream getResponseErrorStream()
136135
137136 /**
138137 * Post the request document and validate the response for any faults from the Server.
138+ *
139139 * @param request - Request document
140140 * @return - Response XML as Document object.
141141 * @throws ClientException
@@ -162,7 +162,8 @@ public Document post(Document request, long startTime)
162162
163163
164164 /**
165- * Validate the Http response for any faults returned from the server.
165+ * Validate the Http response for any faults returned from the server.
166+ *
166167 * @throws FaultException
167168 * @throws ClientException
168169 */
@@ -230,7 +231,8 @@ private void checkForFault()
230231 }
231232
232233 /**
233- * Method helps to parse/read the response xml into Document object.
234+ * Helps to parse/read the response xml into Document object.
235+ *
234236 * @return - returns a Document object
235237 * @throws IOException
236238 * @throws SAXException
@@ -246,7 +248,8 @@ private Document parseReceivedDocument()
246248
247249 /**
248250 * Converts the Document object into ByteArrayStream.
249- * @param doc - Document object
251+ *
252+ * @param doc - Document object
250253 * @return ByteArrayStream
251254 * @throws TransformerConfigurationException
252255 * @throws TransformerException
@@ -263,15 +266,9 @@ static ByteArrayOutputStream makeStream(Document doc)
263266 return baos ;
264267 }
265268
266- /**
267- * Log Request Headers
268- */
269- abstract public void logRequestHeaders ();
269+ abstract public void logRequestHeaders ();
270270
271- /**
272- * Log Response Headers
273- */
274- abstract public void logResponseHeaders ();
271+ abstract public void logResponseHeaders ();
275272}
276273
277274
0 commit comments