|
26 | 26 | import org.xml.sax.InputSource; |
27 | 27 | import org.xml.sax.SAXException; |
28 | 28 |
|
| 29 | +import javax.security.cert.X509Certificate; |
29 | 30 | import javax.xml.parsers.DocumentBuilder; |
30 | 31 | import javax.xml.parsers.ParserConfigurationException; |
31 | 32 |
|
| 33 | +import java.io.File; |
| 34 | +import java.io.FileInputStream; |
32 | 35 | import java.io.IOException; |
33 | 36 | import java.io.StringReader; |
| 37 | +import java.security.KeyStore; |
| 38 | +import java.security.cert.PKIXParameters; |
| 39 | +import java.security.cert.TrustAnchor; |
34 | 40 | import java.text.MessageFormat; |
35 | 41 | import java.util.HashMap; |
| 42 | +import java.util.Iterator; |
36 | 43 | import java.util.Map; |
37 | 44 | import java.util.Properties; |
38 | 45 |
|
@@ -118,8 +125,10 @@ public static Map runTransaction( |
118 | 125 |
|
119 | 126 | con = Connection.getInstance(mc, builder, logger); |
120 | 127 | Document wrappedReply = con.post(signedDoc); |
121 | | - |
122 | | - return (soapUnwrap(wrappedReply, mc, logger)); |
| 128 | + Map<String, String> replyMap = soapUnwrap(wrappedReply, mc, logger); |
| 129 | + logger.log(Logger.LT_INFO, "Client, End of runTransaction Call ",false); |
| 130 | + |
| 131 | + return replyMap; |
123 | 132 | } catch (IOException e) { |
124 | 133 | throw new ClientException( |
125 | 134 | e, con != null && con.isRequestSent(), logger); |
@@ -178,51 +187,54 @@ private static Document soapWrapAndSign( |
178 | 187 | boolean logSignedData = mc.getLogSignedData(); |
179 | 188 | if (!logSignedData) { |
180 | 189 | logger.log( |
181 | | - Logger.LT_REQUEST, |
182 | | - 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)); |
| 195 | + } |
| 196 | + |
| 197 | + Document wrappedDoc = soapWrap(request, mc, builder,logger); |
| 198 | + logger.log(Logger.LT_INFO, "Client, End of soapWrap ",true); |
| 199 | + |
| 200 | + Document resultDocument = null; |
| 201 | + if(mc.getEnablejdkcert()){ |
| 202 | + SecurityUtil.readJdkCert(mc,logger); |
| 203 | + } |
| 204 | + else{ |
| 205 | + SecurityUtil.loadMerchantP12File(mc,logger); |
| 206 | + logger.log(Logger.LT_INFO, "Client, End of loadMerchantP12File ", true); |
183 | 207 | } |
| 208 | + // sign Document object |
| 209 | + resultDocument = SecurityUtil.createSignedDoc(wrappedDoc, mc.getMerchantID(), mc.getKeyPassword(), logger); |
| 210 | + logger.log(Logger.LT_INFO, "Client, End of createSignedDoc ", true); |
| 211 | + |
| 212 | + if ( mc.getUseSignAndEncrypted() ) { |
| 213 | + // Encrypt signed Document |
| 214 | + resultDocument = SecurityUtil.handleMessageCreation(resultDocument, mc.getMerchantID(), logger); |
| 215 | + logger.log(Logger.LT_INFO, "Client, End of handleMessageCreation ", true); |
| 216 | + } |
| 217 | + if (logSignedData) { |
| 218 | + logger.log(Logger.LT_REQUEST,Utility.nodeToString(resultDocument, PCI.REQUEST)); |
| 219 | + //logger.log(Logger.LT_REQUEST,XMLUtils.PrettyDocumentToString(resultDocument)); |
| 220 | + } |
| 221 | + |
| 222 | + return resultDocument ; |
| 223 | + } |
184 | 224 |
|
185 | | - // wrap in SOAP envelope |
| 225 | + private static Document soapWrap(Map request, MerchantConfig mc, DocumentBuilder builder, LoggerWrapper logger) throws SAXException, IOException{ |
| 226 | + // wrap in SOAP envelope |
186 | 227 | Object[] arguments |
187 | 228 | = {mc.getEffectiveNamespaceURI(), |
188 | 229 | mapToString(request, false, PCI.REQUEST)}; |
189 | 230 | String xmlString = MessageFormat.format(SOAP_ENVELOPE1, arguments); |
190 | | - // load XML string into a Document object |
| 231 | + // load XML string into a Document object |
191 | 232 | StringReader sr = new StringReader( xmlString ); |
192 | 233 | 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 ; |
| 234 | + sr.close(); |
| 235 | + return wrappedDoc; |
223 | 236 | } |
224 | | - |
225 | | - |
| 237 | + |
226 | 238 | /** |
227 | 239 | * Extracts the content of the SOAP body from the given Document object |
228 | 240 | * inside a SOAP envelope. |
|
0 commit comments