銀行振替要求メッセージ・フローの作成

銀行振替要求メッセージ・フローを作成するには、以下の手順に従ってください。

  1. 次のように新規メッセージ・フローを作成します。
    1. 既存のメッセージ・ブローカー・プロジェクト 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 Broker 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 プロジェクトからノードへドラッグします。BankTransferRequest.outsca は、「BankTransferMS」>「ブローカー SCA 定義」>「アウトバウンド (SCA エクスポートを呼び出す)」フォルダーで見つけることができます。
    2. 「WPS でのサービス呼び出しの構成」ウィンドウで、「同期呼び出し」チェック・ボックスをクリアして、「OK」をクリックします。
    3. 基本」をクリックし、「固有 ID」を SCA に設定します。
  7. SCA Asynchronous Response ノードを以下のようにカスタマイズします。
    1. BankTransferRequest.outsca を BankTransferMS プロジェクトからノードへドラッグし、「固有 ID」を 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 Broker 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 Broker 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());
              

サンプルの作成に戻る

サンプルのホームに戻る