Chapter 2

Java Sample Code for Uploading Batch Files

This chapter explains how to use the sample Java code from CyberSource to upload batch files to CyberSource.

Requirements

•   J2SE 1.4 or higher

•   Unlimited Strength Jurisdiction Policy files from Sun Microsystems® (US_export_policy.jar and local_policy.jar), available at http://java.sun.com/j2se/1.4.2/download.html#docs

•   Bouncy Castle (which includes bcmail*.jar, bcpg*.jar, bcprov*.jar and bctest*.jar), available at www.bouncycastle.org

•   CyberSource’s sample code package, available on the Support Center, in the "Additional Downloads" section of the downloads page

Using the Sample Code

1   Replace your Java installation’s existing security policy files with the new ones you downloaded from Sun’s site:

a   Locate your existing US_export_policy.jar and local_policy.jar files in the $JAVA_HOME/jre/lib/security directory.

b   Rename or move your existing files to another directory.

c   Copy the new US_export_policy.jar and local_policy.jar that you downloaded from Sun to the $JAVA_HOME/jre/lib/security directory.

2   Copy the Bouncy Castle *.jar files to the $JAVA_HOME/jre/lib/ext directory.

3   Edit $JAVA_HOME/jre/lib/security/java.security and insert the security provider right after the Sun provider. Make sure to increment the numbers of the other providers in the list. The line to insert is this:

Security.provider.2=org.bouncycastle.jce.provider.BouncyCastleProvider

Your list of security providers will now look similar to this:

security.provider.1=sun.security.provider.Sun

security.provider.2=org.bouncycastle.jce.provider.BouncyCastleProvider

security.provider.3=com.sun.net.ssl.internal.ssl.Provider

security.provider.4=com.sun.rsajca.Provider

security.provider.5=com.sun.crypto.provider.SunJCE

security.provider.6=sun.security.jgss.SunProvider

 

4   Create a key store file for your CyberSource security key:

a   In a Web browser, go to one of the following URLs:

If you are in test mode and have not gone live with CyberSource:
https://batchtest.cybersource.com/upload/BatchFileUpload

If you have gone live with CyberSource:
https://batch.cybersource.com/upload/BatchFileUpload

b   Go to File > Properties.

c   Click Certificates.

d   Click the Detail tab.

e   Click Copy to File and then Next.

f   Click Browse and navigate to where you want to save the file.

g   Enter the name you want to use for the file (such as MyCert) and click Save and then Next.

h   Click Finish.

Your file (for example, MyCert.cer) has been created in the location you specified.

i   Go to $JAVA_HOME/bin/keytool and use the J2SE keytool program to create a keystore file that contains this newly created certificate. To do this, type the following command:

$JAVA_HOME/bin/keytool -import -file <path to certificate>/<name of certificate file> -keystore <name of keystore file>.jks -storepass <pass phrase for the keystore file>

 

For example:

$JAVA_HOME/bin/keytool -import -file /home/bluu/MyCert.cer -keystore MyKeystore.jks -storepass MyKeystorePass

 

If successful, the output will be similar to this:

Owner: CN=batchtest.cybersource.com, OU=Operations, O=Cybersource Corporation, L=Mountain View, ST=California, C=US

Issuer: CN=Entrust.net Secure Server Certification Authority, OU=(c) 1999 Entrust.net Limited, OU=www.entrust.net/CPS incorp. by ref. (limits liab.), O=Entrust.net, C=US

Serial number: 374e1b7b

Valid from: Thu Nov 18 17:15:34 PST 2004 until: Tue Jan 31 17:51:24 PST 2006

Certificate fingerprints:

  MD5:  BE:BF:B0:91:69:C4:7B:10:45:EC:D6:0F:16:AA:3D:77

  SHA1: 07:F8:41:DC:B2:FC:F5:DA:FC:EE:09:7A:33:B8:29:15:31:18

Trust this certificate? [no]: yes

Certificate was added to keystore

 

5   Modify the SSLFileTransfer.props file with your settings. The file is part of the CyberSource download package and looks similar to this:

# Upload/Download host

host=<upload host>

 

# Upload/Download port

port=<upload port>

 

# Username to log into the Business Center

bcUserName=<Business Center login name>

 

# Password to log into the Business Center

bcPassword=<Business Center login password>

 

# File to upload

uploadFile=<path to batch file>/<batch file name>

 

# Path where to upload the file (provided by CyberSource)

path=/ebc/UploadBatchFile

 

# Your CyberSource security key

key=<key location path>/<key file name>

 

# New key store you just created that contains the certificate

keyStore=<key store location>/<new key store name>

 

# pass phrase is the string you used in -storepass option when you # created the key store file earlier

passPhrase=<pass phrase>

 

6   Set the JAVA_HOME environment variable to where you installed J2SE. For example:

JAVA_HOME=/home/j2se

7   Include $JAVA_HOME/bin in the PATH.

8   Compile and run the sample:

a   Change to the directory where you stored the CyberSource sample files.

b   Type the following:

javac SSLFileTransfer.java

java SSLFileTransfer <path to props file>/SSLFileTransfer.props

 

If the upload is successful, the output should look similar to this:

HTTP/1.1 200 OK

Date: Wed, 26 Jan 2005 17:26:31 GMT

Server: Apache Coyote/1.0

Content-Type: text/plain

Content-Length: 0

X-Cache: MISS from <your host>

Connection: close

UPLOAD FILE SUCCESSFUL