Exemplo n.º 1
0
  // doGet, doPost delegate to this method
  @SuppressWarnings("unchecked")
  public void doPGU(HttpServletRequest request, HttpServletResponse response, String method) {
    initVelocity();

    // parse command and arguments from request path
    String pathinfo = request.getPathInfo();
    if (pathinfo == null) {
      pathinfo = "";
    }

    System.out.println("REQUEST: " + pathinfo);

    String cmd = null;

    StringTokenizer kk = new StringTokenizer(pathinfo, "/");
    int i = 0;
    Vector[] args = {new Vector<String>(), new Vector<String>()};
    if (kk.countTokens() != 0) {
      cmd = kk.nextToken();
      while (kk.hasMoreTokens()) {
        String kkk = URLDecoder.decode(kk.nextToken());
        System.out.println("[" + method + "] PATHINFO[" + i + "]: " + kkk);
        args[i % 2].add(kkk);
        i++;
      }
    }

    // Default-cmd == index
    if (cmd == null || cmd.equals("")) {
      cmd = "index";
    }

    if ("keyinfo".equals(cmd)) {
      handleKeyInfo(request, response, method, cmd, args);
    } else if ("keygraph".equals(cmd)) {
      handleKeyGraph(request, response, method, cmd, args);
    } else if ("index".equals(cmd)) {
      RenderVelocityAction action = new RenderVelocityAction(request, response, method, "index.vm");
      handleAction(action, cmd, args, request);
    } else if ("echo".equals(cmd)) {
      RenderVelocityAction action = new RenderVelocityAction(request, response, method, "echo.vm");
      handleAction(action, cmd, args, request);
    } else if ("ajax_nodes_edges".equals(cmd)) {

      Element res = new Element("nodes_edges");
      // add key
      String keyid = getValueString("keyid", args);
      if (keyid != null) {
        System.out.println("ajax_nodes_edges:: keyid=" + keyid);
        Vector<String> keyids = new Vector<String>();
        // key basics
        OSDXKey key = getBackend().getKey(keyid);
        if (key != null) {
          res.addContent(key.getSimplePubKeyElement());
          keyids.add(key.getKeyID());

          // add keylogs and fromKeys
          Vector<KeyLog> logs = getBackend().getKeyLogsToID(key.getKeyID());
          if (logs != null && logs.size() > 0) {
            for (KeyLog l : logs) {
              if (!keyids.contains(l.getKeyIDFrom())) {
                OSDXKey fromkey = getBackend().getKey(l.getKeyIDFrom());
                if (fromkey != null) {
                  res.addContent(fromkey.getSimplePubKeyElement());
                  keyids.add(fromkey.getKeyID());
                }
              }
              res.addContent(l.toElement(false));
            }
          }
        }
      }
      response.setContentType("text/xml");
      try {
        PrintWriter out = response.getWriter();
        out.println(Document.buildDocument(res).toStringCompact());
        out.flush();
        out.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
Exemplo n.º 2
0
 // HEAD not allowed
 public void doHead(HttpServletRequest request, HttpServletResponse response) {
   response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
 }