Utilice las instrucciones siguientes para crear el flujo de mensajes del formulario de petición de transferencia.
Tipo de nodo | Nombre de nodo |
---|---|
HTTPInput | HTTP Input |
JavaCompute | TransferRequestForm |
HTTPReply | Respuesta de HTTP |
Nombre de nodo | Terminal | Conectar a este nodo |
---|---|---|
HTTP Input | Out | TransferRequestForm |
TransferRequestForm | Out | Respuesta de HTTP |
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.math.BigDecimal;
//Obtener sistema operativo String OS = System.getProperty("os.name").toLowerCase(); File file = null; //Guardar balance String savingsBalance = null; //Balance corriente si este archivo ya existe (ejemplo ampliado) String currentBalance = null; //Obtener la excepción String exception = null; try { //Leer balance adecuadamente del sistama de archivos local adecuado if (OS.indexOf("windows") > -1) { file = new File("C:\\tmp\\SavingsAccount.txt"); } else { file = new File("/tmp/SavingsAccount.txt"); } //Construir el objeto BufferedReader BufferedReader bufferedReader = new BufferedReader(new FileReader(file)); //Procesar los datos savingsBalance = new BigDecimal(bufferedReader.readLine()) .setScale(2, BigDecimal.ROUND_HALF_UP).toString(); try { //Leer balance del sistema de archivos local adecuado if (OS.indexOf("windows") > -1) { file = new File("C:\\tmp\\CurrentAccount.txt"); } else { file = new File("/tmp/CurrentAccount.txt"); } //Construir el objeto BufferedReader BufferedReader bufferedReader = new BufferedReader(new FileReader(file)); //Procesar los datos currentBalance = new BigDecimal(bufferedReader.readLine()) .setScale(2, BigDecimal.ROUND_HALF_UP).toString(); } catch (Exception e) { //Obtener mensaje de excepción exception = e.getMessage(); } } catch (Exception e) { //Obtener mensaje de excepción exception = e.getMessage(); }
//Crear diseño de página web para entrada de usuario StringBuffer html = new StringBuffer(); html.append("<HTML><HEAD>"); html.append("<META http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'></HEAD>"); html.append("<BODY><form action='/TransferRequestSample' enctype='multipart/form-data' method=post>"); html.append("<table cellpadding=4 cellspacing=2 border=0>"); html.append("<tr><td><td/><h1>Bank Transfer Form</h1></td>"); html.append("<tr><td><b>Request</b></td>"); html.append("<td><select name='Operation'>"); html.append("<option value='TransferToSavingsAccount'>Transfer To Savings Account</option>"); html.append("<option value='TransferToCurrentAccount'>Transfer To Current Account</option>"); html.append("</select></td></tr>"); html.append("<tr><td><b>Amount</b></td>"); html.append("<td><input type='text' name='Amount' size=10 maxlength=10></td></tr>"); html.append("<tr><td><td/><input type='submit' name='submit' value='Submit'></td></tr>"); html.append("<tr><td/><tr><td/>"); html.append("<tr><td><td/><h3>You have " + savingsBalance + " in your Savings Account</h3></td>"); //Si se ha procesado un balance de ahorro, mostrarlo if (savingsBalance != null) { html.append("<tr><td><td/><h3>You have " + savingsBalance + " in your Savings Account</h3></td>"); //Si se ha procesado un balance corriente, mostrarlo if (currentBalance != null) { html.append("<tr><td><td/><h3>You have " + currentBalance + " in your Current Account</h3></td>"); //De lo contrario, avisar al usuario } else { //O bien el archivo no existe if (exception!=null) { html.append("<tr><td><td/><h3>Cannot find " + exception + " This file is required for running the SCA Nodes sample extension</h3></td>"); //O el archivo contiene datos defectuosos } else { html.append("<tr><td><td/><h3><font color=\"#ff0000\">" + file.getName() + " contains corrupt data!</font></h3></td>"); } } //De lo contrario, avisar al usuario de problema grave } else { //O bien el archivo no existe if (exception!=null) { html.append("<tr><td><td/><h3><font color=\"#ff0000\">Cannot find " + exception + "</font></h3></td>"); //O el archivo contiene datos defectuosos } else { html.append("<tr><td><td/><h3><font color=\"#ff0000\">" + file.getName() + " contains corrupt data!</font></h3></td>"); } } html.append("</table></form></BODY></HTML>");
// Definir el tipo de contenido a html so that it may be viewed by a browser MbElement root = outMessage.getRootElement(); MbElement properties = root.getFirstElementByPath ("Properties"); MbElement contentType = properties.getFirstElementByPath ("ContentType"); contentType.setValue("text/html"); // Añadir el formulario de solicitud de correo electrónico como contenido del mensaje y publicar MbElement BLOB = root.createElementAsLastChild(MbBLOB.PARSER_NAME); BLOB.createElementAsFirstChild(MbElement.TYPE_NAME_VALUE, "BLOB", html.toString().getBytes());
Ahora puede crear el conjunto de mensajes de petición de transferencia bancaria, consulte Crear el conjunto de mensajes de petición de transferencia bancaria.