public void run() { Scanner in = new Scanner(System.in); while (true) { String msg; try { msg = in.nextLine().trim(); Pattern p = Pattern.compile("^@(\\w+)\\s+(.+)"); Matcher m = p.matcher(msg); if (msg.equals("quit")) { this.server.disconnect(this); in.close(); System.exit(0); } else if (msg.equals("list")) { this.server.list(this); } else if (m.find()) { String receiverName = m.group(1); BaseClient receiver = server.lookup(receiverName); if (receiver != null) { receiver.receive(this.name, "<private> %s".format(m.group(2))); } else { this.server.broadcast(this.name, m.group(2)); } } else { this.server.broadcast(this.name, msg); } } catch (Exception e) { e.printStackTrace(); } } }
public static void showClient(BaseClient client) { System.out.println("-------------------------------------------------------"); System.out.println("REQUEST:"); System.out.println("-------------------------------------------------------"); System.out.println(client.getRequestAsString()); System.out.println(""); System.out.println("-------------------------------------------------------"); System.out.println("RESPONSE:"); System.out.println("-------------------------------------------------------"); System.out.println(client.getResponseAsString()); System.out.println(""); }
public static void showClientUserAgent(BaseClient client) { System.out.println("-------------------------------------------------------"); System.out.println("REQUEST:"); System.out.println("-------------------------------------------------------"); System.out.println(client.getUrl() + "?" + client.getRequest().getQueryString()); System.out.println(""); if (client.getResponse() != null) { System.out.println("-------------------------------------------------------"); System.out.println("RESPONSE:"); System.out.println("-------------------------------------------------------"); System.out.println("HTTP/1.1 302 Found"); System.out.println("Location: " + client.getResponse().getLocation()); System.out.println(""); } }
@Override public void authenticate() { BaseClient.setDefaultHeader(Headers.AUTHORIZATION, getToken()); }