Prerequisites
You must create a P12 certificate. See the .
With this change to use a P12 certificate in your Java SOAP toolkit configuration, your
application must meet these new requirements:
- Java 9 or later
- Jakarta XML Web Services API
- JAX-WS Runtime
- Jakarta XML Web Services Distribution
- Bouncy Castle Cryptography APIs for JDK 1.5 to JDK 1.8
- Apache XML Security
- WSDL 1.219 or earlier
Java Migration Steps
Follow these steps to upgrade your Java code:
- Add these dependencies to thepom.xmlfile:<dependencies> <dependency> <groupId>jakarta.xml.ws</groupId> <artifactId>jakarta.xml.ws-api</artifactId> <version>4.0.2</version> </dependency> <dependency> <groupId>com.sun.xml.ws</groupId> <artifactId>jaxws-rt</artifactId> <version>4.0.3</version> <scope>runtime</scope> </dependency> <dependency> <groupId>com.sun.xml.ws</groupId> <artifactId>jaxws-ri</artifactId> <version>4.0.3</version> <type>pom</type> </dependency> <dependency> <groupId>org.bouncycastle</groupId> <artifactId>bcprov-jdk15to18</artifactId> <version>1.78</version> </dependency> <dependency> <groupId>org.apache.santuario</groupId> <artifactId>xmlsec</artifactId> <version>4.0.3</version> </dependency> </dependencies>
- Add this plugin to thepom.xmlfile:<build> <plugins> <plugin> <groupId>com.sun.xml.ws</groupId> <artifactId>jaxws-maven-plugin</artifactId> <version>4.0.3</version> <configuration> <wsdlUrls> <wsdlUrl>https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor/CyberSourceTransaction_1.219.wsdl</wsdlUrl> </wsdlUrls> <keep>true</keep> <packageName>com.cybersource.stub</packageName> <sourceDestDir>src/main/java</sourceDestDir> </configuration> </plugin> </plugins> </build>
- Check the value that is set in thewsdlUrltag, and update the version if necessary. The latest version of the WSDL that can be supported is 1.219.
- Run this command in your terminal:mvn clean jaxws:wsimport
- Find these lines in your existing code:
Replace them with these lines:TransactionProcessorLocator service = new TransactionProcessorLocator(); URL endpoint = new URL(SERVER_URL); ITransactionProcessorStub stub = (ITransactionProcessorStub) service.getportXML (endpoint); stub._setProperty(WSHandlerConstants.USER, request .getMerchantID());TransactionProcessor service = new TransactionProcessor(); service.setHandlerResolver(portInfo - >{ List < Handler > handlerList = new ArrayList < >(); handlerList.add(new BinarySecurityTokenHandler()); return handlerList; }); ITransactionProcessor stub = service.getPortXML(); - Copy these files to your project directory:
- BinarySecurityTokenHandler.java
- PropertiesUtil.java
- SecurityUtil.java
- Add atoolkit.propertiesfile in thesrc/main/resourcesfolder in your project. Thetoolkit.propertiesfile must contain this content:
If you want to use your own properties file, you can make these changes in theMERCHANT_ID = <your_merchant_id> LIB_VERSION = 4.0.3 KEY_ALIAS = <your_certificate_key_alias> KEY_FILE = <your_certificate_file> KEY_PASS = <your_certificate_password> KEY_DIRECTORY = src/main/resourcesPropertiesUtil.javafile. - Add your P12 certificate to your key directory.
- Run these commands in your terminal:mvn clean installjava -jar target\JavaSoapToolkit.jar
- (Optional) You can confirm that your configuration is updated successfully by checking that your request was authenticated using a Bearer token. To confirm, add this command after line 54 in thesrc\main\java\com\cybersource\BinarySecurityTokenHandler.javafile:System.out.println( soapMessageContext );
Sample Payload Using P12 Authentication
<?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:schemas-cybersource-com:transaction-data-1.215"> <SOAP-ENV:Header> <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> <wsse:BinarySecurityToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" wsu:Id="X509Token"> MIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigA........ </wsse:BinarySecurityToken> <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> <ds:SignedInfo> <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /> <ds:SignatureMethodAlgorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" /> <ds:Reference URI="#Body"> <ds:Transforms> <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /> </ds:Transforms> <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" /> <ds:DigestValue> KRmKx6digestvalye12389012367u7hlkV1vvbtec........... </ds:DigestValue> </ds:Reference> </ds:SignedInfo> <ds:SignatureValue>otrfnrck17dwxI4UR12345612yNG7TtE8L3XFhfEa/63r2uBDsg7b2YY8C6nKvkJGop4NHW7d30yfrz5dK2CHkp18TM+hVkyNIVLGokZzZpAwuc0sXm33+J4i765421duLsE4jM0FfIABsPHT2vgSq+T0g+812312jOeIk5R5kLhwnlVd92wQvBmpxINBW2Hh5adwwtpv+gj4AtvuhLYe1ky4R/oDNSWLPmyY1dSIyGDKO4ko8CT0mFlAvxECa8dLHRsyFrZVlK6................ </ds:SignatureValue> <ds:KeyInfo> <wsse:SecurityTokenReference> <wsse:Reference URI="#X509Token" /> </wsse:SecurityTokenReference> </ds:KeyInfo> </ds:Signature> </wsse:Security> </SOAP-ENV:Header> <soapenv:Body> <requestMessage xmlns="urn:schemas-cybersource-com:transaction-data-1.215"> <merchantID>johndoe</merchantID> <merchantReferenceCode>MRC-123</merchantReferenceCode> <billTo> <firstName>John</firstName> <lastName>Doe</lastName> <street1>123 Example Road</street1> <city>Austin</city> <state>TX</state> <postalCode>12345</postalCode> <country>US</country> <email>abc@company.com</email> </billTo> <shipTo> <firstName>John</firstName> <lastName>Doe</lastName> <street1>123 Example Road</street1> <city>Austin</city> <state>TX</state> <postalCode>12345</postalCode> <country>US</country> </shipTo> <purchaseTotals> <currency>USD</currency> <grandTotalAmount>100.00</grandTotalAmount> </purchaseTotals> <card> <accountNumber>4111111111111111</accountNumber> <expirationMonth>12</expirationMonth> <expirationYear>2029</expirationYear> <cvNumber>111</cvNumber> </card> <ccAuthService run="true"></ccAuthService> <ccCaptureService run="true"></ccCaptureService> </requestMessage> </soapenv:Body> </soapenv:Envelope>