Examples of IHttpRequest


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

  /**
   * {@inheritDoc}
   */
  public void onRequest(final IHttpExchange exchange) throws IOException {

    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

          return null;
      }

   
    public IMessageHandler onMessageHeaderReceived(IHttpMessage message) throws IOException {
      final IHttpRequest request = (IHttpRequest) message;
   
     
      if (transactionMonitor != null) {
          transactionMonitor.registerMessageHeaderReceived(HttpServerConnection.this, request.getRequestHeader());
      }
     
   
      // handle Connection header
      handleLifeCycleHeaders(request);
     
     
      if (LOG.isLoggable(Level.FINE)) {
       
        if (request.hasBody()) {
                    String body = "";
                   
                    String contentType = request.getContentType();
                    if ((contentType != null) && (contentType.startsWith("application/x-www-form-urlencode"))) {
                        body = request.getNonBlockingBody().toString() + "\n";                     
                    }
                   
                    LOG.fine("[" + getId() + "] request received  from " + getRemoteAddress() +
                             ":" + getRemotePort() +
                             " (" + getCountMessagesReceived() + ". request) " + request.getRequestHeader().toString() + body);
       
        } else {
                    LOG.fine("[" + getId() + "] bodyless request received from " + getRemoteAddress() +
                            ":" + getRemotePort() +
                            " (" + getCountMessagesReceived() + ". request) " + request.getRequestHeader().toString());
        }
      }
     
     
     
   
       
      // handle upgrade header
      if (isAutohandleUpgadeHeader) {
        String upgrade = request.getRequestHeader().getUpgrade();
        if ((upgrade != null) && upgrade.equalsIgnoreCase("TLS/1.0")) {

          if (getUnderlyingTcpConnection().isSecuredModeActivateable()) {
            suspendReceiving();
           
            HttpResponse response = new HttpResponse(101);
            response.setHeader("Connection", "Upgrade");
            response.setHeader("Upgrade", "TLS/1.0, HTTP/1.1");
            writeMessage(response);
           
            getUnderlyingTcpConnection().activateSecuredMode();
         
            resumeReceiving();
           
          } else {
            sendResponseMessage(new HttpResponse(400, "text/html", generateErrorMessageHtml(400, "upgrade TLS is not supported", getId())));
            return this;
          }
         
          return this;
        }
      }
     
     
      boolean isFormUrlEncoded = isContentTypeFormUrlencoded(request);


     
     
      if (message.hasBody()) {
         

          // handle 100 continue header
              if (HttpUtils.hasExpectContinueHeader(request.getRequestHeader())) {
                 
                  if (isFormUrlEncoded || requestHandlerAdapter.isInvokeOnMessageReceived()) {
                      if (LOG.isLoggable(Level.FINE)) {
                          if (requestHandlerAdapter.isInvokeOnMessageReceived()) {
                              LOG.fine("request handler (chain) will be invoked onMessageReceived -> autohandle 100-continue");
                          } else if (isFormUrlEncoded) {
                              LOG.fine("request contains FormUrlEncoded body -> autohandle 100-continue");
                          }
                      }
                     
                      request.setAttribute("org.xlightweb.100-continue-has-been-sent", "true");
                      writeMessageSilence(new HttpResponse(100));
                  }
              }

View Full Code Here

Examples of org.xlightweb.IHttpRequest

    private final AtomicBoolean isCompleteListnerCalled = new AtomicBoolean(false);
    private final AtomicBoolean isClosed = new AtomicBoolean(false);

    public void onRequest(IHttpExchange exchange) throws IOException {

      IHttpRequest request = exchange.getRequest();
     
      IBodyCompleteListener cl = new IBodyCompleteListener() {
        public void onComplete() throws IOException {
          isCompleteListnerCalled.set(true);
        }
      };
      request.getNonBlockingBody().addCompleteListener(cl);
     
     
      IBodyDataHandler dh = new IBodyDataHandler() {
       
        public boolean onData(NonBlockingBodyDataSource bodyDataSource) throws BufferUnderflowException {

          try {
            int available = bodyDataSource.available();
            if (available == -1) {
              isClosed.set(true);
            } else {
              bodyDataSource.readByteBufferByLength(available);
            }
          } catch (IOException e) {
            exceptionRef.set(e);
          }
         
          return true;
        }
      };
      request.getNonBlockingBody().setDataHandler(dh);
    }   
View Full Code Here

Examples of org.xlightweb.IHttpRequest

          return null;
      }

   
    public IMessageHandler onMessageHeaderReceived(IHttpMessage message) throws IOException {
      final IHttpRequest request = (IHttpRequest) message;
   
     
      if (transactionMonitor != null) {
          transactionMonitor.registerMessageHeaderReceived(HttpServerConnection.this, request.getRequestHeader());
      }
     
   
      // handle Connection header
      handleLifeCycleHeaders(request);
     
     
      if (LOG.isLoggable(Level.FINE)) {
       
        if (request.getNonBlockingBody() == null) {
          LOG.fine("[" + getId() + "] bodyless request received from " + getRemoteAddress() +
               ":" + getRemotePort() +
               " (" + getCountMessagesReceived() + ". request) " + request.getRequestHeader().toString());
       
        } else {
          String body = "";
         
          String contentType = request.getContentType();
          if ((contentType != null) && (contentType.startsWith("application/x-www-form-urlencode"))) {
            body = request.getNonBlockingBody().toString() + "\n";           
          }
         
          LOG.fine("[" + getId() + "] request received  from " + getRemoteAddress() +
               ":" + getRemotePort() +
               " (" + getCountMessagesReceived() + ". request) " + request.getRequestHeader().toString() + body);
        }
      }
     
     
     
   
       
      // handle upgrade header
      if (isAutohandleUpgadeHeader) {
        String upgrade = request.getRequestHeader().getUpgrade();
        if ((upgrade != null) && upgrade.equalsIgnoreCase("TLS/1.0")) {

          if (getUnderlyingTcpConnection().isSecuredModeActivateable()) {
            suspendReceiving();
           
            HttpResponse response = new HttpResponse(101);
            response.setHeader("Connection", "Upgrade");
            response.setHeader("Upgrade", "TLS/1.0, HTTP/1.1");
            writeMessage(response);
           
            getUnderlyingTcpConnection().activateSecuredMode();
         
            resumeReceiving();
           
          } else {
            sendResponseMessage(new HttpResponse(400, "text/html", generateErrorMessageHtml(400, "upgrade TLS is not supported", getId())));
            return this;
          }
         
          return this;
        }
      }


      // handle 100 continue header
      if (isAutconfirmExpect100ContinueHeader) {
        String expectHeader = request.getHeader("Expect");
        if ((expectHeader != null) && expectHeader.equalsIgnoreCase("100-Continue")) {
          writeMessageSilence(new HttpResponse(100));
        }
      }
View Full Code Here

Examples of org.xlightweb.IHttpRequest

   
   
 
    public void onRequest(IHttpExchange exchange) throws IOException {
     
      IHttpRequest request = exchange.getRequest();
     
      // only POST is supported
      if (request.getMethod().equalsIgnoreCase("POST")) {
       
        if (request.getRequestURI().endsWith("/RegisterClient")) {
          BlockingBodyDataSource inChannel = request.getBlockingBody();
          inChannel.setReceiveTimeoutSec(1);
         
          BodyDataSink outChannel = exchange.send(new HttpResponseHeader(200, "text/plain"));
          outChannel.setFlushmode(FlushMode.ASYNC);
          outChannel.flush();
View Full Code Here

Examples of org.xlightweb.IHttpRequest

        server.start();
       
        HttpClient httpClient = new HttpClient();
       
       
        IHttpRequest request = new GetRequest("http://localhost:" + server.getLocalPort() + "/test/12345");
        IHttpResponse resp = httpClient.call(request);
        Assert.assertEquals(302, resp.getStatus());
        Assert.assertEquals("123456", resp.getBody().readString());
       
       
View Full Code Here

Examples of org.xlightweb.IHttpRequest

       
        HttpClient httpClient = new HttpClient();
        httpClient.setCacheMaxSizeKB(100);
       
       
        IHttpRequest request = new GetRequest("http://localhost:" + server.getLocalPort() + "/test/12345");
        IHttpResponse resp = httpClient.call(request);
        Assert.assertEquals(302, resp.getStatus());
        Assert.assertEquals("123456", resp.getBody().readString());
       
       
View Full Code Here

Examples of org.xlightweb.IHttpRequest

        server.start();
       
        HttpClient httpClient = new HttpClient();
       
       
        IHttpRequest request = new GetRequest("http://localhost:" + server.getLocalPort() + "/test/12345");
        IHttpResponse resp = httpClient.call(request);
        Assert.assertEquals(302, resp.getStatus());
        Assert.assertEquals("123456", resp.getBlockingBody().readString());
       
       
View Full Code Here

Examples of org.xlightweb.IHttpRequest

       
        HttpClient httpClient = new HttpClient();
        httpClient.setCacheMaxSizeKB(100);
       
       
        IHttpRequest request = new GetRequest("http://localhost:" + server.getLocalPort() + "/test/12345");
        IHttpResponse resp = httpClient.call(request);
        Assert.assertEquals(302, resp.getStatus());
        Assert.assertEquals("123456", resp.getBlockingBody().readString());
       
       
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.