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:
  1. Add these dependencies in the
    pom.xml
    file.
    <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 existing
    pom.xml
    file, you can use the one in the
    JavaSoapToolkit
    folder in GitHub.
  2. Add this plugin in your
    pom.xml
    file:
    <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>
  3. Verify that the
    wsdlUrl
    tag is set to a valid WSDL version value, and update it if necessary. Only version 1.219 or earlier is valid.
  4. Run this command in your terminal:
    mvn clean jaxws:wsimport
  5. Find these lines in your existing code:
    TransactionProcessorLocator service = new TransactionProcessorLocator(); URL endpoint = new URL(SERVER_URL); ITransactionProcessorStub stub = (ITransactionProcessorStub) service.getportXML (endpoint); stub._setProperty(WSHandlerConstants.USER, request .getMerchantID());
    Replace them with these lines:
    TransactionProcessor service = new TransactionProcessor(); service.setHandlerResolver(portInfo - >{ List < Handler > handlerList = new ArrayList < >(); handlerList.add(new BinarySecurityTokenHandler()); return handlerList; }); ITransactionProcessor stub = service.getPortXML();
  6. Go to GitHub and copy these files from the
    JavaSoapToolkit/src/main/java/com/cybersource
    folder. Add them to your project directory:
  7. Add the
    toolkit.properties
    file from the
    src/main/resources
    folder in GitHub to your project.
    Edit the
    toolkit.properties
    file 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/resources
    If you are using your own properties file, you can make these changes in your
    PropertiesUtil.java
    file.
  8. Add your P12 certificate to your key directory.
  9. Run these two commands in your terminal:
    mvn clean install
    java -jar target\JavaSoapToolkit.jar
  10. 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 the
    BinarySecurityTokenHandler.java
    file in the
    src\main\java\com\cybersource
    folder.
    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.