Process the opening handshake initiated by {@link #handshake}}.

@param channel
Channel
@param response
HTTP response containing the closing handshake details
@return future
the {@link ChannelFuture} which is notified once the handshake completes.
18362
public final ChannelFuture processHandshake(final Channel channel, HttpResponse response) {
        return processHandshake(channel, response, channel.newPromise());
    }
206477
public void processResponse(ResponseEvent arg0) {
    synchronized (listeners) {
      if (((ResponseEventExt) arg0).isRetransmission())
        retransmissions++;
      Iterator iter = listeners.iterator();
      while (iter.hasNext() == true) {
        SipListener listener = (SipListener) iter.next();
        listener.processResponse(arg0);
      }
    }
  }
925680
private void handleWebSocketHandshake(FullHttpRequest fullHttpRequest, ChannelHandlerContext ctx)
            throws WebSocketConnectorException {
        String extensionsHeader = fullHttpRequest.headers().getAsString(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS);
        DefaultWebSocketHandshaker webSocketHandshaker =
                new DefaultWebSocketHandshaker(ctx, serverConnectorFuture, fullHttpRequest, fullHttpRequest.uri(),
                                               extensionsHeader != null);

        // Setting common properties to handshaker
        webSocketHandshaker.setHttpCarbonRequest(setupHttpCarbonRequest(fullHttpRequest, ctx));

        ctx.channel().config().setAutoRead(false);
        serverConnectorFuture.notifyWebSocketListener(webSocketHandshaker);
    }
605850
@SuppressWarnings("unchecked")
    @Override
    protected void afterHandle(final Request request, final Response response)
    {
        super.afterHandle(request, response);
        
        final ConcurrentMap<String, Object> responseAttributes = response.getAttributes();
        
        Series<Header> responseHeaders = (Series<Header>)responseAttributes.get(HeaderConstants.ATTRIBUTE_HEADERS);
        
        if(responseHeaders == null)
        {
            responseHeaders = new Series<Header>(Header.class);
            final Series<Header> putIfAbsent =
                    (Series<Header>)responseAttributes.putIfAbsent(HeaderConstants.ATTRIBUTE_HEADERS, responseHeaders);
            
            if(putIfAbsent != null)
            {
                responseHeaders = putIfAbsent;
            }
        }
        
        // Allow all origins
        responseHeaders.add("Access-Control-Allow-Origin", "*");
    }
829540
public ResponseOnSingeRequest executeAndGenResponse(ChannelExec channel) {
        ResponseOnSingeRequest sshResponse = new ResponseOnSingeRequest();

        InputStream in = null;
        OutputStream outputStreamStdErr = new ByteArrayOutputStream();
        StringBuilder sbStdOut = new StringBuilder();
        try {

            in = channel.getInputStream();
            channel.setErrStream(outputStreamStdErr);

            byte[] tmp = new byte[ParallecGlobalConfig.sshBufferSize];
            while (true) {
                while (in.available() > 0) {
                    int i = in.read(tmp, 0, ParallecGlobalConfig.sshBufferSize);
                    if (i < 0)
                        break;
                    sbStdOut.append(new String(tmp, 0, i));

                }

                if (channel.isClosed()) {
                    if (in.available() > 0)
                        continue;
                    sshResponse.setFailObtainResponse(false);

                    // exit 0 is good
                    int exitStatus = channel.getExitStatus();
                    sshResponse.setStatusCodeInt(exitStatus);
                    sshResponse.setStatusCode(Integer.toString(exitStatus));
                    break;
                }

                Thread.sleep(ParallecGlobalConfig.sshSleepMIllisBtwReadBuffer);
            }

            sshResponse.setResponseBody(sbStdOut.toString());
            sshResponse.setErrorMessage(outputStreamStdErr.toString());
            sshResponse.setReceiveTimeNow();
        } catch (Exception t) {
            throw new RuntimeException(t);
        }

        return sshResponse;
    }
829828
private void setHandshakeSuccess() {
        handshakePromise.trySuccess(ctx.channel());

        if (logger.isDebugEnabled()) {
            logger.debug("{} HANDSHAKEN: {}", ctx.channel(), engine.getSession().getCipherSuite());
        }
        ctx.fireUserEventTriggered(SslHandshakeCompletionEvent.SUCCESS);

        if (readDuringHandshake && !ctx.channel().config().isAutoRead()) {
            readDuringHandshake = false;
            ctx.read();
        }
    }
296799
public Future<Channel> renegotiate(final Promise<Channel> promise) {
        if (promise == null) {
            throw new NullPointerException("promise");
        }

        ChannelHandlerContext ctx = this.ctx;
        if (ctx == null) {
            throw new IllegalStateException();
        }

        EventExecutor executor = ctx.executor();
        if (!executor.inEventLoop()) {
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    renegotiateOnEventLoop(promise);
                }
            });
            return promise;
        }

        renegotiateOnEventLoop(promise);
        return promise;
    }
269648
protected ChannelFuture handleHandshake(ChannelHandlerContext ctx, NettyHttpRequest req, WebSocketBean<?> webSocketBean, MutableHttpResponse<?> response) {
        int maxFramePayloadLength = webSocketBean.messageMethod().flatMap(m -> m.getValue(OnMessage.class, "maxPayloadLength", Integer.class)).orElse(65536);
        WebSocketServerHandshakerFactory wsFactory =
                new WebSocketServerHandshakerFactory(
                        getWebSocketURL(ctx, req),
                        null,
                        true,
                        maxFramePayloadLength
                );
        handshaker = wsFactory.newHandshaker(req.getNativeRequest());
        MutableHttpHeaders headers = response.getHeaders();
        io.netty.handler.codec.http.HttpHeaders nettyHeaders;
        if (headers instanceof NettyHttpHeaders) {
            nettyHeaders = ((NettyHttpHeaders) headers).getNettyHeaders();
        } else {
            nettyHeaders = new DefaultHttpHeaders();
            for (Map.Entry<String, List<String>> entry : headers) {
                nettyHeaders.add(entry.getKey(), entry.getValue());
            }
        }
        Channel channel = ctx.channel();
        if (handshaker == null) {
            return WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(channel);
        } else {
            return handshaker.handshake(
                    channel,
                    req.getNativeRequest(),
                    nettyHeaders,
                    channel.newPromise()
            );
        }
    }
