示例#1
0
  public void run() {

    System.err.println("Accepted connection from client");
    String s;
    JSONObject json;
    String command = null;
    ServerCommand sc = null;
    while ((s = in.readLine()) != null) {
      System.out.println("Got command: " + s);
      try {
        json = (JSONObject) JSONSerializer.toJSON(s);
        command = json.getString("command");
        if (json != null && command != null) {
          sc = this.jAuctionServer.serverCommandFactory.getCommand(command, this);
          JSONObject data = json.getJSONObject("data");
          if (sc != null) {
            if (sc.parseJson(data)) {
              Thread t = new Thread(sc);
              t.start();
            } else {
              badRequest();
            }
            json = null;
            command = null;
            sc = null;
          }
        }
      } catch (net.sf.json.JSONException e) {
        badRequest();
        System.err.println("bad request: " + s);
        json = null;
        command = null;
        sc = null;
      }
    }
    close();
  }