Examples of IHttpRequest


Examples of org.xlightweb.IHttpRequest

  /**
   * {@inheritDoc}
   */
  public void onRequest(IHttpExchange exchange) throws IOException {
   
    IHttpRequest request = exchange.getRequest();
   
    if (!hasProxytoUse(request)) {
      exchange.forward(request);
      return;
    }
     
    if (request.isSecure()) {
      forwardSSL(exchange);
     
    } else {
      forwardNonSSL(exchange);
    }
View Full Code Here

Examples of org.xlightweb.IHttpRequest

  }
 
 
  private void forwardNonSSL(IHttpExchange exchange) throws IOException {
   
    IHttpRequest request = exchange.getRequest();
   
    if (proxyUser != null) {
      if (proxyUserPassword != null) {
        request.addHeader("Proxy-Authorization", "Basic " + proxyUserPassword);
       
      } else {
        if (LOG.isLoggable(Level.FINE)) {
          LOG.fine("proxy password is not send send error");
        }
        exchange.sendError(new IOException("proxy user password is not set (hint: usage <HttpClient>.setProxyPassword(...)"));
        return;
      }
    }
   
    IHttpRequest wrappedRequest = null;
    if (request.hasBody()) {
      wrappedRequest = new HttpRequest(new NonSSLRequestHeaderWrapper(request.getRequestHeader()), request.getNonBlockingBody());
    } else {
      wrappedRequest = new HttpRequest(new NonSSLRequestHeaderWrapper(request.getRequestHeader()));
    }
View Full Code Here

Examples of org.xlightweb.IHttpRequest

        exchange.sendError(ioe);
      }
    };
   
   
    IHttpRequest request = exchange.getRequest();
   


    try {
      Map<String, List<String>> cookieHeaders = cookieManager.get(getRequestURI(exchange));
     
     
      for (Entry<String, List<String>> entry : cookieHeaders.entrySet()) {
       
        if (!entry.getValue().isEmpty()) {
          StringBuilder sb = new StringBuilder();
         
          List<String> cookies = entry.getValue();
          for (int i = 0; i < cookies.size(); i++) {
            sb.append(cookies.get(i));
            if ((i +1) < cookies.size()) {
              sb.append("; ");
            }
          }
         
          if ((request.getHeader("Cookie") != null) && isCookieWarning(request)) {
            LOG.warning("cookie is set manually and auto handle cookie is activated " +
                    "(hint: deactivate auto handling cookie by calling <httpClient>.setAutoHandleCookies(false) or " +
                    "suppress this message by setting system property 'org.xlightweb.client.cookieHandler.cookieWarning=false')");
          }         
          request.addHeader(entry.getKey(), sb.toString());
        }
      }
    } catch (URISyntaxException ue) {
      if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("invcalid URI. ignore handling cookies " + ue.toString());
View Full Code Here

Examples of org.xlightweb.IHttpRequest

       
       
        void revalidate(final IValidationHandler hdl) throws IOException {

           
            IHttpRequest requestCopy = HttpUtils.copy(request);
           
            if (response.getHeader("Etag") != null) {
                requestCopy.setHeader("IF-None-Match", response.getHeader("Etag"));
            } else {
                requestCopy.setHeader("If-Modified-Since", response.getHeader("Last-Modified"));
            }           
            requestCopy.setAttribute(CacheHandler.SKIP_CACHE_HANDLING, "true");

           
            IHttpResponseHandler respHdl = new IHttpResponseHandler() {
               
                @Execution(Execution.NONTHREADED)
                @InvokeOn(InvokeOn.MESSAGE_RECEIVED)
                public void onResponse(IHttpResponse response) throws IOException {
                                       
                    if (response.getStatus() == 304) {
                        CacheEntry entry = updateCacheEntryOnRevaildation(request, response.getResponseHeader());
                        register(entry);
                       
                        hdl.onRevalidated(true, CacheEntry.this);
                       
                    } else {
                       
                        if (isCacheableSuccess(response.getStatus())) {
                            CacheEntry entry = updateCacheEntry(request, response);
                            register(entry);
                        } else {
                            deregister(request);
                        }
                       
                        hdl.onRevalidated(false, CacheEntry.this);
                    }
                }
               
               
                public void onException(IOException ioe) throws IOException {
                    if (LOG.isLoggable(Level.FINE)) {
                        LOG.fine("got exception by revalidating "+ ioe.toString());
                    }
                    deregister(request);
                   
                    hdl.onException(ioe);
                }
            };

            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("revalidating request " + requestCopy.getRequestUrl().toString());
            }
            httpClient.send(requestCopy, respHdl);
        }
View Full Code Here

