Exemple #1
0
 /** Generates the code for the checker. */
 protected void addChecker(
     Context ctxt,
     MibNode node,
     String description,
     String syntax,
     String var,
     StringBuffer buff) {
   buff.append(
       Def.TAB
           + "/**\n"
           + Def.TAB
           + " * "
           + MessageHandler.getMessage("generate.mbean.comment.checker", var)
           + "\n"
           + Def.TAB
           + " */\n");
   buff.append(
       Def.TAB + Def.PUBLIC + Def.VOID + Def.CHECK + var + "(" + syntax + "x) " + accessThrows);
   buff.append(
       Def.TAB2
           + "//\n"
           + Def.TAB2
           + "// "
           + MessageHandler.getMessage("generate.mbean.comment.checker.policy")
           + "\n"
           + Def.TAB2
           + "//\n");
   buff.append(Def.TAB + Def.RBRACE + "\n");
 }
Exemple #2
0
 private void addRowStatusSetter(
     Context ctxt,
     MibNode node,
     String description,
     String syntax,
     String var,
     StringBuffer buff) {
   buff.append(
       Def.TAB
           + "/**\n"
           + Def.TAB
           + " * "
           + MessageHandler.getMessage("generate.mbean.comment.setter", var)
           + "\n"
           + Def.TAB
           + " * "
           + MessageHandler.getMessage("generate.mbean.comment." + "setter.rs.nochecker")
           + "\n"
           + Def.TAB
           + " * "
           + MessageHandler.getMessage("generate.mbean.comment." + "checker.rs.override")
           + "\n"
           + Def.TAB
           + " */\n");
   buff.append(
       Def.TAB + Def.PUBLIC + Def.VOID + Def.SET + var + "(" + syntax + "x) " + accessThrows);
   buff.append(Def.TAB2 + var + " = x" + Def.SEMICOLON);
   buff.append(Def.TAB + Def.RBRACE + "\n");
 }
Exemple #3
0
  protected void buildConstructorHeader() throws IOException {
    constructor1.append(
        "\n"
            + Def.TAB
            + "/**\n"
            + Def.TAB
            + " * "
            + MessageHandler.getMessage("generate.mbean.comment.constr", symboleName)
            + "\n"
            + Def.TAB
            + " * "
            + MessageHandler.getMessage("generate.mbean.comment.noRegistration")
            + "\n"
            + Def.TAB
            + " */\n");
    constructor1.append(Def.TAB + Def.PUBLIC + symboleName + "(SnmpMib myMib)" + Def.LBRACE);

    constructor2.append(
        "\n"
            + Def.TAB
            + "/**\n"
            + Def.TAB
            + " * "
            + MessageHandler.getMessage("generate.mbean.comment.constr", symboleName)
            + "\n"
            + Def.TAB
            + " * "
            + MessageHandler.getMessage("generate.mbean.comment.registration")
            + "\n"
            + Def.TAB
            + " */\n");
    constructor2.append(
        Def.TAB + Def.PUBLIC + symboleName + "(SnmpMib myMib, MBeanServer server)" + Def.LBRACE);
  }
    @Override
    public void close() throws IOException {
      bout.close();
      output.close();

      Iterator<MessageHandler> it = config.getMessagerHandlers();

      while (it.hasNext()) {
        MessageHandler handler = it.next();
        handler.handleRequest(url, bout.toByteArray());
      }
    }
Exemple #5
0
  public void init() throws ServletException {
    ServletContext ctx = getServletContext();
    remoteHost =
        ctx.getInitParameter("RMI_SERVER"); // Reads the value from the <context-param> in web.xml

    mh = new MessageHandler(); // Instantiate message handler on service start
    vmh =
        new VigenereRequestManager(
            mh.getQueue(),
            mh.getMap(),
            remoteHost); // Instansiate Request manager at service start with references to same
                         // queue and map as message handler
    executorService.execute(vmh); // Run the Request service daemon
  }
  @Override
  public InputStream getContent() throws IOException {
    InputStream in;

    try {
      successful = true;
      in = connection.getInputStream();
    } catch (IOException e) {
      successful = false;
      in = connection.getErrorStream();
      if (in == null) {
        throw e;
      }
    }

    String encoding = connection.getHeaderField("Content-Encoding");

    if (config.getMaxResponseSize() > 0) {
      in = new LimitingInputStream(config.getMaxResponseSize(), in);
    }

    if ("gzip".equals(encoding)) {
      in = new GZIPInputStream(in);
    }

    if (config.hasMessageHandlers() || config.isTraceMessage()) {
      byte[] bytes = FileUtil.toBytes(in);
      in = new ByteArrayInputStream(bytes);

      if (config.hasMessageHandlers()) {
        Iterator<MessageHandler> it = config.getMessagerHandlers();
        while (it.hasNext()) {
          MessageHandler handler = it.next();
          if (handler instanceof MessageHandlerWithHeaders) {
            ((MessageHandlerWithHeaders) handler)
                .handleResponse(url, bytes, connection.getHeaderFields());
          } else {
            handler.handleResponse(url, bytes);
          }
        }
      }

      if (config.isTraceMessage()) {
        new TeeInputStream(config, bytes);
      }
    }

    return in;
  }
