Package org.xlightweb

Examples of org.xlightweb.HttpResponse


  @Override
  protected void onProtocolException(Exception ex) {
    if (ex instanceof BadMessageException) {
      setPersistent(false);
      try {
        sendResponseMessage(new HttpResponse(400, "text/html", generateErrorMessageHtml(400, ex.getMessage(), getId())));
      } catch (IOException ioe) {
        if (LOG.isLoggable(Level.FINE)) {
          LOG.fine("[" + getId() + "] could not send error message " + 400 + " reason " + ioe.toString());
        }
        destroy();
View Full Code Here


        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

          header.setHeader("Connection", "close");
          header.setProtocol(getRequest().getProtocol());
        }
       
      } catch (Exception e) {
        HttpResponse errorResponse = null;
        if (HttpUtils.isShowDetailedError()) {
          errorResponse = new HttpResponse(400, "text/html", generateErrorMessageHtml(400, DataConverter.toString(e), getId()));
         
        } else {
          errorResponse = new HttpResponse(400, "text/html", generateErrorMessageHtml(400, HttpUtils.getReason(400), getId()));
        }
        setResponseCommited(true);
        HttpServerConnection.this.sendResponseMessage(errorResponse);
        throw new IOException(e.toString());
      }
View Full Code Here

    }

   
    @Override
    protected void doSendContinue() throws IOException {
        writeMessageSilence(new HttpResponse(100));
    }
View Full Code Here

            response.getResponseHeader().setProtocol(getRequest().getProtocol());
            response.getResponseHeader().setHeader("Connection", "close");
          }
        }
      } catch (Exception e) {
        HttpResponse errorResponse = null;
        if (HttpUtils.isShowDetailedError()) {
          errorResponse = new HttpResponse(400, "text/html", generateErrorMessageHtml(400, DataConverter.toString(e), getId()));
         
        } else {
          errorResponse = new HttpResponse(400, "text/html", generateErrorMessageHtml(400, HttpUtils.getReason(400), getId()));
        }
        setResponseCommited(true);
        HttpServerConnection.this.sendResponseMessage(errorResponse);
        throw new IOException(e.toString());
      }
View Full Code Here

        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("[" + getId() + "] no handler found (for requested resource). returning error message");
        }
       
        try {
            IHttpResponse response = new HttpResponse(404, "text/html", generateErrorMessageHtml(404, null, getId()));
            callResponseHandler(responseHandler, response);
        } catch (IOException ioe) {
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("[" + getId() + "] could not send not handle response. " + ioe.toString());
            }
View Full Code Here

        String basepath = file.getParentFile().getAbsolutePath();
       
        IHttpRequestHandler businessHandler = new IHttpRequestHandler() {
           
            public void onRequest(IHttpExchange exchange) throws IOException, BadMessageException {
                exchange.send(new HttpResponse(200, "text/plain", "OK"));
            }
        };
        chain.addLast(businessHandler);
       
        FileServiceRequestHandler fileHandler = new FileServiceRequestHandler(basepath, true);
View Full Code Here

  @Override
  protected void onProtocolException(Exception ex) {
    if (ex instanceof BadMessageException) {
      setPersistent(false);
      try {
        sendResponseMessage(new HttpResponse(400, "text/html", generateErrorMessageHtml(400, ex.getMessage(), getId())));
      } catch (IOException ioe) {
        if (LOG.isLoggable(Level.FINE)) {
          LOG.fine("[" + getId() + "] could not send error message " + 400 + " reason " + ioe.toString());
        }
        destroy();
View Full Code Here

        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

  public void testGetWithExpireHeader() throws Exception {
     
        IHttpRequestHandler reqHdl = new IHttpRequestHandler() {
           
            public void onRequest(IHttpExchange exchange) throws IOException, BadMessageException {
                HttpResponse resp = new HttpResponse(200, "text/plain", "test");
                resp.setHeader("Expires", "Fri, 30 Oct 2011 14:19:41 GMT");
                exchange.send(resp);
            }
        };
       
        HttpServer server = new HttpServer(reqHdl);
        server.start();
       
       
        HttpClient httpClient = new HttpClient();
        httpClient.setCacheMaxSizeKB(100);
        ConnectionUtils.registerMBean(httpClient);
       
        IHttpResponse resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertEquals("test", resp.getBlockingBody().readString());
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
       
        QAUtil.sleep(1000);
       
        resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertTrue(resp.getHeader(CacheHandler.XHEADER_NAME).startsWith("HIT"));
        Assert.assertEquals("test", resp.getBlockingBody().readString());
       
       
        Assert.assertEquals(1, httpClient.getNumCacheHit());
        Assert.assertEquals(1, httpClient.getNumCacheMiss());
       
View Full Code Here

TOP

Related Classes of org.xlightweb.HttpResponse

Copyright © 2018 www.massapicom. 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.