Examples of org.xlightweb.IHttpRequest

       
        IHttpRequestHandler rh = new IHttpRequestHandler() {
           
            public void onRequest(IHttpExchange exchange) throws IOException, BadMessageException {
                IHttpRequest request = exchange.getRequest();
               
                BodyDataSink dataSink = exchange.send(new HttpResponseHeader(200));
                dataSink.write("test");
               
                QAUtil.sleep(200);
View Full Code Here

Examples of org.xlightweb.IHttpRequest

       
        IHttpRequestHandler rh = new IHttpRequestHandler() {
           
            public void onRequest(IHttpExchange exchange) throws IOException, BadMessageException {
                IHttpRequest request = exchange.getRequest();
               
                BodyDataSink dataSink = exchange.forward(request.getRequestHeader());
                dataSink.write("addedLine\r\n");
                dataSink.write(request.getBlockingBody().readString());
                dataSink.close();
            }
        };
        chain.addLast(rh);
       
       
        IHttpRequestHandler rh2 = new IHttpRequestHandler() {
           
            public void onRequest(IHttpExchange exchange) throws IOException, BadMessageException {
                IHttpRequest request = exchange.getRequest();
                exchange.send(new HttpResponse(200, request.getBlockingBody().readString()));
            }
        };
        chain.addLast(rh2);

       
View Full Code Here

Examples of org.xlightweb.IHttpRequest

 
  private static final class ServerHandler implements IHttpRequestHandler {
   
    public void onRequest(IHttpExchange exchange) throws IOException {
     
      IHttpRequest request = exchange.getRequest();
      if (request.getHeader("sleep-time") != null) {
        int sleepTime = Integer.parseInt(request.getHeader("sleep-time"));
        QAUtil.sleep(sleepTime);
      }
      
      exchange.send(new HttpResponse(200, "text/plain", "OK"));
    }
View Full Code Here

Examples of org.xlightweb.IHttpRequest

       
       
        void revalidate(final IValidationHandler hdl) throws IOException {

           
            IHttpRequest requestCopy = HttpUtils.copy(request);
           
            if (response.getHeader("Etag") != null) {
                requestCopy.setHeader("IF-None-Match", response.getHeader("Etag"));
            } else {
                requestCopy.setHeader("If-Modified-Since", response.getHeader("Last-Modified"));
            }           
            requestCopy.setAttribute(CacheHandler.SKIP_CACHE_HANDLING, "true");

           
            IHttpResponseHandler respHdl = new IHttpResponseHandler() {
               
                @Execution(Execution.NONTHREADED)
                @InvokeOn(InvokeOn.MESSAGE_RECEIVED)
                public void onResponse(IHttpResponse response) throws IOException {
                                       
                    if (response.getStatus() == 304) {
                        CacheEntry entry = updateCacheEntryOnRevaildation(request, response.getResponseHeader());
                        register(entry);
                       
                        hdl.onRevalidated(true, CacheEntry.this);
                       
                    } else {
                       
                        if (isCacheableSuccess(response.getStatus())) {
                            CacheEntry entry = updateCacheEntry(request, response);
                            register(entry);
                        } else {
                            deregister(request);
                        }
                       
                        hdl.onRevalidated(false, CacheEntry.this);
                    }
                }
               
               
                public void onException(IOException ioe) throws IOException {
                    if (LOG.isLoggable(Level.FINE)) {
                        LOG.fine("got exception by revalidating "+ ioe.toString());
                    }
                    deregister(request);
                   
                    hdl.onException(ioe);
                }
            };

            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("revalidating request " + requestCopy.getRequestUrl().toString());
            }
            httpClient.send(requestCopy, respHdl);
        }
View Full Code Here

Examples of org.xlightweb.IHttpRequest

     
      private Authenticator authenticator = new Authenticator();
     
      public void onRequest(final IHttpExchange exchange) throws IOException {
       
        IHttpRequest request = exchange.getRequest();
        String authorization = request.getHeader("Authorization");
        if (authorization != null) {
          String[] s = authorization.split(" ");
          if (!s[0].equalsIgnoreCase("BASIC")) {
            exchange.sendError(401);
          }
         
          String decoded = new String(Base64.decodeBase64(s[1].getBytes()));
          String[] userPasswordPair = decoded.split(":");
         
          String authtoken = authenticator.login(userPasswordPair[0], userPasswordPair[1]);

          request.removeHeader("Authorization");
          request.setHeader("X-Authentication", authtoken);
         
         
          IHttpResponseHandler respHdl = new IHttpResponseHandler() {

            public void onResponse(IHttpResponse response) throws IOException {
              exchange.send(response);
             
            }
           
            public void onException(IOException ioe) {
            }
          };
         
          exchange.forward(exchange.getRequest(), respHdl);
           return;
        }
       
           
        String authentication = request.getHeader("Authentication");
        if (authentication == null) {
         
          HttpResponse resp = new HttpResponse(401);
          resp.setHeader("WWW-Authenticate", "basic");
          exchange.send(resp);
View Full Code Here

Examples of org.xlightweb.IHttpRequest

 
  private static final class ServerHandler implements IHttpRequestHandler {
   
    public void onRequest(IHttpExchange exchange) throws IOException {
     
      IHttpRequest request = exchange.getRequest();
      if (request.getHeader("sleep-time") != null) {
        int sleepTime = Integer.parseInt(request.getHeader("sleep-time"));
        QAUtil.sleep(sleepTime);
      }
      
      exchange.send(new HttpResponse(200, "text/plain", "OK"));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.