Package org.eclipse.jetty.server

Examples of org.eclipse.jetty.server.AbstractHttpConnection


    }

    public ByteArrayBuffer getResponse(String uri, int port, Map extraEnv)
            throws Exception {
        // get the current, previously active connection if one exists
        AbstractHttpConnection conn = AbstractHttpConnection
                .getCurrentConnection();

        // Identify the effective server name for this request
        Request parentRequest = (conn == null ? null : conn.getRequest());
        String host = (parentRequest == null ? "localhost:" + port //
                : parentRequest.getHeader("Host"));

        // construct an HTTP request for this data
        StringBuilder requestHeader = new StringBuilder();
View Full Code Here


    /**
     * This must be called within the context of an active HTTP request.
     */
    private static ConnectionTimeoutPreventer newTimeoutPreventor() {
        AbstractHttpConnection httpConnection = AbstractHttpConnection.getCurrentConnection();
        if (httpConnection == null) {
            LOGGER.log(Level.FINE, "No HttpConnection boundto local thread: " + Thread.currentThread().getName());
            return new ConnectionTimeoutPreventer() {
                @Override
                public void connectionActive() {
                }
            };
        } else {
            //call code reflectively because by default we have no access to jetty internal classes from a webapp
            // thus by only using HttpConnection we only need to add "-org.eclipse.jetty.server.HttpConnection" to server classes
            // to allow access to this class from a webapp
            final Object endpoint = httpConnection.getEndPoint();
            // try to cancel IDLE time
            try {
                LOGGER.fine("TimeoutPreventor - Invoking cancelIdle() method on endpoint class " + endpoint.getClass().getName());
                Method cancelIdle = endpoint.getClass().getMethod("cancelIdle");
                cancelIdle.invoke(endpoint);
View Full Code Here

              } else if (callback instanceof PasswordCallback) {
                ((PasswordCallback) callback).setPassword((char[]) credentials.toString().toCharArray());
              } else if (callback instanceof ObjectCallback) {
                ((ObjectCallback) callback).setObject(credentials);
              } else if (callback instanceof RequestParameterCallback) {
                AbstractHttpConnection connection = AbstractHttpConnection.getCurrentConnection();
                Request request = (connection == null ? null : connection.getRequest());

                if (request != null) {
                  RequestParameterCallback rpc = (RequestParameterCallback) callback;
                  rpc.setParameterValues(Arrays.asList(request.getParameterValues(rpc.getParameterName())));
                }
View Full Code Here

    this.gson = prettyGson;
  }

  @Override
  public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException {
    AbstractHttpConnection connection = AbstractHttpConnection.getCurrentConnection();
    connection.getRequest().setHandled(true);

    response.setContentType(MimeTypes.TEXT_PLAIN);

    Map<String, Object> errorMap = new LinkedHashMap<String, Object>();
    int code = connection.getResponse().getStatus();
    errorMap.put("status", code);
    String message = connection.getResponse().getReason();
    if (message == null) {
      message = HttpStatus.getMessage(code);
    }
    errorMap.put("message", message);
View Full Code Here

      if (logger.isLoggable(logStatus)) {
        TreeLogger branch = logger.branch(logStatus, String.valueOf(status)
            + " - " + request.getMethod() + ' ' + request.getUri() + " ("
            + userString + request.getRemoteHost() + ')' + bytesString);
        if (branch.isLoggable(logHeaders)) {
          AbstractHttpConnection connection = request.getConnection();
          logHeaders(branch.branch(logHeaders, "Request headers"), logHeaders,
              connection.getRequestFields());
          logHeaders(branch.branch(logHeaders, "Response headers"), logHeaders,
              connection.getResponseFields());
        }
      }
    }
View Full Code Here

            byte[] requestBytes = request.getRequestBytes();

            ByteArrayEndPoint endPoint = new ByteArrayEndPoint(requestBytes, 1024);
            endPoint.setGrowOutput(true);

            AbstractHttpConnection connection = new BlockingHttpConnection(ReverseHTTPConnector.this, endPoint, getServer());
           
            connectionOpened(connection);
            try
            {
                // Loop over the whole content, since handle() only
                // reads up to the connection buffer's capacities
                while (endPoint.getIn().length() > 0)
                    connection.handle();

                byte[] responseBytes = endPoint.getOut().asArray();
                RHTTPResponse response = RHTTPResponse.fromResponseBytes(request.getId(), responseBytes);
                client.deliver(response);
            }
View Full Code Here

        UserDataConstraint dataConstraint = roleInfo.getUserDataConstraint();
        if (dataConstraint == null || dataConstraint == UserDataConstraint.None)
        {
            return true;
        }
        AbstractHttpConnection connection = AbstractHttpConnection.getCurrentConnection();
        Connector connector = connection.getConnector();

        if (dataConstraint == UserDataConstraint.Integral)
        {
            if (connector.isIntegral(request))
                return true;
View Full Code Here

        // Transfer unread data from old connection to new connection
        // We need to copy the data to avoid races:
        // 1. when this unread data is written and the server replies before the clientToProxy
        // connection is installed (it is only installed after returning from this method)
        // 2. when the client sends data before this unread data has been written.
        AbstractHttpConnection httpConnection = AbstractHttpConnection.getCurrentConnection();
        Buffer headerBuffer = ((HttpParser)httpConnection.getParser()).getHeaderBuffer();
        Buffer bodyBuffer = ((HttpParser)httpConnection.getParser()).getBodyBuffer();
        int length = headerBuffer == null ? 0 : headerBuffer.length();
        length += bodyBuffer == null ? 0 : bodyBuffer.length();
        IndirectNIOBuffer buffer = null;
        if (length > 0)
        {
View Full Code Here

        upgradeConnection(request, response, clientToProxy);
    }

    private ClientToProxyConnection prepareConnections(ConcurrentMap<String, Object> context, SocketChannel channel, Buffer buffer)
    {
        AbstractHttpConnection httpConnection = AbstractHttpConnection.getCurrentConnection();
        ProxyToServerConnection proxyToServer = newProxyToServerConnection(context, buffer);
        ClientToProxyConnection clientToProxy = newClientToProxyConnection(context, channel, httpConnection.getEndPoint(), httpConnection.getTimeStamp());
        clientToProxy.setConnection(proxyToServer);
        proxyToServer.setConnection(clientToProxy);
        return clientToProxy;
    }
View Full Code Here

    /*
     * @see org.eclipse.jetty.server.server.Handler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)
     */
    public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
    {
        AbstractHttpConnection connection = AbstractHttpConnection.getCurrentConnection();
        connection.getRequest().setHandled(true);
        String method = request.getMethod();
        if(!method.equals(HttpMethods.GET) && !method.equals(HttpMethods.POST) && !method.equals(HttpMethods.HEAD))
            return;
        response.setContentType(MimeTypes.TEXT_HTML_8859_1);   
        if (_cacheControl!=null)
            response.setHeader(HttpHeaders.CACHE_CONTROL, _cacheControl);
        ByteArrayISO8859Writer writer= new ByteArrayISO8859Writer(4096);
        handleErrorPage(request, writer, connection.getResponse().getStatus(), connection.getResponse().getReason());
        writer.flush();
        response.setContentLength(writer.size());
        writer.writeTo(response.getOutputStream());
        writer.destroy();
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jetty.server.AbstractHttpConnection

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.