Migrate with Java
This section explains how to edit the files in your application to use P12 authentication. If
you do not have the files that are mentioned in this section, you can find them in the
most recent version of the Java SOAP toolkit in GitHub.
Follow these steps to upgrade your Java code:
- Add these dependencies in 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>If you do not have an existingpom.xmlfile, you can use the one in theJavaSoapToolkitfolder in GitHub.
- Add this plugin in yourpom.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>
- Verify that thewsdlUrltag is set to a valid WSDL version value, and update it if necessary. Only version 1.219 or earlier is valid.
- 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(); - Go to GitHub and copy these files from theJavaSoapToolkit/src/main/java/com/cybersourcefolder. Add them to your project directory:
- Add thetoolkit.propertiesfile from thesrc/main/resourcesfolder in GitHub to your project.Edit thetoolkit.propertiesfile to contain this required content:MERCHANT_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/resourcesIf you are using your own properties file, you can make these changes in yourPropertiesUtil.javafile.
- Add your P12 certificate to your key directory.
- Run these two commands in your terminal:mvn clean installjava -jar target\JavaSoapToolkit.jar
- To confirm that your configuration is updated successfully, you can add a Bearer token that verifies that your requests are authenticated. To do so, add this command after line 54 in theBinarySecurityTokenHandler.javafile in thesrc\main\java\com\cybersourcefolder.System.out.println( soapMessageContext );
What to Do Next
After completing the above migration steps, you must send a test authorization
request using your P12 certificate to validate your migration. For more information,
see Send a Test Request with P12 Authentication.