Package fpdu

Examples of fpdu.FPDU


   * *Date* Received: FPDU RCONNECT   from Bob. Connection refused.
   */
  public void testLogRemoteNominalRConnect() {
    FPDUParameter param = new FPDUParameter("Bob", "Alice");

    FPDU fpdu = new FPDU(param);
    fpdu.setType(EnumFPDU.RCONNECT);
   
    String result = PeSITLog.logRemote(fpdu);
    assertThat(result, containsString("Received: " +
        "FPDU RCONNECT   from Bob. Connection refused."));
  }
View Full Code Here


   * *Date* Received: FPDU READ   from Bob. File reading request from Bob.
   */
  public void testLogRemoteNominalRead() {
    FPDUParameter param = new FPDUParameter("Bob", "Alice");

    FPDU fpdu = new FPDU(param);
    fpdu.setType(EnumFPDU.READ);
   
    String result = PeSITLog.logRemote(fpdu);
    assertThat(result, containsString("Received: " +
        "FPDU READ   from Bob. File reading request from Bob."));
  }
View Full Code Here

  /**
   * Test of logRemote with a null FPDU
   * Expected return: Error null FPDU
   */
  public void testLogRemoteNullFPDU() {
    FPDU fpdu = null;
   
    String result = PeSITLog.logRemote(fpdu);
    assertEquals("failure - should be equal", "Error null FPDU", result);
  }
View Full Code Here


public class ProcessHTTP2FPDU {

  public FPDU process(String message) {
    FPDU fpdu = null;
    System.out.println(message);
    Date date = new Date();
    String type;
    String from = "Bob";
    String to = "Alice";
   
    StringTokenizer tokenizer;
    String token;
   
    FPDUParameter parameter;
   
    if (!message.equals("/favicon.ico")) {
      tokenizer = new StringTokenizer(message, "/?& =");
      // If there is at least one token
      if (tokenizer.hasMoreTokens()) {
        // The first token is the type of FPDU
        type = tokenizer.nextToken();
       
        // While there are token, we get the parameters
        while (tokenizer.hasMoreTokens()) {
          token = tokenizer.nextToken();
          if (token.equals("type")) {
            if(tokenizer.hasMoreTokens()) {
              type = tokenizer.nextToken();
            } else {
              // No value for parameter
              System.out.println("Error in the HTTP request, " +
                  "no value for type");
            }
          } else if(token.equals("from")) {
            if(tokenizer.hasMoreTokens()) {
              from = tokenizer.nextToken();
            } else {
              // No value for parameter
              System.out.println("Error in the HTTP request, " +
                  "no value for from");
            }
          } else if(token.equals("to")) {
            if(tokenizer.hasMoreTokens()) {
              to = tokenizer.nextToken();
            } else {
              // No value for parameter
              System.out.println("Error in the HTTP request, " +
                  "no value for to");
            }
          }
        }
        parameter = new FPDUParameter(from, to);
        parameter.setDate(date);
        fpdu = new FPDU(getRightType(type), parameter);
      }
    } else {
      fpdu = new FPDU("Ceci n'est pas un FPDU");
    }
    return fpdu;
  }
View Full Code Here

