Package org.glassfish.grizzly

Examples of org.glassfish.grizzly.Connection$CloseListener


    @SuppressWarnings("unchecked")
    public NextAction handleRead(FilterChainContext ctx) throws IOException {
        // Get the parsed HttpContent (we assume prev. filter was HTTP)
        final HttpContent message = ctx.getMessage();

        final Connection grizzlyConnection = ctx.getConnection();
        final org.glassfish.tyrus.spi.Connection tyrusConnection = TYRUS_CONNECTION.get(grizzlyConnection);

        // Get the HTTP header
        final HttpHeader header = message.getHttpHeader();
View Full Code Here


                    connectionGrizzlyFuture = connectorHandler.connect(address);
                    break;
            }

            try {
                final Connection connection = connectionGrizzlyFuture.get(timeoutMs, TimeUnit.MILLISECONDS);

                LOGGER.log(Level.CONFIG, String.format("Connected to '%s'.", connection.getPeerAddress()));
                return;
            } catch (InterruptedException interruptedException) {
                LOGGER.log(Level.CONFIG, String.format("Connection to '%s' failed.", uri), interruptedException);
                closeTransport(privateTransport);
            } catch (TimeoutException timeoutException) {
View Full Code Here

        final UpgradeResponse upgradeResponse = new TyrusUpgradeResponse();
        final WebSocketEngine.UpgradeInfo upgradeInfo = serverContainer.getWebSocketEngine().upgrade(upgradeRequest, upgradeResponse);

        switch (upgradeInfo.getStatus()) {
            case SUCCESS:
                final Connection grizzlyConnection = ctx.getConnection();
                write(ctx, upgradeRequest, upgradeResponse);

                final org.glassfish.tyrus.spi.Connection connection = upgradeInfo.createConnection(new GrizzlyWriter(ctx.getConnection()), new org.glassfish.tyrus.spi.Connection.CloseListener() {
                    @Override
                    public void close(CloseReason reason) {
                        grizzlyConnection.close();
                    }
                });

                TYRUS_CONNECTION.set(grizzlyConnection, connection);

                grizzlyConnection.addCloseListener(new CloseListener() {
                    @Override
                    public void onClosed(Closeable closeable, ICloseType type) throws IOException {
                        connection.close(new CloseReason(CloseReason.CloseCodes.GOING_AWAY, "Close detected on connection"));
                        // might not be necessary, connection is going to be recycled/freed anyway
                        TYRUS_CONNECTION.remove(grizzlyConnection);
View Full Code Here

        return ctx.getStopAction();
    }

    @Override
    public NextAction handleClose(final FilterChainContext ctx) throws IOException {
        final Connection connection = ctx.getConnection();
        final SelectionKey selectionKey = ((NIOConnection) connection).getSelectionKey();

        try {
            if (connector != null) {
                connector.notifyConnectionClosed((SocketChannel) selectionKey.channel());
View Full Code Here

            // Check to see if the ProtocolNegotiator has given
            // us a different FilterChain to use. If so, we need
            // use a different FilterChainContext when invoking sendRequest().
            sendingCtx = checkAndHandleFilterChainUpdate(ctx, sendingCtx);
        }
        final Connection c = ctx.getConnection();
        final HttpContext httpCtx;
        if (!Utils.isSpdyConnection(c)) {
            httpCtx = HttpContext.newInstance(c, c, c, requestPacketLocal);
        } else {
            SpdySession session = SpdySession.get(c);
View Full Code Here

        } else {
            throw new IllegalStateException("Unsupported authorization method: " + auth);
        }

        try {
            final Connection c = getConnectionForNextRequest(ctx, req, responsePacket, httpTransactionContext);
            final HttpTxContext newContext = httpTransactionContext.copy();
            httpTransactionContext.setFuture(null);
            HttpTxContext.set(ctx, newContext);
            newContext.setInvocationStatus(STOP);
            httpTransactionContext.getProvider().execute(c, req, httpTransactionContext.getHandler(), httpTransactionContext.getFuture(),
View Full Code Here

            return true;
        }

        final ConnectionManager m = httpTransactionContext.getProvider().getConnectionManager();
        try {
            final Connection c = m.obtainConnection(requestToSend, httpTransactionContext.getFuture());
            final HttpTxContext newContext = httpTransactionContext.copy();
            httpTransactionContext.setFuture(null);
            newContext.setInvocationStatus(CONTINUE);
            newContext.setRequest(requestToSend);
            newContext.setRequestUri(requestToSend.getUri());
View Full Code Here

        // Suspend further handleConnect processing.  We do this to ensure that
        // the SSL handshake has been completed before returning the connection
        // for use in processing user requests.  Additionally, this allows us
        // to determine if a connection is SPDY or HTTP as early as possible.
        ctx.suspend();
        final Connection c = ctx.getConnection();
        handshake(ctx.getConnection(), new EmptyCompletionHandler<SSLEngine>() {
            @Override
            public void completed(SSLEngine result) {
                // Handshake was successful.  Resume the handleConnect
                // processing.  We pass in Invoke Action so the filter
View Full Code Here

        try {
            if (isNTLMFirstHandShake(proxyAuth)) {
                tempInvocationStatus = InvocationStatus.CONTINUE;
            }
            if (proxyAuth.toLowerCase().startsWith("negotiate")) {
                final Connection c = getConnectionForNextRequest(ctx, req, responsePacket, httpTransactionContext);
                final HttpTxContext newContext = httpTransactionContext.copy();
                httpTransactionContext.setFuture(null);
                HttpTxContext.set(ctx, newContext);

                newContext.setInvocationStatus(tempInvocationStatus);

                String challengeHeader;
                String server = proxyServer.getHost();

                challengeHeader = GSSSPNEGOWrapper.generateToken(server);

                req.getHeaders().add(Header.ProxyAuthorization.toString(), "Negotiate " + challengeHeader);

                return executeRequest(httpTransactionContext, req, c, newContext);
            } else if (isNTLMSecondHandShake(proxyAuth)) {
                final Connection c = ctx.getConnection();
                final HttpTxContext newContext = httpTransactionContext.copy();

                httpTransactionContext.setFuture(null);
                HttpTxContext.set(ctx, newContext);

                newContext.setInvocationStatus(tempInvocationStatus);

                return executeRequest(httpTransactionContext, req, c, newContext);

            } else {
                final Connection c = getConnectionForNextRequest(ctx, req, responsePacket, httpTransactionContext);
                final HttpTxContext newContext = httpTransactionContext.copy();
                httpTransactionContext.setFuture(null);
                HttpTxContext.set(ctx, newContext);

                newContext.setInvocationStatus(tempInvocationStatus);
View Full Code Here

    }

    public Connection obtainConnection(final Request request, final GrizzlyResponseFuture requestFuture) throws ExecutionException,
            InterruptedException, TimeoutException, IOException {

        final Connection c = obtainConnection0(request, requestFuture);
        markConnectionAsDoNotCache(c);
        return c;

    }
View Full Code Here

TOP

Related Classes of org.glassfish.grizzly.Connection$CloseListener

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.