rendered paste body/*
* credit.java
*
* Created on November 6, 2006, 1:42 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package javaapplication2;
import java.io.*;
import java.util.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import com.cybersource.ws.client.*;
/**
*
* @author xbmodder
*/
public class credit {
Properties props;
/** Creates a new instance of credit */
public credit() {
String [] args;
args = new String[0];
props = Utility.readProperties( args );
System.out.println(props.getProperty("merchantID"));
}
public String hit(String foo) {
Document doc = Request(props, foo);
Document reply=null;
//System.out.println(Utility.nodeToString(doc));
try
{
reply = XMLClient.runTransaction( doc, props );
//System.out.println("Fllo");
// System.out.println( Utility.nodeToString( reply));
}
catch (ClientException e)
{
System.out.println( e.getLogString() );
}
catch (FaultException e)
{
System.out.println( e.getLogString() );
}
return Utility.nodeToString(reply);
}
private Document Request(Properties props, String foo){
Document doc = null;
try
{
// read in the XML file
byte[] xmlBytes = foo.getBytes();
// byte[] xmlBytes = foo.getBytes();
// replace _NSURI_ (if any) with effective namespace URI.
String xmlString = new String( xmlBytes, "UTF-8" );
// String xmlString = new String(foo.getBytes(), "UTF-8");
System.out.println(xmlString);
int pos = xmlString.indexOf( "_NSURI_" );
if (pos != -1)
{
StringBuffer sb = new StringBuffer( xmlString );
sb.replace(
pos, pos + 7,
XMLClient.getEffectiveNamespaceURI( props, null ) );
xmlBytes = sb.toString().getBytes( "UTF-8" );
}
// load the byte array into a Document object.
ByteArrayInputStream bais = new ByteArrayInputStream( xmlBytes );
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware( true );
DocumentBuilder builder = dbf.newDocumentBuilder();
doc = builder.parse( bais );
bais.close();
}
catch (ClientException e)
{
e.printStackTrace();
}
catch (ParserConfigurationException e)
{
e.printStackTrace();
}
catch (SAXException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
return( doc );
}
}