13.01.2013 Views

Connecting to PaymentTrust's Secure Transaction Network - WorldPay

Connecting to PaymentTrust's Secure Transaction Network - WorldPay

Connecting to PaymentTrust's Secure Transaction Network - WorldPay

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Java sample code<br />

The following Java code fragments are intended for the Java JDK v1.3 or later. Java JSSE 1.0.2<br />

or later is required. Make sure the JSSE jar files are found within the extensions folder [JRE<br />

Home]/lib/ext. When compiling sample code, make sure JSSE jar files are within the<br />

CLASSPATH. The sample code below is taken as is from the provided Java sample code<br />

fragments supplied by PaymentTrust Ltd.<br />

import java.security.*;<br />

import java.net.*;<br />

import java.io.*;<br />

import java.util.*;<br />

public class HTTPClient<br />

{<br />

public static void main(String[] args)<br />

{<br />

// Set up a few system properties <strong>to</strong> be able <strong>to</strong> send transactions securely <strong>to</strong><br />

// the HTTP server. For more information please visit: http://java.sun.com/products/jsse/<br />

//<br />

// Dynamically register the sun SSL provider.<br />

Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());<br />

// Add the JSSE URL handler <strong>to</strong> the list of packages which are searched by the<br />

// java URL class.<br />

System.setProperty("java.pro<strong>to</strong>col.handler.pkgs", "com.sun.net.ssl.internal.www.pro<strong>to</strong>col");<br />

273<br />

// HTTP method <strong>to</strong> be used <strong>to</strong> communicate <strong>to</strong> HTTP server.<br />

// Values allowed: GET or POST. This is used <strong>to</strong> demonstrate how <strong>to</strong> use both<br />

// methods. It is recommended <strong>to</strong> use the POST method.<br />

String httpMethod = new String("POST");<br />

// The URL location <strong>to</strong> connect <strong>to</strong>.<br />

// To connect <strong>to</strong> the HTTP server securely, http:// must be replaced with https://<br />

String urlLocation = new String("https://www.paymenttrust.ca/stlinkssl/test/stlink.dll");<br />

// The STL transaction string.<br />

// We use URLEncoder <strong>to</strong> encode any reserved characters by the HTTP pro<strong>to</strong>col.<br />

String transaction = new<br />

String(URLEncoder.encode("https://www.paymenttrust.ca/stlinkssl/test/stlink.dll?StringIn=Version

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!