   * @param remoteBank
   * @return
   * @throws Exception
   */
  public OutputConnectionWS disconnect (String bankName) throws Exception {
    FPDU fpduResponse = null;
    Date date;
    FPDUParameter parameter;
    Connection connection;
    // The local bank wants to close the connection
    connection = ConnectionPool.getOutConnections()
      .get(bankName);
    System.out.println("debug remote bank name : "
        + bankName);
   
    if (connection == null) {
      System.out.println("CONNECTION WS Error: " +
          "Cannot release null connection");
      throw new ConnectionException("CONNECTION WS: Error release");
    }
    if (connection.getState() != EnumState.connected) {
      System.out.println("CONNECTION WS Error: " +
          "Cannot release connection (connection " +
          "was not open in the first place)");
      // Raise exception
      throw new WrongFPDUException("CONNECTION WS Error: " +
          "Cannot release connection (connection " +
          "was not open in the first place)");
    }
    connection.setState(EnumState.waitfor_relconf);
    // Create FPDU relconf
    parameter = new FPDUParameter(ConnectionPool.getLocalIdentity(),
        bankName);
    date = new Date();
    parameter.setDate(date);
    parameter.setLocalConnectionId(connection.getIdConnection());
    parameter.setRemoteConnectionId(connection.getRemoteId());
    fpduResponse = new FPDU(EnumFPDU.RELEASE, parameter);
   
    // If there is a message, we log it
    if (fpduResponse != null) {
      PeSITLog.logLocal(fpduResponse);
    }
View Full Code Here

   * @param bank
   * @return
   * @throws Exception
   */
  public OutputConnectionWS connect (String bank) throws Exception {
    FPDU fpdu = null;
    Connection connection;
    System.out.println("REMOTE BANK: " + bank);
   
    System.out.println("CONNECTION WS: " +
        "Local bank asked for connection");
    connection = ConnectionPool.getConnection(bank);
    connection.setState(EnumState.waitfor_acconnect);
    Date date = new Date();
    // Send the CONNECT FPDU
    FPDUParameter parameter = new FPDUParameter("Local", bank);
    // Set date
    parameter.setDate(date);
    // Set local identifier
    parameter.setLocalConnectionId(connection.getIdConnection());
    fpdu = new FPDU(EnumFPDU.CONNECT, parameter);
    System.out.print("CONNECTION WS: Print FPDU -> ");
    System.out.println(fpdu)
    // If there is a message, we log it
    if (fpdu != null) {
      PeSITLog.logLocal(fpdu);
View Full Code Here

   */
  @WebMethod
  public OutputConnectionWS FPDUReception (FPDU fpdu)
    throws ConnectionException, WrongFPDUException {
    Connection connection;
    FPDU fpduResponse = null;
    FPDUParameter parameter;
    String remoteBank = fpdu.getParameter().getSender();
    Date date;
    Boolean respBool = false;
   
    // First we log the received FPDU
    PeSITLog.logRemote(fpdu);
   
    switch (fpdu.getType()) {
      case CONNECT:
        System.out.println(remoteBank +
            " asked for connection");
        connection = ConnectionPool.getConnection(
            remoteBank);
        // If a bank is already using the service
        if (connection == null) {
          System.out.println("CONNECTION WS Error: "
              + ConnectionPool.getLocalIdentity() +
              " already asked for a connection");
          // Raise exception
          throw new ConnectionException("CONNECTION WS " +
              "Error: "
              + ConnectionPool.getLocalIdentity() +
              " already asked for a connection");
        } else if (connection.getState() != EnumState.idle) {
          System.out.println("Error: "
              + remoteBank +
              " cannot ask for connection as a connection" +
              " already exists");
          throw new ConnectionException("CONNECTION WS " +
              "Error: "
              + remoteBank +
              " cannot ask for connection as a connection" +
              " already exists");
        }
        connection.setState(EnumState.connected);
        // Set connection ids
        connection.setRemoteId(
            fpdu.getParameter().getLocalConnectionId());
        // If the new connection is open, send aconnect
        parameter = new FPDUParameter("Local",
            fpdu.getParameter().getSender());
        date = new Date();
        parameter.setDate(date);
        parameter.setLocalConnectionId(connection.getIdConnection());
        parameter.setRemoteConnectionId(connection.getRemoteId());
        fpduResponse = new FPDU(EnumFPDU.ACONNECT, parameter);
        respBool = true;
        break;
      case ACONNECT:
        connection = ConnectionPool.getOutConnections()
          .get(remoteBank);
        if (connection == null ||
          connection.getState() != EnumState.waitfor_acconnect) {   
          System.out.println("CONNECTION WS Error: " +
              "Cannot ack connect  ( " +
              "did not send connect in the first place)");
          // Raise exception
          throw new WrongFPDUException("CONNECTION WS Error: " +
              "Cannot ack connect  ( " +
              "did not receive connect in the first place)");
        }
        connection.setState(EnumState.connected);
        // A transfer is now ready to start
        break;
      case RCONNECT:
        connection = ConnectionPool.getOutConnections()
          .get(remoteBank);
        if (connection == null ||
          connection.getState() != EnumState.waitfor_acconnect) {   
          System.out.println("CONNECTION WS Error: " +
              "Cannot refuse connect  ( " +
              "did not receive connect in the first place)");
          // Raise exception
          throw new WrongFPDUException("CONNECTION WS Error: " +
              "Cannot refuse connect  ( " +
              "did not receive connect in the first place)");
        }
        connection.setState(EnumState.connection_refused);
        // A transfer is now ready to start
        break;
      case RELEASE:
        // Here the remote bank wants to close the connection
       
        // We have to check if the remote bank is the actual seeker
        // of the connection , otherwise it cannot ask for a release
       
        connection = ConnectionPool.getOutConnections()
          .get(remoteBank);
        if (connection == null ||
          connection.getState() != EnumState.connected) {
          System.out.println("CONNECTION WS Error: " +
              "Cannot release connection (connection " +
              "was not open in the first place)");
          // Raise exception
          throw new WrongFPDUException("CONNECTION WS Error: " +
              "Cannot release connection (connection " +
              "was not open in the first place)");
          // TODO: handle lost of release packets
        }
        connection.setState(EnumState.idle);
        // Release connection
        ConnectionPool.returnConnection(remoteBank, connection);

        // Create FPDU relconf
        parameter = new FPDUParameter("Local", remoteBank);
        date = new Date();
        parameter.setDate(date);
        parameter.setLocalConnectionId(connection.getIdConnection());
        parameter.setRemoteConnectionId(connection.getRemoteId());
        fpduResponse = new FPDU(EnumFPDU.RELCONF, parameter);
        respBool = true;
        break;
      case RELCONF:
        // The connection is closed
        connection = ConnectionPool.getOutConnections()
View Full Code Here

        outputToSend = currentConnectionWS.messageParser("connect_" + bankName);
      } catch (Exception e) {
        e.printStackTrace();
        return false;
      }
      FPDU fpduToSend = outputToSend.getFpdu();
         
          // Send FPDU to the interserver
      if (!sendFPDU(fpduToSend)) {
        // If sendFPDU fail then return false
        return false;
View Full Code Here

      e.printStackTrace();
      System.out.println("exception 1");
      return false;
    }
   
    FPDU fpduToSend = outputToSend.getFpdu();
       
    // Send FPDU to the interserver
    if (!sendFPDU(fpduToSend)) {
      // If sendFPDU fail then return false
      return false;
View Full Code Here

      // TODO : raise exception
    }
   
    // If fpdu need to be sent
    if (outputToSend.isHandleFPDU()) {
      FPDU fpduToSend = outputToSend.getFpdu();
      // Send FPDU to the interserver
      if (!sendFPDU(fpduToSend)) {
        // If sendFPDU fail then return false
        // : TODO : raise Exception or return false
      }
View Full Code Here

TOP

Related Classes of fpdu.FPDU

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.