Criar o Fluxo de Mensagens de Formulário de Pedido de Transferência

Utilize as seguintes instruções para criar o fluxo de mensagens de formulário de pedido de transferência.

  1. Crie um novo projeto do Message Broker:
    1. Clique em Arquivo > Novo > Projeto do Message Broker.
    2. Configure o Nome do Projeto para SCANodesSample, clique em Concluir.
  2. Crie um novo fluxo de mensagens:
    1. Clique com o botão direito do mouse no projeto do Message Broker SCANodesSample, clique em Novo > Fluxo de Mensagens.
    2. Configure Nome do Fluxo de Mensagens para BankTransferRequestInitiator e clique em Concluir.
  3. No editor de Fluxo de Mensagens, inclua e renomeie os nós listados na tabela a seguir.

    Tipo de Nó Nome de Nó
    HTTPInput Entrada HTTP
    JavaCompute TransferRequestForm
    HTTPReply Resposta HTTP

  4. Conecte os nós como descrito na tabela a seguir.

    Nome de Nó Terminal Conectar a esse Nó
    Entrada HTTP Out TransferRequestForm
    TransferRequestForm Out Resposta HTTP
  5. Customize o nó de HTTP de entrada:
    1. Clique com o botão direito do mouse no nó de Entrada HTTP, clique em Propriedades.
    2. Clique em Básico, configure Sufixo do Caminho para URL para /TransferRequestForm
  6. Customize o nó TransferRequestForm:
    1. Dê um clique duplo no nó TransferRequestForm, assegure que o Nome do projeto seja BankTransferJava, e clique em Avançar.
    2. Certifique-se de que as Pastas de origem no caminho de construção e a Pasta de saída padrão contenham BankTransferJava, clique em Avançar.
    3. Configure Pacote para sca.broker.sample.banktransfer e clique em Avançar.
    4. Selecione o modelo Criando classe de mensagem, clique em Concluir.
    5. O arquivo Java é aberto automaticamente. Se ele não abrir, clique com o botão direito do mouse no nó TransferRequestForm, clique em Abrir Java.
    6. Inclua as seguintes instruções de importação:
      import java.io.BufferedReader;
      import java.io.File;
      import java.io.FileReader;
      import java.io.IOException;
      import java.math.BigDecimal;
          	
    7. Inclua o seguinte código 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. Salve e feche o arquivo Java.

Agora você pode criar o conjunto de mensagens de pedido de transferência bancária, consulte Criar o conjunto de mensagens do pedido de transferência bancária.

Voltar para Construir Amostra

Voltar para Home da Amostra