Exemple #7
0
  public MbeanGenerator(ResourceManager mgr, MibNode aGroup, Context ctxt) throws IOException {
    super(mgr, aGroup, ctxt);

    gentype = ctxt.gentype;

    // Specify oid of the current bean ...
    //
    oid = node.getComputedOid();

    // Try to find a symbol to associate to the group
    //
    varName = node.getSymbolName();
    if (varName == null) varName = getClassName(node.getComputedOid());
    symboleName = getNodeSymbolName(node);

    Trace.info(MessageHandler.getMessage("generate.info.var", varName));

    // Open the file which will represent the M-bean.
    //
    out = openFile(symboleName + Def.JAVA);

    // Write generic header ...
    //
    writeHeader();

    // write our own header ...
    //
    writeClassDeclaration();

    // write the beginning of the constructor
    //
    buildConstructorHeader();
  }
Exemple #8
0
 private void addRowStatusChecker(
     Context ctxt,
     MibNode node,
     String description,
     String syntax,
     String var,
     StringBuffer buff) {
   buff.append(
       Def.TAB
           + "/**\n"
           + Def.TAB
           + " * "
           + MessageHandler.getMessage("generate.mbean.comment.checker", var)
           + "\n"
           + Def.TAB
           + " * "
           + MessageHandler.getMessage("generate.mbean.comment.checker.rs.deprecated")
           + "\n"
           + Def.TAB
           + " * "
           + MessageHandler.getMessage("generate.mbean.comment.checker.rs.override")
           + "\n"
           + Def.TAB
           + " */\n");
   buff.append(
       Def.TAB
           + Def.PUBLIC
           + Def.VOID
           + Def.CHECK
           + var
           + "("
           + syntax
           + "x) "
           + BeanGenerator.accessThrows);
   buff.append(
       Def.TAB2
           + "//\n"
           + Def.TAB2
           + "// "
           + MessageHandler.getMessage("generate.mbean.comment.checker.rs.policy")
           + "\n"
           + Def.TAB2
           + "//\n");
   buff.append(Def.TAB + Def.RBRACE + "\n");
 }
Exemple #9
0
  protected void addCacheVar(MibNode node, String syntax, long fixed, String init, String var)
      throws IOException {
    // Put some comments ...
    //
    var_list.append(
        Def.TAB
            + "/**\n"
            + Def.TAB
            + " * "
            + MessageHandler.getMessage("generate.mbean.comment.varUse", var)
            + "\n"
            + Def.TAB
            + " * "
            + MessageHandler.getMessage("generate.mbean.comment.varOid", node.getOid())
            + "\n"
            + Def.TAB);
    if (fixed != -1) {
      var_list.append(
          " * "
              + MessageHandler.getMessage("generate.mbean.comment.varFix", String.valueOf(fixed))
              + "\n"
              + Def.TAB);
    }

    // Shall we put the description in the generated code ?
    // if yes call the formatDescription method ...
    // The answer is yes if requested !
    if (mib.isDescriptionOn()) {
      // Get the object definition associated to the node
      //
      ASTObjectTypeDefinition definition = node.getObjectType();
      String description = definition.getDefinition().getDescription();
      var_list.append(formatDescription(description));
    }
    var_list.append(" */\n");

    if (init == null) init = "";

    // Declare the variable
    //
    var_list.append(Def.TAB + Def.PROTECTED + syntax + var + init + Def.SEMICOLON + "\n");
  }
