Package org.xlightweb

Examples of org.xlightweb.HttpResponse


    public void testGetAlreadyExpired() 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");
                resp.setHeader("Cache-Control", "public, max-age=1");
                exchange.send(resp);
            }
        };
       
        HttpServer server = new HttpServer(reqHdl);
        server.start();
       
        HttpClient httpClient = new HttpClient();
        httpClient.setCacheMaxSizeKB(100);
       
        IHttpResponse resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertEquals("test", resp.getBody().readString());
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
       
        QAUtil.sleep(2000);
       
        resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
        Assert.assertEquals("test", resp.getBody().readString());
       
        QAUtil.sleep(1000);
       
        Assert.assertEquals(0, httpClient.getNumCacheHit());
        Assert.assertEquals(2, httpClient.getNumCacheMiss());
View Full Code Here


                       
                       
                        @Override
                        public void onComplete() {
                            try {
                                IHttpResponse responseCopy = new HttpResponse(responseHeader.copy(), responseBodyCopy);
                                interaction.setResponse(responseCopy);
                               
                            } catch (IOException ioe) {
                                if (LOG.isLoggable(Level.FINE)) {
                                    LOG.fine("error occured by creating/registering cachedResponse " + ioe.toString());
View Full Code Here

 
  private static final class RequestHandler implements IHttpRequestHandler {
   
    public void onRequest(IHttpExchange exchange) throws IOException {
     
      exchange.send(new HttpResponse(200, "text/plain", "OK"));
    }
View Full Code Here

        public BodyDataSink send(IHttpResponseHeader header) throws IOException, IllegalStateException {
           
            // return response to caller (request will not be send to remote endpoint)
            BodyDataSink dataSink = newInMemoryBodyDataSink(header.getCharacterEncoding(), executor);
           
            IHttpResponse response = new HttpResponse(header, getDataSourceOfInMemoryBodyDataSink(dataSink));
            send(response);
           
            return dataSink;
        }
View Full Code Here

        public BodyDataSink send(IHttpResponseHeader header, int contentLength) throws IOException, IllegalStateException {
           
            // return response to caller (request will not be send to remote endpoint)
            BodyDataSink dataSink = newInMemoryBodyDataSink(header.getCharacterEncoding(), executor);
           
            IHttpResponse response = new HttpResponse(header, getDataSourceOfInMemoryBodyDataSink(dataSink));
            send(response);
           
            return dataSink;
        }
View Full Code Here

 
 
  public static final class RequestHandler implements IHttpRequestHandler {
     
    public void onRequest(IHttpExchange exchange) throws IOException {
      exchange.send(new HttpResponse(200, "text/plain" , "isSecured=" + exchange.getRequest().isSecure()));
    }
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

          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

            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

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.