As a guess, should you be using post or get to send this?

Ade

-----Original Message-----
From: phil williams [mailto:[EMAIL PROTECTED]
Sent: 28 August 2004 11:37
To: CF-Talk
Subject: Problem with sending XML through local socket

OK I have been implementing the Secure Trading socket,
http://www.securetrading.com , for an online store that I am developing for
a client and have hit a snag.  The system uses a Java file to connect
through the localhost on port 5000 to send the data to ST for processing in
XML format.  A XML response is then returned.  Their example using Java to
send the XML is fine but my ColdFusion code is getting a time out ewrror.
Here�s the code I�m using:

<cffile action="" file="#certDirPath#\sendPayment.xml"
variable="testxml">
<cfhttp method="post" url="" port="5000" timeout="60">
<cfhttpparam type="xml" name="xpay" value="#testxml#">
</cfhttp>

It�s simply reading the xml file and sending it with cfhttp.  Their Java
code is like this:
/********************************************************************
* SECURETRADING Merchant Software
*
* Sample Java XPay script
*
* Description:
* Reads an XML string in from a file (representing a merchant's own script)
* and then open a socket, writing the XML string to the XPay API.
* The certificate is read in and replaced in the XML string
* To run this file ensure that test.xml resides in the same directory as
* this file
*
* Version 2.2
*
* Last modified: 25/02/2002
*
* Copyright (C) 2002 SECURETRADING All rights reserved.
*
* This software is for informational purposes only.
* SECURETRADING make no warranties, express or implied, through the
* distribution of this example.
*
* SECURETRADING
* http://www.securetrading.com
* Tel (+44) 01248 672 050
* Email [EMAIL PROTECTED]
*
* You may only modify or use this script for the purpose of
* authorised access to the SECURETRADING Payment Gateway Network
* in accordance with your SECURETRADING Agreement.
*
*************************************************************************/

import java.net.*;
import java.io.*;

public class Test
{
public static void main(String[] args) throws Exception
{

// First get the location of the certificate file from the command line
System.out.println("** Note: When using live certificates, they should be
kept in secure place on your server **\n");
String filename;
try
{
filename = args[0];
}
catch (Exception e)
{
System.out.println("Certificate Filename Error\n");
System.out.println("Incorrect or no certificate filename specified");
System.out.println("Include the certificate filename when running this
example :");
System.out.println("java Test mycert.pem\n");
System.out.println();
throw new Exception("Certificate filename not specified");
}

// Use the given filename to read in the certificate details and then
combine them with the XML from test.xml
try
{
// Read in the certificate
String certificate = Test.readFile(filename);

// As an example, send the XML string which is in the example test.xml
file
// This string could normally be created by XML Parsers or other such
objects
String xml = Test.readFile("test.xml");

// Combine the xml with the certificate
xml = Test.replace(xml, certificate);

// Connect to the XPay client which runs on this computer
System.out.println("Please wait while the transaction is authorised...");
String host = "127.0.0.1";
int port = 5000;
Socket sock = new Socket(host, port);

// Get the relevant streams to the socket
InputStreamReader ir = new InputStreamReader(sock.getInputStream());
BufferedReader in = new BufferedReader(ir);

OutputStreamWriter or = new OutputStreamWriter(sock.getOutputStream());
BufferedWriter out = new BufferedWriter(or);

// Send the actual xml string representing a transaction
out.write(xml);
out.flush();

// Receive the resulting XML response for this transaction
// Wait until the result is ready
// Now there is something ready to receive in the socket stream

String inputLine, result = "";
while( (inputLine = in.readLine()) != null )
result+=inputLine+"\n";

// Print the result. This could be parsed into any data structure
System.out.println(result);
}
catch (Exception e)
{
System.out.println("Error");
System.out.println(e.getMessage());
}
}

// Read in a file and returns the contents

private static String readFile(String filename) throws IOException,
FileNotFoundException
{
System.out.println("Reading from file: "+filename);
BufferedReader input = new BufferedReader(new InputStreamReader(new
FileInputStream(filename)));
String text="";
while (input.ready())
{
text += (char)input.read();
}
return text;
}

// In the XML add the certificate between the <Certificate></Certificate>
tags.

private static String replace(String xml, String certificate)
{
int fio = xml.lastIndexOf("<Certificate>")+13; // Add the length of the
tag in order to point to the index of the end
int lio = xml.lastIndexOf("</Certificate>");
String result =
xml.substring(0,fio)+certificate+xml.substring(lio,xml.length());
return result;
}

}
// END OF PROGRAM //

My question is is there anything wrong with my code or can I adapt their
script to send the request as CF is Java based?

Thanks in advance
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to