Exemple #10
0
 protected void writeClassDeclaration() throws IOException {
   // Add some comments
   //
   write(
       "/**\n"
           + " * "
           + MessageHandler.getMessage("generate.mbean.comment.desc", varName)
           + "\n"
           + " * "
           + MessageHandler.getMessage("generate.mbean.comment.oid", oid)
           + "\n"
           + " */\n");
   write(
       Def.PUBLIC
           + Def.CLASS
           + symboleName
           + Def.IMPLEMENT
           + symboleName
           + Def.MBEANSUFFIX
           + ", "
           + Def.SERIALIZABLE
           + Def.LBRACE
           + "\n");
 }
  private void outputMessage(String msg, int msgType) {
    if (isInterrupted()) {
      return;
    }

    if (m_msgHandler != null) {
      m_msgHandler.outputMessage(msg + "\n", msgType);
    } else {
      try {
        m_outWriter.write(msg);
        m_outWriter.newLine();
      } catch (Exception ex) {
        System.err.println(msg);
      }
    }
  }
 public void run() {
   try {
     setConfig(ConfigManager.getCurrentConfig());
     if (m_outWriter == null && m_msgHandler == null) {
       useLocalWriter = true;
     } else {
       useLocalWriter = false;
     }
     if (useLocalWriter) {
       openOutputFile();
     }
     checkRules();
     if (useLocalWriter) {
       closeOutputFile();
     }
   } finally {
     if (m_msgHandler != null) {
       m_msgHandler.close();
     }
   }
 }
Exemple #13
0
  /** Generates the code for the getter. */
  protected void addGetter(
      Context ctxt,
      MibNode node,
      String description,
      String syntax,
      String var,
      StringBuffer buff) {

    buff.append(
        Def.TAB
            + "/**\n"
            + Def.TAB
            + " * "
            + MessageHandler.getMessage("generate.mbean.comment.getter", var)
            + "\n"
            + Def.TAB
            + " */\n");
    buff.append(Def.TAB + Def.PUBLIC + syntax + Def.GET + var + "() " + accessThrows);
    buff.append(Def.TAB2 + Def.RETURN + var + Def.SEMICOLON);
    buff.append(Def.TAB + Def.RBRACE + "\n");
  }
Exemple #14
0
  /** Process table. */
  protected void handleTable(MibNode node) throws IOException {
    // create a table generator
    //
    TableBeanGenerator table = new TableBeanGenerator(manager, node, context);

    // The meta table generator is now created by the
    // MetaBeanGenerator, which is more logic.
    //
    // // MetaTableGenerator metatable=
    // //   new MetaTableGenerator(manager, node, context);

    // create a table generator interface
    //
    // TableBeanIfGenerator tableIf= new TableBeanIfGenerator(manager, packageName, prefix,
    // targetDir, node, mib);

    // Get the entry name
    //
    String entry = table.getEntryName();

    // Get the table name
    //
    String tableName = table.getTableClassName();

    // Name of the symbol
    //
    String variable = table.getSymbolName();

    // Add cache variable for storing table
    //
    addCacheVar(node, tableName, (long) -1, null, variable);

    // Initialize the table in the constructor
    //
    constructor1.append(
        Def.TAB2 + variable + " = " + Def.NEW + tableName + "(myMib)" + Def.SEMICOLON);
    constructor2.append(
        Def.TAB2 + variable + " = " + Def.NEW + tableName + "(myMib, server)" + Def.SEMICOLON);

    // Add access method on the table
    //
    accessors.append(
        Def.TAB
            + "/**\n"
            + Def.TAB
            + " * "
            + MessageHandler.getMessage("generate.mbean.comment.table.access", variable)
            + "\n"
            + Def.TAB
            + " */\n");
    accessors.append(
        Def.TAB + Def.PUBLIC + tableName + Def.ACCESS + variable + "() " + accessThrows);
    accessors.append(
        Def.TAB2 + Def.RETURN + variable + Def.SEMICOLON + Def.TAB + Def.RBRACE + "\n");

    // Show the table as an indexed property...
    //
    accessors.append(
        Def.TAB
            + "/**\n"
            + Def.TAB
            + " * "
            + MessageHandler.getMessage("generate.mbean.comment.table.entry", variable)
            + "\n"
            + Def.TAB
            + " */\n");
    accessors.append(
        Def.TAB
            + Def.PUBLIC
            + entry
            + Def.MBEANSUFFIX
            + "[] "
            + Def.GET
            + variable
            + "() "
            + accessThrows);
    accessors.append(
        Def.TAB2
            + Def.RETURN
            + variable
            + ".getEntries()"
            + Def.SEMICOLON
            + Def.TAB
            + Def.RBRACE
            + "\n");
  }
Exemple #15
0
  // Specify the version of mibgen used for generating the code
  //
  protected void writeVersion() throws IOException {
    String msgid = "generate.version";

    write("\n//\n// " + MessageHandler.getMessage(msgid, mib.getModuleName()) + "\n//\n\n");
  }
