/** * The <code>setCookie</code> method is used to set a cookie value with the cookie name. This will * add a cookie to the response stored under the name of the cookie, when this is committed it * will be added as a Set-Cookie header to the resulting response. * * @param cookie this is the cookie to be added to the response * @return returns the cookie that has been set in the response */ @Override public Cookie setCookie(Cookie cookie) { String name = cookie.getName(); if (name != null) { this.cookies.put(name, cookie); } return cookie; }
@Override public void setDomain(String domain) { c.setDomain(domain); }
@Override public String getDomain() { return c.getDomain(); }
@Override public void setPath(String path) { c.setPath(path); }
@Override public String getPath() { return c.getPath(); }
@Override public void setExpiry(int expiry) { c.setExpiry(expiry); }
@Override public int getExpiry() { return c.getExpiry(); }
@Override public void setSecure(boolean secure) { c.setSecure(secure); }
@Override public boolean getSecure() { return c.getSecure(); }
@Override public void setValue(String value) { c.setValue(value); }
@Override public String getValue() { return c.getValue(); }
@Override public String getName() { return c.getName(); }
@Override public void setVersion(int version) { c.setVersion(version); }
@Override public int getVersion() { return c.getVersion(); }
@Override public void handle(Request req, Response res) { try { Path p = req.getPath(); Query qry = req.getQuery(); PrintStream ps = res.getPrintStream(); long time = System.currentTimeMillis(); String service; if (p.getSegments().length >= 1) { service = p.getSegments()[0]; } else { service = ""; } res.setValue("Content-Type", "text/html"); res.setValue("Server", "SLPeripherals/1.0 (Simple 4.0)"); res.setDate("Date", time); res.setDate("Last-Modified", time); // System.out.println("request" + url); try { if (Integer.valueOf(service) != null) { int i = Integer.valueOf(service); if (services.get(i) != null) { // put an event and wait for response IComputerAccess ica = (IComputerAccess) ((Object[]) services.get(i))[0]; TileEntityHTTPD hd = (TileEntityHTTPD) ((Object[]) services.get(i))[1]; hd.reqsw.add(ps); int idx = hd.reqsw.lastIndexOf(ps); // reqs.add("{bl}"); // int idx=reqs.lastIndexOf("{bl}"); Map<String, String> cookies = new HashMap<String, String>(); for (Cookie c : res.getCookies()) { cookies.put(c.getName(), c.getValue()); } ica.queueEvent("http_server_request", new Object[] {idx, p.getPath(1), qry, cookies}); return; /* * * for (int ij = 1; ij <= 10; ij++) { Thread.sleep(100); * * if (! reqs.get(idx).equals("{bl}")) { // request * done. ps.print(reqs.get(idx)); ps.close(); return; } * * } * * // request timed out * * reqs.remove(idx); * * * * ps.print( * "<hr>The computer did not respond after 1 second, request timed out." * ); ps.close(); return; */ } else { ps.print( "SLP HTTP Server (based on the Simple Framework)<br>" + "The service " + i + " is not online."); } } } catch (Exception e) { ps.print( "SLP HTTP Server (based on the Simple Framework)<br>" + "Please go to a service by typing the computer id then a slash, example:<br>" + "http://localhost/4/<br>" + "would go to Computer ID 4's service. - The IDs are assigned by ComputerCraft.<br>" + "(please note 'localhost' depends on your setup. You may have to use a port number too. See the current URL.).<br>(exception encountered)"); } ps.close(); } catch (Exception e) { e.printStackTrace(); } }