Search in sources :

Example 1 with EndPoint

use of org.eclipse.jetty.io.EndPoint in project jetty.project by eclipse.

the class HttpConnectionOverFCGI method process.

private void process(ByteBuffer buffer) {
    try {
        EndPoint endPoint = getEndPoint();
        boolean looping = false;
        while (true) {
            if (!looping && parse(buffer))
                return;
            int read = endPoint.fill(buffer);
            if (LOG.isDebugEnabled())
                LOG.debug("Read {} bytes from {}", read, endPoint);
            if (read > 0) {
                if (parse(buffer))
                    return;
            } else if (read == 0) {
                releaseBuffer(buffer);
                fillInterested();
                return;
            } else {
                releaseBuffer(buffer);
                shutdown();
                return;
            }
            looping = true;
        }
    } catch (Exception x) {
        if (LOG.isDebugEnabled())
            LOG.debug(x);
        releaseBuffer(buffer);
        close(x);
    }
}
Also used : EndPoint(org.eclipse.jetty.io.EndPoint) EndPoint(org.eclipse.jetty.io.EndPoint) AsynchronousCloseException(java.nio.channels.AsynchronousCloseException) TimeoutException(java.util.concurrent.TimeoutException) EOFException(java.io.EOFException)

Example 2 with EndPoint

use of org.eclipse.jetty.io.EndPoint in project jetty.project by eclipse.

the class SocketCustomizationListener method onOpened.

@Override
public void onOpened(Connection connection) {
    EndPoint endp = connection.getEndPoint();
    boolean ssl = false;
    if (_ssl && endp instanceof DecryptedEndPoint) {
        endp = ((DecryptedEndPoint) endp).getSslConnection().getEndPoint();
        ssl = true;
    }
    if (endp instanceof SocketChannelEndPoint) {
        Socket socket = ((SocketChannelEndPoint) endp).getSocket();
        customize(socket, connection.getClass(), ssl);
    }
}
Also used : DecryptedEndPoint(org.eclipse.jetty.io.ssl.SslConnection.DecryptedEndPoint) SocketChannelEndPoint(org.eclipse.jetty.io.SocketChannelEndPoint) DecryptedEndPoint(org.eclipse.jetty.io.ssl.SslConnection.DecryptedEndPoint) EndPoint(org.eclipse.jetty.io.EndPoint) SocketChannelEndPoint(org.eclipse.jetty.io.SocketChannelEndPoint) Socket(java.net.Socket)

Example 3 with EndPoint

use of org.eclipse.jetty.io.EndPoint in project jetty.project by eclipse.

the class SslConnectionFactory method newConnection.

@Override
public Connection newConnection(Connector connector, EndPoint endPoint) {
    SSLEngine engine = _sslContextFactory.newSSLEngine(endPoint.getRemoteAddress());
    engine.setUseClientMode(false);
    SslConnection sslConnection = newSslConnection(connector, endPoint, engine);
    sslConnection.setRenegotiationAllowed(_sslContextFactory.isRenegotiationAllowed());
    configure(sslConnection, connector, endPoint);
    ConnectionFactory next = connector.getConnectionFactory(_nextProtocol);
    EndPoint decryptedEndPoint = sslConnection.getDecryptedEndPoint();
    Connection connection = next.newConnection(connector, decryptedEndPoint);
    decryptedEndPoint.setConnection(connection);
    return sslConnection;
}
Also used : SslConnection(org.eclipse.jetty.io.ssl.SslConnection) SSLEngine(javax.net.ssl.SSLEngine) Connection(org.eclipse.jetty.io.Connection) AbstractConnection(org.eclipse.jetty.io.AbstractConnection) SslConnection(org.eclipse.jetty.io.ssl.SslConnection) EndPoint(org.eclipse.jetty.io.EndPoint)

Example 4 with EndPoint

use of org.eclipse.jetty.io.EndPoint in project jetty.project by eclipse.

the class IPAccessHandler method handle.

