public synchronized void forwardUpload(Connection fromConnection, UploadResource message)
      throws FITTESTException {
    Upload upload = FITTESTSingleton.getObjectFactory().createUpload();
    upload.setFrom(message.getTo());
    upload.setTo(message.getTowards());
    try {
      URI fileURI = new URI(message.getResource());
      File file = null;
      if (fileURI.isAbsolute()) {
        file = new File(fileURI);
      } else {
        file = new File(new URI(_registry.findService(IFileTransferService.class).getBasePath()));
        file = new File(file, message.getResource());
      }
      if (file.exists()) {
        if (file.isDirectory()) {
          ICompressionService compression = _registry.findService(ICompressionService.class);
          upload.setInflate(true);
          file = compression.zipAndGzip(file);
          upload.setChecksum(compression.checksum(file));
        }

        upload.setResourceSize(file.length());
        upload.setResource(
            message.getTo()
                + "/"
                + Validation.formatToValidFileName(message.getFrom())
                + "/"
                + file.getName()); // forward slash because it is a URI
        forward(fromConnection, upload);

        Connection connection =
            _registry.findService(IConnectionService.class).getConnection(message.getTowards());
        _registry
            .findService(IFileTransferService.class)
            .download(connection.getOutputStream(), file.toURI().toString());
      } else {
        throw new FITTESTException(file.getAbsolutePath() + " does not exist");
      }
    } catch (URISyntaxException e) {
      throw new FITTESTException(e.getMessage());
    }
  }
 public synchronized void onReception(Connection connection, RegisterAgent message)
     throws FITTESTException {
   if (message.getType()
       != null) { // if null => possibility of a renew lease after the agent deregistered (or any
                  // other possible cause)
     RegistrationData data =
         getService()
             .registerAgent(
                 connection.getRemoteAddress().split(":")[0],
                 new Integer(connection.getRemoteAddress().split(":")[1]),
                 message.getEnvironment(),
                 message.getType(),
                 message.getDescription(),
                 message.getFrom());
     message.setFrom(data.getEntity().getId());
     message.setTo(data.getIteid());
     RegisterAgentReponse response =
         FITTESTSingleton.getObjectFactory().createRegisterAgentReponse();
     response.setFittestAgentId(data.getEntity().getId());
     response.setFittestIteId(data.getIteid());
     response.setFittestLease(data.getLease());
     reply(connection, message, response);
   }
 }