@Override public void onResponseStatus(Buffer version, int status, Buffer reason) throws IOException { // Update the exchange method to get to support the Post/Redirect/Get // http://en.wikipedia.org/wiki/Post/Redirect/Get if (exchange.getMethod().equals("POST") && (status == HttpStatus.SEE_OTHER_303 || status == HttpStatus.MOVED_TEMPORARILY_302)) { exchange.setMethod("GET"); } // Since the default RedirectListener only cares about http // response codes 301 and 302, we override this method and // trick the super class into handling this case for us. if (status == HttpStatus.SEE_OTHER_303) { status = HttpStatus.MOVED_TEMPORARILY_302; } super.onResponseStatus(version, status, reason); } }
/** * */ private void stopServer() { HttpClient client = new HttpClient(); try { final HttpExchange exchange = new HttpExchange(); exchange.setMethod("POST"); exchange.setURL(String.format("http://127.0.0.1:%s/shutdown?secret=%s", port, secret)); client.send(exchange); log.info("LOG00010: shutdown status {}", exchange.getStatus()); } catch (IOException e) { log.error("LOG00020: Can't stop server gracefully", e); } }
exchange.setMethod(request.getMethod()); exchange.setURL(url.toString()); exchange.setVersion(request.getProtocol());
exchange.setMethod(request.getMethod()); exchange.setURL(url.toString()); exchange.setVersion(request.getProtocol());
exch.setMethod("GET"); exch.setRequestContentType(getPostContentType()); exch.setRequestContent(formatPostData(data));
exch.setMethod("GET"); exch.setAddress(new Address(host, port)); exch.setURI(getRequestURI());
exch.setMethod("GET"); exch.setRequestContentType(getPostContentType()); exch.setRequestContent(formatPostData(data));
authenticate(); HttpExchange postExchange = new FritzahaContentExchange(callback); postExchange.setMethod("POST"); postExchange.setURL(getURL(path)); try {
exch.setMethod("GET"); exch.setAddress(new Address(host, port)); exch.setURI(getRequestURI());
/** * Sends an HTTP GET request using the asynchronous client * * @param Path * Path of the requested resource * @param Args * Arguments for the request * @param Callback * Callback to handle the response with */ public HttpExchange asyncGet(String path, String args, FritzahaCallback callback) { if (!isAuthenticated()) authenticate(); HttpExchange getExchange = new FritzahaContentExchange(callback); getExchange.setMethod("GET"); getExchange.setURL(getURL(path, addSID(args))); try { asyncclient.send(getExchange); } catch (IOException e) { logger.error("An I/O error occurred while sending the GET request " + getURL(path, addSID(args))); return null; } logger.debug("GETting URL " + getURL(path, addSID(args))); return getExchange; }
exchange.setMethod(request.getMethod()); exchange.setURL(url.toString()); exchange.setVersion(request.getProtocol());