/* ------------------------------------------------------------ */
/**
     * Checks the incoming request against the whitelist and blacklist
     *
     * @see org.eclipse.jetty.server.handler.HandlerWrapper#handle(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    // Get the real remote IP (not the one set by the forwarded headers (which may be forged))
    HttpChannel channel = baseRequest.getHttpChannel();
    if (channel != null) {
        EndPoint endp = channel.getEndPoint();
        if (endp != null) {
            InetSocketAddress address = endp.getRemoteAddress();
            if (address != null && !isAddrUriAllowed(address.getHostString(), baseRequest.getPathInfo())) {
                response.sendError(HttpStatus.FORBIDDEN_403);
                baseRequest.setHandled(true);
                return;
            }
        }
    }
    getHandler().handle(target, baseRequest, request, response);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) HttpChannel(org.eclipse.jetty.server.HttpChannel) EndPoint(org.eclipse.jetty.io.EndPoint)

Example 5 with EndPoint

use of org.eclipse.jetty.io.EndPoint in project jetty.project by eclipse.

the class HttpSenderOverHTTP method sendContent.

@Override
protected void sendContent(HttpExchange exchange, HttpContent content, Callback callback) {
    try {
        HttpClient client = getHttpChannel().getHttpDestination().getHttpClient();
        ByteBufferPool bufferPool = client.getByteBufferPool();
        ByteBuffer chunk = null;
        while (true) {
            ByteBuffer contentBuffer = content.getByteBuffer();
            boolean lastContent = content.isLast();
            HttpGenerator.Result result = generator.generateRequest(null, null, chunk, contentBuffer, lastContent);
            if (LOG.isDebugEnabled())
                LOG.debug("Generated content ({} bytes) - {}/{}", contentBuffer == null ? -1 : contentBuffer.remaining(), result, generator);
            switch(result) {
                case NEED_CHUNK:
                    {
                        chunk = bufferPool.acquire(HttpGenerator.CHUNK_SIZE, false);
                        break;
                    }
                case FLUSH:
                    {
                        EndPoint endPoint = getHttpChannel().getHttpConnection().getEndPoint();
                        if (chunk != null)
                            endPoint.write(new ByteBufferRecyclerCallback(callback, bufferPool, chunk), chunk, contentBuffer);
                        else
                            endPoint.write(callback, contentBuffer);
                        return;
                    }
                case SHUTDOWN_OUT:
                    {
                        shutdownOutput();
                        break;
                    }
                case CONTINUE:
                    {
                        if (lastContent)
                            break;
                        callback.succeeded();
                        return;
                    }
                case DONE:
                    {
                        callback.succeeded();
                        return;
                    }
                default:
                    {
                        throw new IllegalStateException(result.toString());
                    }
            }
        }
    } catch (Throwable x) {
        if (LOG.isDebugEnabled())
            LOG.debug(x);
        callback.failed(x);
    }
}
Also used : ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) HttpClient(org.eclipse.jetty.client.HttpClient) EndPoint(org.eclipse.jetty.io.EndPoint) HttpGenerator(org.eclipse.jetty.http.HttpGenerator) ByteBuffer(java.nio.ByteBuffer)

Aggregations

EndPoint (org.eclipse.jetty.io.EndPoint)42 Test (org.junit.Test)19 IOException (java.io.IOException)11 ByteBuffer (java.nio.ByteBuffer)10 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)9 SSLEngine (javax.net.ssl.SSLEngine)8 ServletException (javax.servlet.ServletException)8 WebSocketSession (org.eclipse.jetty.websocket.common.WebSocketSession)8 InputStream (java.io.InputStream)7 Socket (java.net.Socket)7 ByteBufferPool (org.eclipse.jetty.io.ByteBufferPool)7 SocketChannelEndPoint (org.eclipse.jetty.io.SocketChannelEndPoint)7 OutputStream (java.io.OutputStream)6 SslConnection (org.eclipse.jetty.io.ssl.SslConnection)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 HttpClientTransportOverHTTP (org.eclipse.jetty.client.http.HttpClientTransportOverHTTP)5 Connector (org.eclipse.jetty.server.Connector)5 ServerConnector (org.eclipse.jetty.server.ServerConnector)5