186947
@Override
  public void channelInactive(ChannelHandlerContext ctx) {
    Status status = Status.UNAVAILABLE.withDescription(
        "Connection closed while performing protocol negotiation for " + ctx.pipeline().names());
    failWrites(status.asRuntimeException());
  }
764005
public ClientHandshakeFuture handshake() {
        final DefaultClientHandshakeFuture handshakeFuture = new DefaultClientHandshakeFuture();
        try {
            URI uri = new URI(url);

            String scheme = uri.getScheme();
            if (!Constants.WS_SCHEME.equalsIgnoreCase(scheme) && !Constants.WSS_SCHEME.equalsIgnoreCase(scheme)) {
                LOG.error("Only WS(S) is supported.");
                throw new URISyntaxException(url, "WebSocket client supports only WS(S) scheme");
            }

            final String host = uri.getHost() == null ? "127.0.0.1" : uri.getHost();
            final int port = getPort(uri);
            final boolean ssl = Constants.WSS_SCHEME.equalsIgnoreCase(scheme);
            WebSocketClientHandshaker webSocketHandshaker = WebSocketClientHandshakerFactory.newHandshaker(
                    uri, WebSocketVersion.V13, subProtocols, true, headers, maxFrameSize);
            MessageQueueHandler messageQueueHandler = new MessageQueueHandler();
            clientHandshakeHandler = new WebSocketClientHandshakeHandler(webSocketHandshaker, handshakeFuture,
                                                                         messageQueueHandler, ssl, autoRead, url,
                                                                         handshakeFuture);
            Bootstrap clientBootstrap = initClientBootstrap(host, port, handshakeFuture);
            clientBootstrap.connect(uri.getHost(), port).sync();
        } catch (Exception throwable) {
            handleHandshakeError(handshakeFuture, throwable);
        }
        return handshakeFuture;
    }
1310197
@Override
    public void processConnect(WebSocketChannel channel, WSURI location, String[] protocols) {
        LOG.entering(CLASS_NAME, "connect", channel);

        nextHandler.processConnect(channel, location, protocols);
    }
292970
@Override
    public void process(Request request, Response response)
    {
		if (!response.hasHeader(CORRELATION_ID))
		{
			response.addHeader(CORRELATION_ID, request.getHeader(CORRELATION_ID));
		}
    }
1049042
private static <V> ListenableFuture<V> closedChannelFuture() {
    SettableFuture<V> future = SettableFuture.create();
    future.setException(new ClosedChannelException());
    return future;
  }
616005
@Override
    public void processConnect(WebSocketChannel channel, WSURI uri, String[] protocols) {
        LOG.entering(CLASS_NAME, "connect", new Object[] { uri, protocols });
        WebSocketNativeChannel wsChannel = (WebSocketNativeChannel)channel;
        wsChannel.balanced.set(0);
        nextHandler.processConnect(channel, uri.addQueryParameter(".kl=Y"), protocols);
    }
1327590
@Override
    public void handle(T result, HttpResponse response) {
        String transitionHeader = response.getHeaders().get(Headers.IBM_TRANSITION);
        if (transitionHeader != null) {
            result.setTransitionDate(parseDate(transitionHeader));
            String transition = parseTransition(transitionHeader);
            if (transition != null) {
                result.setTransition(transition);
            }
        }
    }
382684
@Override
    public void openChannel(FutureCallback<Channel> callback) throws IllegalStateException {
        assertOpen();

        ChannelFuture future = this.bootstrap.clone().register();
        future.addListener(new NetworkManagerChannelFutureCallback(callback));
    }
962679
protected void handleHttpRequest(final ChannelHandlerContext channelContext, final HttpRequest request) throws Exception {
        if (isWebSocketsUpgradeRequest( request )) {

            final Handshake handshake = findHandshake( request );

            if (handshake != null) {

                HttpResponse response = handshake.generateResponse( request );

                response.addHeader( Names.UPGRADE, Values.WEBSOCKET );
                response.addHeader( Names.CONNECTION, Values.UPGRADE );

                final ChannelPipeline pipeline = channelContext.getChannel().getPipeline();
                reconfigureUpstream( pipeline, handshake );

                Channel channel = channelContext.getChannel();
                ChannelFuture future = channel.write( response );
                future.addListener( new ChannelFutureListener() {
                    public void operationComplete(ChannelFuture future) throws Exception {
                        reconfigureDownstream( pipeline, handshake );
                        pipeline.replace( ServerHandshakeHandler.this, "websocket-disconnection-negotiator", new WebSocketDisconnectionNegotiator() );
                        forwardConnectEventUpstream( channelContext );
                        decodeHost( channelContext, request );
                        decodeSession( channelContext, request );
                    }
                } );

                return;
            }
        }

        // Send an error page otherwise.
        sendHttpResponse( channelContext, request, new DefaultHttpResponse( HttpVersion.HTTP_1_1, HttpResponseStatus.FORBIDDEN ) );
    }