Search in sources :

Example 1 with DashboardWebSocketHandler

use of org.mockserver.dashboard.DashboardWebSocketHandler in project mockserver by mock-server.

the class PortUnificationHandler method switchToHttp.

private void switchToHttp(ChannelHandlerContext ctx, ByteBuf msg) {
    ChannelPipeline pipeline = ctx.pipeline();
    addLastIfNotPresent(pipeline, new HttpServerCodec(configuration.maxInitialLineLength(), configuration.maxHeaderSize(), configuration.maxChunkSize()));
    addLastIfNotPresent(pipeline, new HttpContentDecompressor());
    addLastIfNotPresent(pipeline, httpContentLengthRemover);
    addLastIfNotPresent(pipeline, new HttpObjectAggregator(Integer.MAX_VALUE));
    if (configuration.tlsMutualAuthenticationRequired() && !isSslEnabledUpstream(ctx.channel())) {
        HttpResponse httpResponse = response().withStatusCode(426).withHeader("Upgrade", "TLS/1.2, HTTP/1.1").withHeader("Connection", "Upgrade");
        if (MockServerLogger.isEnabled(Level.INFO)) {
            mockServerLogger.logEvent(new LogEntry().setLogLevel(Level.INFO).setMessageFormat("no tls for connection:{}returning response:{}").setArguments(ctx.channel().localAddress(), httpResponse));
        }
        ctx.channel().writeAndFlush(mockServerHttpResponseToFullHttpResponse.mapMockServerResponseToNettyResponse(// Upgrade Required
        httpResponse).get(0)).addListener((ChannelFuture future) -> future.channel().disconnect().awaitUninterruptibly());
    } else {
        addLastIfNotPresent(pipeline, new CallbackWebSocketServerHandler(httpState));
        addLastIfNotPresent(pipeline, new DashboardWebSocketHandler(httpState, isSslEnabledUpstream(ctx.channel()), false));
        addLastIfNotPresent(pipeline, new MockServerHttpServerCodec(configuration, mockServerLogger, isSslEnabledUpstream(ctx.channel()), ctx.channel().localAddress(), SniHandler.retrieveClientCertificates(mockServerLogger, ctx)));
        addLastIfNotPresent(pipeline, new HttpRequestHandler(configuration, server, httpState, actionHandler));
        pipeline.remove(this);
        ctx.channel().attr(LOCAL_HOST_HEADERS).set(getLocalAddresses(ctx));
        // fire message back through pipeline
        ctx.fireChannelRead(msg.readBytes(actualReadableBytes()));
    }
}
Also used : HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) CallbackWebSocketServerHandler(org.mockserver.netty.websocketregistry.CallbackWebSocketServerHandler) HttpRequestHandler(org.mockserver.netty.HttpRequestHandler) MockServerHttpServerCodec(org.mockserver.codec.MockServerHttpServerCodec) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) HttpResponse(org.mockserver.model.HttpResponse) MockServerHttpResponseToFullHttpResponse(org.mockserver.mappers.MockServerHttpResponseToFullHttpResponse) DashboardWebSocketHandler(org.mockserver.dashboard.DashboardWebSocketHandler) LogEntry(org.mockserver.log.model.LogEntry) HttpContentDecompressor(io.netty.handler.codec.http.HttpContentDecompressor) MockServerHttpServerCodec(org.mockserver.codec.MockServerHttpServerCodec)

Aggregations

HttpContentDecompressor (io.netty.handler.codec.http.HttpContentDecompressor)1 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)1 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)1 MockServerHttpServerCodec (org.mockserver.codec.MockServerHttpServerCodec)1 DashboardWebSocketHandler (org.mockserver.dashboard.DashboardWebSocketHandler)1 LogEntry (org.mockserver.log.model.LogEntry)1 MockServerHttpResponseToFullHttpResponse (org.mockserver.mappers.MockServerHttpResponseToFullHttpResponse)1 HttpResponse (org.mockserver.model.HttpResponse)1 HttpRequestHandler (org.mockserver.netty.HttpRequestHandler)1 CallbackWebSocketServerHandler (org.mockserver.netty.websocketregistry.CallbackWebSocketServerHandler)1