Exemple #16
0
  public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    resp.setContentType("text/html");
    PrintWriter out = resp.getWriter();

    int maxKeyLength = Integer.parseInt(req.getParameter("frmMaxKeyLength"));
    String cypherText = req.getParameter("frmCypherText");
    String taskNumber = req.getParameter("frmStatus");
    String plainText = null; // Holder for returned test

    out.print("<html><head><title>Distributed Systems Assignment</title>");
    out.print("</head>");
    out.print("<body>");

    if (taskNumber == null) {
      jobNumber++;
      taskNumber = new String("T" + jobNumber + " Quelength " + q.isEmpty());
      // Make message object from input text
      final OutMessage message = new OutMessage(jobNumber, cypherText, maxKeyLength);
      // pass message to handler and onto queue in its own thread from pool

      executorService.execute(
          new Runnable() {
            public void run() {
              mh.add(message);
            }
          });

    } else {
      // Check out-queue for finished job

      // copy plain text to string cypher2 to appear on page
      plainText = mh.get(jobNumber);
    }

    out.print("<H1>Processing request for Job#: " + taskNumber + "</H1>");
    out.print("<div id=\"r\"></div>");

    out.print("RMI Server is located at " + remoteHost);
    out.print("<P>Maximum Key Length: " + maxKeyLength);
    out.print("<P>CypherText: " + cypherText);
    out.print("<P>Decoded: " + plainText);
    out.print(
        "<P>This servlet should only be responsible for handling client request and returning responses. Everything else should be handled by different objects.");
    out.print(
        "<P>Note that any variables declared inside this doGet() method are thread safe. Anything defined at a class level is shared between HTTP requests.");

    out.print("<P> Next Steps:");
    out.print("<OL>");
    out.print(
        "<LI>Generate a big random number to use a a job number, or just increment a static long variable declared at a class level, e.g. jobNumber");
    out.print(
        "<LI>Create some type of a message request object from the maxKeyLength, cypherText and jobNumber.");
    out.print("<LI>Add the message request object to a LinkedList or BlockingQueue (the IN-queue)");
    out.print(
        "<LI>Return the jobNumber to the client web browser with a wait interval using <meta http-equiv=\"refresh\" content=\"10\">. The content=\"10\" will wait for 10s.");
    out.print("<LI>Have some process check the LinkedList or BlockingQueue for message requests ");
    out.print(
        "<LI>Poll a message request from the front of the queue and make an RMI call to the Vigenere Cypher Service");
    out.print(
        "<LI>Get the result and add to a Map (the OUT-queue) using the jobNumber and the key and the result as a value");
    out.print(
        "<LI>Return the cyphertext to the client next time a request for the jobNumber is received and delete the key / value pair from the Map.");
    out.print("</OL>");

    out.print("<form name=\"frmCracker\">");
    out.print("<input name=\"frmMaxKeyLength\" type=\"hidden\" value=\"" + maxKeyLength + "\">");
    out.print("<input name=\"frmCypherText\" type=\"hidden\" value=\"" + cypherText + "\">");
    out.print("<input name=\"frmStatus\" type=\"hidden\" value=\"" + taskNumber + "\">");
    out.print("</form>");
    out.print("</body>");
    out.print("</html>");

    out.print("<script>");
    out.print("var wait=setTimeout(\"document.frmCracker.submit();\", 10000);");
    out.print("</script>");

    /*-----------------------------------------------------------------------
     *  Next Steps: just in case you removed the above....
     *-----------------------------------------------------------------------
     * 1) Generate a big random number to use a a job number, or just increment a static long variable declared at a class level, e.g. jobNumber
     * 2) Create some type of a "message request" object from the maxKeyLength, cypherText and jobNumber.
     * 3) Add the "message request" object to a LinkedList or BlockingQueue (the IN-queue)
     * 4) Return the jobNumber to the client web browser with a wait interval using <meta http-equiv="refresh" content="10">. The content="10" will wait for 10s.
     * 4) Have some process check the LinkedList or BlockingQueue for "message requests"
     * 5) Poll a "message request" from the front of the queue and make an RMI call to the Vigenere Cypher Service
     * 6) Get the result and add to a Map (the OUT-queue) using the jobNumber and the key and the result as a value
     * 7) Return the cyphertext to the client next time a request for the jobNumber is received and delete the key / value pair from the Map.
     */

    // You can use this method to implement the functionality of an RMI client

    //

  }