创建银行转帐请求消息流

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

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

    节点类型 节点名
    HTTPInput HTTP Input
    JavaCompute SetupTransferRequest
    SCAAsyncRequest SCA Asynchronous Request
    SCAAsyncResponse SCA Asynchronous Response
    JavaCompute SetupTransferReply
    JavaCompute SetupTransferFailedReply
    HTTPReply HTTP Reply

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

    节点名 终端 连接到此节点
    HTTP Input Out SetupTransferRequest
    SetupTransferRequest Failure SetupTransferFailedReply
    SetupTransferFailedReply Out HTTP Reply
    SetupTransferRequest Out SCA Asynchronous Request
    SCA Asynchronous Response Out SetupTransferReply
    SetupTransferReply Out HTTP Reply
  4. 定制 HTTP Input 节点:
    1. 右键单击 HTTP Input 节点,然后单击“属性”。
    2. 单击“基本”,将“URL 的路径后缀”设置为 /TransferRequestSample
    3. 单击“输入消息解析”。 对于“消息域”属性,请从列表中选择 MIME
  5. 定制 SetupTransferRequest 节点:
    1. 双击 SetupTransferRequest 节点,确保“项目名称”为 SCANodesSampleJava,然后单击“下一步”。
    2. 确保“构建路径上的源文件夹”和“缺省输出文件夹”包含 SCANodesSampleJava,然后单击“下一步”。
    3. 将“”设置为 sca.broker.sample.banktransfer,然后单击“下一步”。
    4. 选择“创建消息类”模板,然后单击“完成”。
    5. 右键单击 SetupTransferRequest 节点,然后单击“打开 Java”。
    6. 添加以下导入语句:
      import java.math.BigDecimal;
      		
    7. 添加以下 Java 代码:
      //Get the incoming MIME parts
      MbElement inRoot = inMessage.getRootElement();
      MbElement inMime = inRoot.getFirstElementByPath("MIME");
      MbElement inParts = inMime.getFirstElementByPath("Parts");
      //Traverse the local environment for property overrides
      MbElement outRoot = outMessage.getRootElement();			
      MbMessage locEnv = inAssembly.getLocalEnvironment();
      MbMessage newLocEnv = new MbMessage(locEnv);
      MbElement destination = newLocEnv.getRootElement()
      .getFirstElementByPath("Destination");
      MbElement http = destination.getFirstElementByPath("HTTP");
      MbElement requestIdentifier = http.getFirstElementByPath
      ("RequestIdentifier");
      MbElement soap = destination.createElementAsLastChild
      (MbElement.TYPE_NAME, "SCA", null);
      MbElement request = soap.createElementAsLastChild
      (MbElement.TYPE_NAME, "Request", null);
      request.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, 
      "UserContext", requestIdentifier.getValue());
              
      //Operation
      String operation = null;
      //Transfer amount
      String amount = null;
      //Get the first part
      MbElement part = inParts.getFirstChild();			
      //Iterate through all of the parts dynamically setting SCA overrides
      while (part != null) {
        //Strip out the property 
        String content = (String)part.getFirstChild().getValue();
        int start = content.indexOf("\"") + 1;
        int end = content.indexOf("\"", start);
        String property = content.substring(start, end);
        //Get the corresponding property data
        MbElement data = part.getLastChild().getFirstElementByPath("BLOB");
        //If there is a data part then setup the relevant property overrides
        if (data != null) {
          //Obtain the byte data
          byte[] blobData = (byte[])data.getFirstElementByPath
          ("BLOB").getValue(); 
          //Convert to a string
          String dataString = new String(blobData);
          //Set LE properties
          if (property.equals("Operation")) { 
            request.createElementAsLastChild
            (MbElement.TYPE_NAME_VALUE, property, dataString);
            operation = dataString;
          } 
          else if (property.equals("Amount")) {
            amount = dataString;						
            try {
              BigDecimal bigDecimal = new BigDecimal(amount);
              if (bigDecimal.scale() > 2 || bigDecimal.scale() < 0) {
                throw new Exception ("Invalid currency format specified!");
              }
            } catch (NumberFormatException nfe) {
              throw new Exception ("Invalid amount specified!");
            }
          }
        } else {
          throw new Exception("No amount specified!");				
        }
        //Get the next part
        part = part.getNextSibling();
      }
              
      //Delete the HTTPInputHeader since we don't need this 
      in our MQ message request
      MbElement httpInputHeader = outRoot.getFirstElementByPath
      ("HTTPInputHeader");
      httpInputHeader.detach();			
      //Create the integration node XMLNSC Parser element
      MbElement outParser = outRoot.createElementAsLastChild
      (MbXMLNSC.PARSER_NAME);
      MbElement service = outParser.createElementAsLastChild
      (MbElement.TYPE_NAME, 
      operation, null);
      service.setNamespace("http://SavingsAccount/SavingsAccountInterface");
      MbElement transferin = service.createElementAsLastChild
      (MbElement.TYPE_NAME, 
      "transferin", null);
      transferin.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, 
      "amount", amount);			
      //Create the new assembly with the new property overrides
      MbMessageAssembly outAssembly = new MbMessageAssembly(
      					inAssembly,
      					newLocEnv,
      					inAssembly.getExceptionList(),
      					outMessage);
              
    8. 除去以下 Java 代码,因为该代码与您刚创建的 MbMessageAssembly 冲突:
      MbMessageAssembly outAssembly = new MbMessageAssembly
      (inAssembly, outMessage);
         		
  6. 定制 SCA Asynchronous Request 节点:
    1. BankTransferRequest.outsca 从 BankTransferMS 项目中拖动到该节点上。您可以在“BankTransferMS > 集成 SCA 定义 > 出站(调用 SCA 导出)”文件夹中找到 BankTransferRequest.outsca
    2. 在“配置 WPS 上的服务调用”窗口中,取消选中“同步调用”复选框,然后单击“确定”。
    3. 单击“基本”,将“唯一标识”设置为 SCA
  7. 定制 SCA Asynchronous Response 节点:
    1. BankTransferRequest.outsca 从 BankTransferMS 项目中拖动到该节点上 ,然后将“唯一标识”设置为 SCA
  8. 定制 SetupTransferReply 节点:
    1. 双击 SetupTransferReply 节点,确保“项目名称”为 SCANodesSampleJava,然后单击“下一步”。
    2. 确保“构建路径上的源文件夹”和“缺省输出文件夹”包含 SCANodesSampleJava,然后单击“下一步”。
    3. 将“”设置为 sca.broker.sample.banktransfer,然后单击“下一步”。
    4. 选择“创建消息类”模板,然后单击“完成”。
    5. 右键单击 SetupTransferReply 节点,然后单击“打开 Java”。
    6. 添加以下导入语句:
      import java.math.BigDecimal;
      		
    7. 添加以下 Java 代码:
      //Traverse the local environment for property overrides
      MbMessage locEnv = inAssembly.getLocalEnvironment();
      MbMessage newLocEnv = new MbMessage(locEnv);
      MbElement locEnvRoot = newLocEnv.getRootElement();
      MbElement soap = locEnvRoot.getFirstElementByPath("SCA");
      MbElement response = soap.getFirstElementByPath("Response");
      MbElement userContext = response.getFirstElementByPath
      ("UserContext");
      MbElement destination = locEnvRoot.getFirstElementByPath
      ("Destination");
      MbElement http = destination.createElementAsLastChild
      (MbElement.TYPE_NAME, "HTTP", null);
      http.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, 
      "RequestIdentifier", userContext.getValue());
      //Obtain response message values
      MbElement inRoot = inMessage.getRootElement();			
      MbElement XMLNSC = inRoot.getFirstElementByPath("XMLNSC");
      MbElement transferResponse = XMLNSC.getLastChild();
      MbElement transferOut = transferResponse.getFirstElementByPath
      ("transferout");
      String amount = new BigDecimal(transferOut.getFirstElementByPath
      ("amount").getValue().toString())
      .setScale(2, BigDecimal.ROUND_HALF_UP).toString();
      String oldBalance = new BigDecimal(transferOut.getFirstElementByPath
      ("oldbalance").getValue().toString())
      .setScale(2, BigDecimal.ROUND_HALF_UP).toString();
      String newBalance = new BigDecimal(transferOut.getFirstElementByPath
      ("newbalance").getValue().toString())
      .setScale(2, BigDecimal.ROUND_HALF_UP).toString();
      String accept = transferOut.getFirstElementByPath
      ("accept").getValue().toString();
              
      //Construct confirmation message
      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='/TransferRequestForm' 
      method=post>");
      if (accept.equals("yes")) {
      	html.append("<h1>Your transfer of " + amount +" 
      	has been successful!</h1>");
      	html.append("<h3>Your old savings balance was " 
      	+ oldBalance + "</h3>");				
      	html.append("<h3>Your new savings balance is " 
      	+ newBalance + "</h3>");				
      } else {
      	html.append("<h1><font color=\"#ff0000\">
      	Your transfer of " + amount + " has been unsuccessful 
      	due to insufficient funds!
      	</font></h1>");				
      	html.append("<h3>Your savings balance 
      	remains unchanged at " + 
      	newBalance + "</h3>");				
      }
      html.append("<tr><td><input type='submit' name='OK' 
      value='OK'></td></tr>");
      html.append("</form></BODY></HTML>");
              
      //Set the content type to be html so that 
      it may be viewed by a browser
      MbElement outRoot = outMessage.getRootElement();			
      MbElement outProperties = outRoot.getFirstElementByPath
      ("Properties");	
      MbElement contentType = outProperties.getFirstElementByPath
      ("ContentType");			
      contentType.setValue("text/html");	
      //Delete the MQMD header since we don't 
      need this in our HTTP reply
      MbElement mqmd = outRoot.getFirstElementByPath("MQMD");
      mqmd.detach();			
      //Create the integration node Blob Parser element
      MbElement outParser = outRoot.createElementAsLastChild
      (MbBLOB.PARSER_NAME);
      //Create the BLOB element in the Blob parser domain 
      with the required text
      outParser.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, 
      "BLOB", html.toString().getBytes());
      //Create the new assembly with the new property overrides
      MbMessageAssembly outAssembly = new MbMessageAssembly(
      					inAssembly,
      					newLocEnv,
      					inAssembly.getExceptionList(),
      					outMessage);
              
    8. 除去以下 Java 代码,因为该代码与您刚创建的 MbMessageAssembly 冲突:
      MbMessageAssembly outAssembly = new MbMessageAssembly
      (inAssembly, outMessage);
         		
  9. 定制 SetupTransferFailedReply 节点:
    1. 双击 SetupTransferFailedReply 节点,确保“项目名称”为 SCANodesSampleJava,然后单击“下一步”。
    2. 确保“构建路径上的源文件夹”和“缺省输出文件夹”包含 SCANodesSampleJava,然后单击“下一步”。
    3. 将“”设置为 sca.broker.sample.banktransfer,然后单击“下一步”。
    4. 选择“修改消息类”模板,然后单击“完成”。
    5. 右键单击 SetupTransferFailedReply 节点,然后单击“打开 Java”。
    6. 添加以下 Java 代码:
      //Set the content type to be html so that it can be viewed by a browser
      MbElement outRoot = outMessage.getRootElement();
      MbElement outProperties = outRoot.getFirstElementByPath
      ("Properties");	
      MbElement contentType = outProperties.getFirstElementByPath
      ("ContentType");			
      contentType.setValue("text/html");	
      //Clear out any messages 
      outRoot.getLastChild().detach();
              
      //Get the exception reported
      MbElement exception = inAssembly.getExceptionList()
      .getRootElement().getFirstElementByPath
      ("RecoverableException").getFirstElementByPath("UserException")
      .getFirstElementByPath("UserException");
      //Create a HTML response
      StringBuffer buffer = new StringBuffer();			
      String head = "<html><body text=\"#ff0000\">
      <form action=\"/TransferRequestForm\" 
      method=post>";			
      buffer.append(head);
      //Iterate through the exception stacktrace and 
      add the reason text to the message response
      MbElement insert = exception.getFirstElementByPath("Insert");
      for (int i=0;i<5;i++) {
        insert = insert.getNextSibling();
      }
      String text = (String)insert.getFirstElementByPath
      ("Text").getValue();
      if (text.length() > 0) {
        buffer.append("<h1>");					
        buffer.append(text);
        buffer.append("</h1>");					
      }
      //Complete the HTML body
      String tail = "<br><input type=\"submit\" 
      name=\"OK\" value=\"OK\">
      </form></body></html>";
      buffer.append(tail);
              
      //Create the integration node Blob Parser element
      MbElement outParser = outRoot.createElementAsLastChild
      (MbBLOB.PARSER_NAME);
      //Create the BLOB element in the Blob parser 
      domain with the required text
      outParser.createElementAsLastChild
      (MbElement.TYPE_NAME_VALUE, "BLOB", 
      buffer.toString().getBytes());
              

返回“构建样本”

返回到样本主页