Java {#rn-announce}
===================

Prerequisites
-------------

You must create a P12 certificate. See the *[Getting Started with REST Developer Guide](https://developer.cybersource.com/docs/cybs/en-us/platform/developer/all/rest/rest-getting-started/restgs-jwt-message-intro/restgs-security-p12-intro.md "")*.  
With this change to use a P12 certificate in your Java SOAP toolkit configuration, your application must meet these new requirements:
* Java 9 or higher
* 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:

1. Add these dependencies to the *pom.xml* file:

   ```
   &lt;dependencies&gt;
     &lt;dependency&gt;
       &lt;groupId&gt;jakarta.xml.ws&lt;/groupId&gt;
       &lt;artifactId&gt;jakarta.xml.ws-api&lt;/artifactId&gt;
       &lt;version&gt;4.0.2&lt;/version&gt;
     &lt;/dependency&gt;
     &lt;dependency&gt;
       &lt;groupId&gt;com.sun.xml.ws&lt;/groupId&gt;
       &lt;artifactId&gt;jaxws-rt&lt;/artifactId&gt;
       &lt;version&gt;4.0.3&lt;/version&gt;
       &lt;scope&gt;runtime&lt;/scope&gt;
     &lt;/dependency&gt;
     &lt;dependency&gt;
       &lt;groupId&gt;com.sun.xml.ws&lt;/groupId&gt;
       &lt;artifactId&gt;jaxws-ri&lt;/artifactId&gt;
       &lt;version&gt;4.0.3&lt;/version&gt;
       &lt;type&gt;pom&lt;/type&gt;
     &lt;/dependency&gt;
     &lt;dependency&gt;
       &lt;groupId&gt;org.bouncycastle&lt;/groupId&gt;
       &lt;artifactId&gt;bcprov-jdk15to18&lt;/artifactId&gt;
       &lt;version&gt;1.78&lt;/version&gt;
     &lt;/dependency&gt;
     &lt;dependency&gt;
       &lt;groupId&gt;org.apache.santuario&lt;/groupId&gt;
       &lt;artifactId&gt;xmlsec&lt;/artifactId&gt;
       &lt;version&gt;4.0.3&lt;/version&gt;
     &lt;/dependency&gt;
   &lt;/dependencies&gt;
   ```
2. Add this plugin to the *pom.xml* file:

   ```
   &lt;build&gt;
     &lt;plugins&gt;
       &lt;plugin&gt;
         &lt;groupId&gt;com.sun.xml.ws&lt;/groupId&gt;
         &lt;artifactId&gt;jaxws-maven-plugin&lt;/artifactId&gt;
         &lt;version&gt;4.0.3&lt;/version&gt;
         &lt;configuration&gt;
   	  &lt;wsdlUrls&gt;
              &lt;wsdlUrl&gt;https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor/CyberSourceTransaction_1.219.wsdl&lt;/wsdlUrl&gt;
           &lt;/wsdlUrls&gt;
           &lt;keep&gt;true&lt;/keep&gt;
           &lt;packageName&gt;com.cybersource.stub&lt;/packageName&gt;
           &lt;sourceDestDir&gt;src/main/java&lt;/sourceDestDir&gt;
         &lt;/configuration&gt;
       &lt;/plugin&gt;
     &lt;/plugins&gt;
   &lt;/build&gt;
   ```
3. Check the value that is set in the *wsdlUrl* tag, and update the version if necessary. The latest version of the WSDL that can be supported is 1.219.

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 - &gt;{
     List &lt; Handler &gt; handlerList = new ArrayList &lt; &gt;();
     handlerList.add(new BinarySecurityTokenHandler());
     return handlerList;
   });

   ITransactionProcessor stub = service.getPortXML();
   ```
6. Copy these files to your project directory:

   * BinarySecurityTokenHandler.java
   * PropertiesUtil.java
   * SecurityUtil.java
7. Add a *toolkit.properties* file in the *src/main/resources* folder in your project. The *toolkit.properties* file must contain this content:

   ```
   MERCHANT_ID = &lt;your_merchant_id&gt;
   LIB_VERSION = 4.0.3
   KEY_ALIAS = &lt;your_certificate_key_alias&gt;
   KEY_FILE = &lt;your_certificate_file&gt;
   KEY_PASS = &lt;your_certificate_password&gt;
   KEY_DIRECTORY = src/main/resources
   ```

   If you want to use your own properties file, you can make these changes in the *PropertiesUtil.java* file.

8. Add your P12 certificate to your key directory.

9. Run these commands in your terminal:

   ```
   mvn clean install
   ```

   ```
   java -jar target\JavaSoapToolkit.jar
   ```
10. (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 the *src\\main\\java\\com\\cybersource\\BinarySecurityTokenHandler.java* file:

    ```
    System.out.println( soapMessageContext ); 
    ```

