Esempio n. 1
0
  private void loadDirectory(String[] files, String path) throws Exception {
    StringBuilder currentPath = new StringBuilder();
    for (int i = 0; i < files.length; i++) {
      if (!path.endsWith("/")) {
        currentPath.append(path).append("/");
      }
      currentPath.append(files[i]);

      if (SingletonFSInterface.instance().isFile(new URI(currentPath.toString()))) // if it's a file
      {
        try {
          if (!files[i].startsWith(".")) {
            mibLoader.load(files[i]);
          }
        } catch (Exception e) {
          GlobalLogger.instance()
              .getApplicationLogger()
              .error(TextEvent.Topic.PROTOCOL, e, "ERROR : loading the MIBS files");
          if (e instanceof MibLoaderException) {
            ((MibLoaderException) e).getLog().printTo(new PrintStream("../logs/snmpStack.log"));
          }
        }
      } else // if it's a directory, load it and all it's content
      {
        if (!files[i].startsWith(".")) {
          loadDirectory(
              SingletonFSInterface.instance().list(new URI(currentPath.toString())),
              currentPath.toString());
        }
      }
      // reset currentPath
      currentPath.delete(0, currentPath.length());
    }
  }
Esempio n. 2
0
  /** @param args */
  public static void main(String[] args) throws Exception {

    /*
     * Set the FSInterface to LocalFS.
     */
    SingletonFSInterface.setInstance(new LocalFSInterface());

    if (tester == null) {
      tester = Tester.buildInstance();
    }
    logger = GlobalLogger.instance().getApplicationLogger();

    putHashmap();
    getHashmap();
  }
  @Override
  public boolean handle(HybridSocket hybridSocket) {
    if (false == init) return true;

    try {
      GlobalLogger.instance()
          .getApplicationLogger()
          .debug(TextEvent.Topic.PROTOCOL, "ServerSocketHttp waiting for header");

      HttpRequest request = defaultHttpServerConnection.receiveRequestHeader();

      if (request instanceof HttpEntityEnclosingRequest) {
        GlobalLogger.instance()
            .getApplicationLogger()
            .debug(TextEvent.Topic.PROTOCOL, "ServerSocketHttp receiving entity");
        defaultHttpServerConnection.receiveRequestEntity((HttpEntityEnclosingRequest) request);
      }

      Stack stack = StackFactory.getStack(StackFactory.PROTOCOL_HTTP);

      MsgHttp msgRequest = new MsgHttp(stack, request);

      //
      // Set the channel attached to the msg
      //
      msgRequest.setChannel(this.connHttp);

      synchronized (messagesReceived) {
        messagesReceived.addLast(msgRequest);
      }

      //
      // Call back to the generic stack
      //
      stack.receiveMessage(msgRequest);
    } catch (Exception e) {
      if (messagesReceived.isEmpty()) {
        GlobalLogger.instance()
            .getApplicationLogger()
            .warn(
                TextEvent.Topic.PROTOCOL,
                e,
                "Exception in ServerSocketHttp without pending messages");
      } else {
        GlobalLogger.instance()
            .getApplicationLogger()
            .error(
                TextEvent.Topic.PROTOCOL, e, "Exception in ServerSocketHttp with pending messages");
      }

      //
      // try to close itself
      //
      try {
        synchronized (this) {
          StackFactory.getStack(StackFactory.PROTOCOL_HTTP).closeChannel(this.connHttp.getName());
        }
      } catch (Exception ee) {
        GlobalLogger.instance()
            .getApplicationLogger()
            .error(TextEvent.Topic.PROTOCOL, ee, "Error while closing connection ", this.connHttp);
      }

      GlobalLogger.instance()
          .getApplicationLogger()
          .info(TextEvent.Topic.PROTOCOL, "ServerSocketHttp ended");
    }

    return _continue;
  }