N
Neil Aggarwal
Hello:
This class posts and XML request to ProPay's test server and generates
the correct response:
import java.io.*;
import java.net.*;
public class DirectSocketTest {
public static final String PROPAY_SERVER = "devtst.propay.com";
public static final String PROPAY_SERVER_PATH =
"/xml/xml.exe/process";
/** Creates a new instance of DirectSocketTest */
public DirectSocketTest() throws Exception {
// Connect a socket to the propay server
Socket socket = new Socket(PROPAY_SERVER,80);
// Create a writer to the socket
PrintWriter writer = new PrintWriter(new
OutputStreamWriter(socket.getOutputStream()));
// Get a reader from the socket
BufferedReader reader = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
// Create the request for the propay server
String content = "<?xml version= \"1.0\"?>";
content += "<!DOCTYPE Request.dtd>";
content += "<XML Request>";
content += "
<username>[email protected]</username>";
content += "
<certStr>MadroneTestCertStraaaaaaaaaaaa</certStr>";
content += " <class>partner</class>";
content += " <XMLTrans>";
content += " <transType>05</transType>";
content += " <amount>9997</amount>" ;
content += " <sourceEmail>[email protected]</sourceEmail>"
;
content += " <ccNum>1544444444443333</ccNum>" ;
content += " <expDate>0102</expDate>" ;
content += " <CVV2>312</CVV2>" ;
content += " <invNum>G67613E</invNum>" ;
content += " </XMLTrans>" ;
content += "</XMLRequest>" ;
writer.println("POST "+PROPAY_SERVER_PATH+" HTTP/1.0");
writer.println("From: (e-mail address removed)");
writer.println("User-Agent: HTTPTool/1.0");
writer.println("Content-Type: text/xml; charset:ISO-8859-1;");
writer.println("Content-Length: "+content.length());
writer.println();
writer.println(content);
writer.println();
writer.flush();
// Read the result
String line = reader.readLine();
while( line != null ) {
System.out.println( line );
line = reader.readLine();
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
new DirectSocketTest();
}
}
Here is the output:
HTTP/1.1 200 OK
Server: Microsoft-IIS/4.0
Date: Sun, 18 Apr 2004 02:35:44 GMT
Content-Type: text/xml
Content-Length: 391
Content:
<?xml version="1.0" standalone="no"?>
<XMLResponse xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.propay.com/schema/PPResponse.xsd">
<XMLTrans>
<transType>05</transType>
<sourceEmail>[email protected]</sourceEmail>
<invNum>G67613E</invNum>
<status>48</status>
<transNum></transNum>
<authCode></authCode>
</XMLTrans>
</XMLResponse>
I wrote this class to do the same thing using the java.net classes:
import java.io.*;
import java.net.*;
public class PropayTest {
public static final String PROPAY_URL =
"http://devtst.propay.com/xml/xml.exe/process";
/** Creates a new instance of PropayTest */
public PropayTest() throws Exception {
// Create the request for the propay server
String content = "<?xml version= \"1.0\"?>";
content += "<!DOCTYPE Request.dtd>";
content += "<XML Request>";
content += "
<username>[email protected]</username>";
content += "
<certStr>MadroneTestCertStraaaaaaaaaaaa</certStr>";
content += " <class>partner</class>";
content += " <XMLTrans>";
content += " <transType>05</transType>";
content += " <amount>9997</amount>" ;
content += " <sourceEmail>[email protected]</sourceEmail>"
;
content += " <ccNum>1544444444443333</ccNum>" ;
content += " <expDate>0102</expDate>" ;
content += " <CVV2>312</CVV2>" ;
content += " <invNum>G67613E</invNum>" ;
content += " </XMLTrans>" ;
content += "</XMLRequest>" ;
// Connect to the propay url
URL url = new URL(PROPAY_URL);
URLConnection connection = url.openConnection();
if( connection instanceof HttpURLConnection )
((HttpURLConnection)connection).setRequestMethod("POST");
connection.setRequestProperty("Content-Length",
Integer.toString(content.length()) );
connection.setRequestProperty("Content-Type","text/xml;
charset:ISO-8859-1;");
connection.setDoOutput(true);
connection.connect();
// Create a writer to the url
PrintWriter writer = new PrintWriter(new
OutputStreamWriter(connection.getOutputStream()));
// Get a reader from the url
BufferedReader reader = new BufferedReader(new
InputStreamReader(connection.getInputStream()));
// Send the content to the propay server
writer.println();
writer.println(content);
writer.println();
writer.flush();
String line = reader.readLine();
while( line != null ) {
System.out.println( line );
line = reader.readLine();
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
new PropayTest();
}
}
But I get this output:
<?xml version="1.0" standalone="no"?>
<XMLResponse xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.propay.com/schema/PPResponse.xsd">
</XMLResponse>
Any ideas on why the java.net version of the code does not act the
same?
Thanks
Neil
This class posts and XML request to ProPay's test server and generates
the correct response:
import java.io.*;
import java.net.*;
public class DirectSocketTest {
public static final String PROPAY_SERVER = "devtst.propay.com";
public static final String PROPAY_SERVER_PATH =
"/xml/xml.exe/process";
/** Creates a new instance of DirectSocketTest */
public DirectSocketTest() throws Exception {
// Connect a socket to the propay server
Socket socket = new Socket(PROPAY_SERVER,80);
// Create a writer to the socket
PrintWriter writer = new PrintWriter(new
OutputStreamWriter(socket.getOutputStream()));
// Get a reader from the socket
BufferedReader reader = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
// Create the request for the propay server
String content = "<?xml version= \"1.0\"?>";
content += "<!DOCTYPE Request.dtd>";
content += "<XML Request>";
content += "
<username>[email protected]</username>";
content += "
<certStr>MadroneTestCertStraaaaaaaaaaaa</certStr>";
content += " <class>partner</class>";
content += " <XMLTrans>";
content += " <transType>05</transType>";
content += " <amount>9997</amount>" ;
content += " <sourceEmail>[email protected]</sourceEmail>"
;
content += " <ccNum>1544444444443333</ccNum>" ;
content += " <expDate>0102</expDate>" ;
content += " <CVV2>312</CVV2>" ;
content += " <invNum>G67613E</invNum>" ;
content += " </XMLTrans>" ;
content += "</XMLRequest>" ;
writer.println("POST "+PROPAY_SERVER_PATH+" HTTP/1.0");
writer.println("From: (e-mail address removed)");
writer.println("User-Agent: HTTPTool/1.0");
writer.println("Content-Type: text/xml; charset:ISO-8859-1;");
writer.println("Content-Length: "+content.length());
writer.println();
writer.println(content);
writer.println();
writer.flush();
// Read the result
String line = reader.readLine();
while( line != null ) {
System.out.println( line );
line = reader.readLine();
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
new DirectSocketTest();
}
}
Here is the output:
HTTP/1.1 200 OK
Server: Microsoft-IIS/4.0
Date: Sun, 18 Apr 2004 02:35:44 GMT
Content-Type: text/xml
Content-Length: 391
Content:
<?xml version="1.0" standalone="no"?>
<XMLResponse xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.propay.com/schema/PPResponse.xsd">
<XMLTrans>
<transType>05</transType>
<sourceEmail>[email protected]</sourceEmail>
<invNum>G67613E</invNum>
<status>48</status>
<transNum></transNum>
<authCode></authCode>
</XMLTrans>
</XMLResponse>
I wrote this class to do the same thing using the java.net classes:
import java.io.*;
import java.net.*;
public class PropayTest {
public static final String PROPAY_URL =
"http://devtst.propay.com/xml/xml.exe/process";
/** Creates a new instance of PropayTest */
public PropayTest() throws Exception {
// Create the request for the propay server
String content = "<?xml version= \"1.0\"?>";
content += "<!DOCTYPE Request.dtd>";
content += "<XML Request>";
content += "
<username>[email protected]</username>";
content += "
<certStr>MadroneTestCertStraaaaaaaaaaaa</certStr>";
content += " <class>partner</class>";
content += " <XMLTrans>";
content += " <transType>05</transType>";
content += " <amount>9997</amount>" ;
content += " <sourceEmail>[email protected]</sourceEmail>"
;
content += " <ccNum>1544444444443333</ccNum>" ;
content += " <expDate>0102</expDate>" ;
content += " <CVV2>312</CVV2>" ;
content += " <invNum>G67613E</invNum>" ;
content += " </XMLTrans>" ;
content += "</XMLRequest>" ;
// Connect to the propay url
URL url = new URL(PROPAY_URL);
URLConnection connection = url.openConnection();
if( connection instanceof HttpURLConnection )
((HttpURLConnection)connection).setRequestMethod("POST");
connection.setRequestProperty("Content-Length",
Integer.toString(content.length()) );
connection.setRequestProperty("Content-Type","text/xml;
charset:ISO-8859-1;");
connection.setDoOutput(true);
connection.connect();
// Create a writer to the url
PrintWriter writer = new PrintWriter(new
OutputStreamWriter(connection.getOutputStream()));
// Get a reader from the url
BufferedReader reader = new BufferedReader(new
InputStreamReader(connection.getInputStream()));
// Send the content to the propay server
writer.println();
writer.println(content);
writer.println();
writer.flush();
String line = reader.readLine();
while( line != null ) {
System.out.println( line );
line = reader.readLine();
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
new PropayTest();
}
}
But I get this output:
<?xml version="1.0" standalone="no"?>
<XMLResponse xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.propay.com/schema/PPResponse.xsd">
</XMLResponse>
Any ideas on why the java.net version of the code does not act the
same?
Thanks
Neil