import java.io.*;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class Actions
{
private String xmlStr = null;
private String finalFileName = null;
private String xmlDocument = null;
private String Formatted_msg = null;
public int init() throws Throwable {
return 0;
}//end of init
public int action() throws Throwable {
FileReader fr = null;
File f=new File("SalesTxn.xml");
int fileLength = (int) f.length();
char[] cbuf = new char[fileLength];
try {
fr = new FileReader(f);
fr.read(cbuf);
} catch (FileNotFoundException e) {
lr.error_message("Could not find data file: " + f);
lr.abort();
} catch (IOException e) {
lr.error_message("Error reading file: " + f);
lr.abort();
} finally{
try{
if(fr!=null){
fr.close();
}
}catch(IOException ioe){
lr.error_message("Error closing file reader: " + ioe);
lr.abort();
}
}
new String(cbuf);
String xmlDocument = String.valueOf(cbuf);
xmlDocument = xmlDocument.replace("<Body>TESTING</Body>","<Body>TEST<pBody></Body>");
Formatted_msg = xmlDocument;
// System.out.println("Formatted_msg:\n" +Formatted_msg);
try {
String request="https://webapps-qa.homedepot.com/MMCJECCInterface/rest/eccInterfaceServices/sendMessageDetails";
URL url = new URL(request);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type", "application/xml");
OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
lr.start_transaction("SOCC_01_ProText_ECC_01_Request");
writer.write(Formatted_msg);
writer.flush();
String line;
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = reader.readLine()) != null) {
// System.out.println("Sales Response:"+ line);
if (line.contains("SUCCESS")) {
lr.end_transaction("SOCC_01_ProText_ECC_01_Request", lr.PASS);
}else{
lr.end_transaction("SOCC_01_ProText_ECC_01_Request", lr.FAIL);
}
}
writer.close();
reader.close();
//System.out.println("\nDone");
} catch (Exception e) {
e.printStackTrace();
}
// System.out.println("\nDone");
return 0;
}//end of action
public int end() throws Throwable {
return 0;
}//end of end
}
No comments:
Post a Comment