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
4949 */
5050public class Client {
5151 private static final String HEADER_FORMAT = "{0}={1}" ;
52-
52+
5353 private static final String SOAP_ENVELOPE1 = "<soap:Envelope xmlns:soap=\" " +
54- "http://schemas.xmlsoap.org/soap/envelope/\" >\n <soap:Body id=\" body1\" >\n " +
55- "<nvpRequest xmlns=\" {0}\" >\n {1}</nvpRequest>" +
56- "\n </soap:Body>\n </soap:Envelope>" ;
57-
54+ "http://schemas.xmlsoap.org/soap/envelope/\" >\n <soap:Body id=\" body1\" >\n " +
55+ "<nvpRequest xmlns=\" {0}\" >\n {1}</nvpRequest>" +
56+ "\n </soap:Body>\n </soap:Envelope>" ;
57+
5858 private static final String ELEM_NVP_REPLY = "nvpReply" ;
59-
59+
6060 private static final String MERCHANT_ID = "merchantID" ;
61-
6261
63-
62+
63+
6464 /**
6565 * Runs a transaction.
6666 *
@@ -71,11 +71,11 @@ public class Client {
7171 * @throws ClientException if any other exception occurs.
7272 */
7373 public static Map runTransaction (Map <String ,String > request , Properties props )
74- throws FaultException , ClientException {
74+ throws FaultException , ClientException {
7575 return (runTransaction (
76- request , props , null , true , true ));
76+ request , props , null , true , true ));
7777 }
78-
78+
7979 /**
8080 * Runs a transaction.
8181 *
@@ -91,16 +91,16 @@ public static Map runTransaction(Map<String,String> request, Properties props)
9191 * @throws ClientException if any other exception occurs.
9292 */
9393 public static Map runTransaction (
94- Map <String , String > request , Properties props ,
95- Logger _logger , boolean prepare , boolean logTranStart )
96- throws FaultException , ClientException {
94+ Map <String , String > request , Properties props ,
95+ Logger _logger , boolean prepare , boolean logTranStart )
96+ throws FaultException , ClientException {
9797 MerchantConfig mc ;
9898 LoggerWrapper logger = null ;
9999 Connection con = null ;
100-
100+
101101 try {
102102 setVersionInformation (request );
103-
103+
104104 String merchantID = request .get (MERCHANT_ID );
105105 if (merchantID == null ) {
106106 // if no merchantID is present in the request, get its
@@ -111,17 +111,17 @@ public static Map runTransaction(
111111 } else {
112112 mc = new MerchantConfig (props , merchantID );
113113 }
114-
114+
115115 logger = new LoggerWrapper (_logger , prepare , logTranStart , mc );
116-
116+
117117 DocumentBuilder builder = Utility .newDocumentBuilder ();
118-
118+
119119 Document signedDoc
120- = soapWrapAndSign (request , mc , builder ,logger );
120+ = soapWrapAndSign (request , mc , builder ,logger );
121121
122- // FileWriter writer = new FileWriter(new File("signedDoc.xml"));
123- // writer.write(XMLUtils.PrettyDocumentToString(signedDoc));
124- // writer.close();
122+ // FileWriter writer = new FileWriter(new File("signedDoc.xml"));
123+ // writer.write(XMLUtils.PrettyDocumentToString(signedDoc));
124+ // writer.close();
125125
126126 con = Connection .getInstance (mc , builder , logger );
127127 Document wrappedReply = con .post (signedDoc );
@@ -131,29 +131,29 @@ public static Map runTransaction(
131131 return replyMap ;
132132 } catch (IOException e ) {
133133 throw new ClientException (
134- e , con != null && con .isRequestSent (), logger );
134+ e , con != null && con .isRequestSent (), logger );
135135 } catch (ParserConfigurationException e ) {
136136 throw new ClientException (
137- e , con != null && con .isRequestSent (), logger );
137+ e , con != null && con .isRequestSent (), logger );
138138 } catch (SignException e ) {
139139 throw new ClientException (
140- e , con != null && con .isRequestSent (), logger );
140+ e , con != null && con .isRequestSent (), logger );
141141 } catch (ConfigException e ) {
142142 throw new ClientException (
143- e , con != null && con .isRequestSent (), logger );
143+ e , con != null && con .isRequestSent (), logger );
144144 } catch (SAXException e ) {
145- throw new ClientException (
146- e , con != null && con .isRequestSent (), logger );
147- } catch (SignEncryptException e ) {
148- throw new ClientException (
149- e , con != null && con .isRequestSent (), logger );
150- } finally {
145+ throw new ClientException (
146+ e , con != null && con .isRequestSent (), logger );
147+ } catch (SignEncryptException e ) {
148+ throw new ClientException (
149+ e , con != null && con .isRequestSent (), logger );
150+ } finally {
151151 if (con != null ) {
152152 con .release ();
153153 }
154154 }
155155 }
156-
156+
157157 /**
158158 * Sets the version information in the request.
159159 *
@@ -164,8 +164,8 @@ private static void setVersionInformation(Map<String, String> request) {
164164 request .put ("clientLibraryVersion" , Utility .VERSION );
165165 request .put ("clientEnvironment" , Utility .ENVIRONMENT );
166166 }
167-
168-
167+
168+
169169 /**
170170 * Wraps the given Map object in SOAP envelope and signs it.
171171 *
@@ -176,77 +176,76 @@ private static void setVersionInformation(Map<String, String> request) {
176176 * @return signed document.
177177 * @throws IOException if reading from string fails.
178178 * @throws SignException if signing fails.
179- * @throws SAXException
180- * @throws SignEncryptException
179+ * @throws SAXException
180+ * @throws SignEncryptException
181181 */
182182 private static Document soapWrapAndSign (
183- Map request , MerchantConfig mc , DocumentBuilder builder ,
184- LoggerWrapper logger )
185- throws
186- IOException , SignException , SAXException , SignEncryptException {
183+ Map request , MerchantConfig mc , DocumentBuilder builder ,
184+ LoggerWrapper logger )
185+ throws
186+ IOException , SignException , SAXException , SignEncryptException {
187187 boolean logSignedData = mc .getLogSignedData ();
188188 if (!logSignedData ) {
189189 logger .log (
190- Logger .LT_REQUEST ,
191- "UUID > " +(mc .getUniqueKey ()).toString () + "\n " +
192- "Input request is" + "\n " +
193- "======================================= \n "
194- + mapToString (request , true , PCI .REQUEST ));
190+ Logger .LT_REQUEST ,
191+ "UUID > " +(mc .getUniqueKey ()).toString () + "\n " +
192+ "Input request is" + "\n " +
193+ "======================================= \n "
194+ + mapToString (request , true , PCI .REQUEST ));
195195 }
196196
197197 Document wrappedDoc = soapWrap (request , mc , builder ,logger );
198- logger .log (Logger .LT_INFO , "Client, End of soapWrap " ,true );
198+ logger .log (Logger .LT_INFO , "Client, End of soapWrap " ,true );
199199
200200 Document resultDocument = null ;
201- <<<<<<< HEAD
202201 if (mc .getEnablejdkcert ()){
203- SecurityUtil .readJdkCert (mc ,logger );
202+ SecurityUtil .readJdkCert (mc ,logger );
204203 }
205204 else {
206- SecurityUtil .loadMerchantP12File (mc ,logger );
207- logger .log (Logger .LT_INFO , "Client, End of loadMerchantP12File " , true );
205+ SecurityUtil .loadMerchantP12File (mc ,logger );
206+ logger .log (Logger .LT_INFO , "Client, End of loadMerchantP12File " , true );
208207 }
209208 // sign Document object
210209 resultDocument = SecurityUtil .createSignedDoc (wrappedDoc , mc .getMerchantID (), mc .getKeyPassword (), logger );
211210 logger .log (Logger .LT_INFO , "Client, End of createSignedDoc " , true );
212-
211+
213212 if ( mc .getUseSignAndEncrypted () ) {
214- // Encrypt signed Document
213+ // Encrypt signed Document
215214 resultDocument = SecurityUtil .handleMessageCreation (resultDocument , mc .getMerchantID (), logger );
216215 logger .log (Logger .LT_INFO , "Client, End of handleMessageCreation " , true );
217216 }
218- =======
217+
219218 SecurityUtil .loadMerchantP12File (mc ,logger );
220- logger .log (Logger .LT_INFO , "Client, End of loadMerchantP12File " , true );
219+ logger .log (Logger .LT_INFO , "Client, End of loadMerchantP12File " , true );
221220
222221 // sign Document object
223222 resultDocument = SecurityUtil .createSignedDoc (wrappedDoc , mc .getMerchantID (), mc .getKeyPassword (), logger );
224223 logger .log (Logger .LT_INFO , "Client, End of createSignedDoc " , true );
225-
224+
226225 if ( mc .getUseSignAndEncrypted () ) {
227- // Encrypt signed Document
226+ // Encrypt signed Document
228227 resultDocument = SecurityUtil .handleMessageCreation (resultDocument , mc .getMerchantID (), logger );
229228 logger .log (Logger .LT_INFO , "Client, End of handleMessageCreation " , true );
230229 }
231- >>>>>>> upstream / master
230+
232231 if (logSignedData ) {
233- logger .log (Logger .LT_REQUEST ,Utility .nodeToString (resultDocument , PCI .REQUEST ));
234- //logger.log(Logger.LT_REQUEST,XMLUtils.PrettyDocumentToString(resultDocument));
232+ logger .log (Logger .LT_REQUEST ,Utility .nodeToString (resultDocument , PCI .REQUEST ));
233+ //logger.log(Logger.LT_REQUEST,XMLUtils.PrettyDocumentToString(resultDocument));
235234 }
236-
235+
237236 return resultDocument ;
238237 }
239-
238+
240239 private static Document soapWrap (Map request , MerchantConfig mc , DocumentBuilder builder , LoggerWrapper logger ) throws SAXException , IOException {
241- // wrap in SOAP envelope
240+ // wrap in SOAP envelope
242241 Object [] arguments
243- = {mc .getEffectiveNamespaceURI (),
244- mapToString (request , false , PCI .REQUEST )};
242+ = {mc .getEffectiveNamespaceURI (),
243+ mapToString (request , false , PCI .REQUEST )};
245244 String xmlString = MessageFormat .format (SOAP_ENVELOPE1 , arguments );
246245 // load XML string into a Document object
247246 StringReader sr = new StringReader ( xmlString );
248247 Document wrappedDoc = builder .parse ( new InputSource ( sr ) );
249- sr .close ();
248+ sr .close ();
250249 return wrappedDoc ;
251250 }
252251
@@ -260,36 +259,36 @@ private static Document soapWrap(Map request, MerchantConfig mc, DocumentBuilder
260259 * @return content of SOAP body as a Map object.
261260 */
262261 private static HashMap soapUnwrap (
263- Document doc , MerchantConfig mc , LoggerWrapper logger ) {
264-
265- // 3/8/2016 if the message was encrypted we need to decrypt it
266-
262+ Document doc , MerchantConfig mc , LoggerWrapper logger ) {
263+
264+ // 3/8/2016 if the message was encrypted we need to decrypt it
265+
267266 boolean logSignedData = mc .getLogSignedData ();
268267 if (logSignedData ) {
269268 logger .log (Logger .LT_REPLY ,
270- Utility .nodeToString (doc , PCI .REPLY ));
269+ Utility .nodeToString (doc , PCI .REPLY ));
271270 }
272-
271+
273272 // look for the nvpReply element
274273 Node nvpReply
275- = Utility .getElement (
276- doc , ELEM_NVP_REPLY , mc .getEffectiveNamespaceURI ());
277-
274+ = Utility .getElement (
275+ doc , ELEM_NVP_REPLY , mc .getEffectiveNamespaceURI ());
276+
278277 Text nvpString = (Text ) nvpReply .getFirstChild ();
279-
278+
280279 String replyString = nvpString .getNodeValue ();
281-
280+
282281 HashMap reply = Utility .stringToMap (replyString );
283-
282+
284283 if (!logSignedData ) {
285284 logger .log (
286- Logger .LT_REPLY ,
287- mapToString (reply , true , PCI .REPLY ));
285+ Logger .LT_REPLY ,
286+ mapToString (reply , true , PCI .REPLY ));
288287 }
289-
288+
290289 return reply ;
291290 }
292-
291+
293292 /**
294293 * Converts the contents of a Map object into a string, one name-value pair
295294 * to a line and the name and value are separated by an equal sign.
@@ -303,9 +302,9 @@ private static HashMap soapUnwrap(
303302 * empty.
304303 */
305304 static String mapToString (Map src , boolean mask , int type ) {
306- return Utility .mapToString (src , mask , type );
305+ return Utility .mapToString (src , mask , type );
307306 }
308-
307+
309308
310309}
311310
0 commit comments