创建转帐请求表单消息流

使用以下指示信息创建转帐请求表单消息流。

  1. 创建 Integration 项目:
    1. 单击“文件 > 新建 > Integration 项目”。
    2. 将“项目名称”设置为 SCANodesSample,然后单击“完成”。
  2. 创建新消息流:
    1. 右键单击 Integration 项目 SCANodesSample,然后单击“新建 > 消息流”。
    2. 将“消息流名称”设置为 BankTransferRequestInitiator,然后单击“完成”。
  3. 在“消息流”编辑器中,添加并重命名下表中列出的节点。

    节点类型 节点名
    HTTPInput HTTP Input
    JavaCompute TransferRequestForm
    HTTPReply HTTP Reply

  4. 按下表中所述连接节点。

    节点名 终端 连接到此节点
    HTTP Input Out TransferRequestForm
    TransferRequestForm Out HTTP Reply
  5. 定制 HTTP Input 节点:
    1. 右键单击 HTTP Input 节点,然后单击“属性”。
    2. 单击“基本”,将“URL 的路径后缀”设置为 /TransferRequestForm
  6. 定制 TransferRequestForm 节点:
    1. 双击 TransferRequestForm 节点,确保“项目名称”为 BankTransferJava,然后单击“下一步”。
    2. 确保“构建路径上的源文件夹”和“缺省输出文件夹”包含 BankTransferJava,然后单击“下一步”。
    3. 将“”设置为 sca.broker.sample.banktransfer,然后单击“下一步”。
    4. 选择“创建消息类”模板,然后单击“完成”。
    5. 这将自动打开 Java 文件。 如果此文件未打开,请右键单击 TransferRequestForm 节点,然后单击打开 Java
    6. 添加以下导入语句:
      import java.io.BufferedReader;
      import java.io.File;
      import java.io.FileReader;
      import java.io.IOException;
      import java.math.BigDecimal;
          	
    7. 添加以下 Java 代码:
      //Get operating system
      String OS = System.getProperty("os.name").toLowerCase();
      File file = null;
      //Savings balance
      String savingsBalance = null;
      //Current balance if this file also exists i.e. the extended sample
      String currentBalance = null;
      //Get the exception
      String exception = null;
      try {
        //Read balance from appropriate local file system appropriately
        if (OS.indexOf("windows") > -1) {
          file = new File("C:\\tmp\\SavingsAccount.txt");        	
        } else {
          file = new File("/tmp/SavingsAccount.txt");        	
        }
        //Construct the BufferedReader object
       BufferedReader bufferedReader = new BufferedReader(new FileReader(file));            
        //Process the data
        savingsBalance = new BigDecimal(bufferedReader.readLine())
        .setScale(2, 
        BigDecimal.ROUND_HALF_UP).toString();
        try {
          //Read balance from appropriate local file system 
          if (OS.indexOf("windows") > -1) {
      	  file = new File("C:\\tmp\\CurrentAccount.txt");        	
      	} else {
      	  file = new File("/tmp/CurrentAccount.txt");        	
      	}
      	//Construct the BufferedReader object
        BufferedReader bufferedReader = new BufferedReader(new FileReader(file));            
          //Process the data
          currentBalance = new BigDecimal(bufferedReader.readLine())
          .setScale(2, 
          BigDecimal.ROUND_HALF_UP).toString();
        } catch (Exception e) {  
          //Get exception message
          exception = e.getMessage();
        }
      } catch (Exception e) {  
        //Get exception message
        exception = e.getMessage();
      }
              
      //Create web page layout for user input
      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>");			
      //If a savings balance was processed then display it
      if (savingsBalance != null) {
        html.append("<tr><td><td/><h3>You have " + 
        savingsBalance + " in your Savings Account</h3></td>");			
        //If a current balance was processed then display it
        if (currentBalance != null) {
          html.append("<tr><td><td/><h3>You have " + 
          currentBalance + " in your Current Account</h3></td>");
      	//Otherwise warn the user
        } else {
        //Either file does not exist
        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>");											
        //Or file contains corrupt data
        } else {
          html.append("<tr><td><td/><h3><font color=\"#ff0000\">" + file.getName() + " contains corrupt data!</font></h3></td>");												
        }
      }
      //Otherwise seriously warn the user
      } else {
        //Either file does not exist
        if (exception!=null) {
          html.append("<tr><td><td/><h3><font color=\"#ff0000\">Cannot find " + exception + "</font></h3></td>");																	
        //Or file contains corrupt data
        } else {
          html.append("<tr><td><td/><h3><font color=\"#ff0000\">" + file.getName() + " contains corrupt data!</font></h3></td>");												
        }
      }
      html.append("</table></form></BODY></HTML>");
              
      // Set the content type to be 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");					
      // Add the email request form as the message content and publish
      MbElement BLOB = root.createElementAsLastChild(MbBLOB.PARSER_NAME);		
      BLOB.createElementAsFirstChild(MbElement.TYPE_NAME_VALUE, "BLOB", 
      html.toString().getBytes());            
              
  7. 保存并关闭 Java 文件。

您现在可以创建银行转帐请求消息集,请参阅创建银行转帐请求消息集

返回“构建样本”

返回到样本主页