3

I receive following exception when running a local mock server in eclipse and trying to connect with a client:

org.mockserver.client.SocketConnectionException: Channel set as inactive before valid response has been received at org.mockserver.client.HttpClientConnectionHandler.updatePromise(HttpClientConnectionHandler.java:18) at org.mockserver.client.HttpClientConnectionHandler.channelInactive(HttpClientConnectionHandler.java:24) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:257) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:243) at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:236) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelInactive(DefaultChannelPipeline.java:1403) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:257) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:243) at io.netty.channel.DefaultChannelPipeline.fireChannelInactive(DefaultChannelPipeline.java:912) at io.netty.channel.AbstractChannel$AbstractUnsafe$8.run(AbstractChannel.java:827) at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:405) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:906) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.lang.Thread.run(Unknown Source)

Following code is used to start the server:

public class RestApiTests {

    private ClientAndServer mockServer;

    @BeforeClass
    public void init() {
        startServer();
    }

    private void startServer() {
        mockServer = org.mockserver.integration.ClientAndServer.startClientAndServer(1080);
        try (MockServerClient client = new MockServerClient("localhost", 1080)) {
            client.when(HttpRequest.request().withMethod("GET").withPath("/429"))
                    .respond(request -> HttpResponse.response().withHeaders(Header.header("Content-Type", "text/plain"),
                            Header.header("X-RateLimit-Reset",
                                    String.valueOf(System.currentTimeMillis() * 1000 + new Random().nextInt(999))))
                            .withStatusCode(429));
        }
    }
}

Excerpt of my build.gradle:

dependencies {
    testCompile group: 'org.mock-server', name: 'mockserver-netty', version: '5.6.1'
    testCompile group: 'org.mock-server', name: 'mockserver-client-java', version: '5.6.1'
}

The exception occurs when using the client. A colleague is executing this code successfully in intelliJ. Waiting a few seconds before calling the constructor did not change anything.


Edit

Found the underlying exception (still not sure what causes this):

org.apache.http.NoHttpResponseException: localhost:1080 failed to respond at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:141) at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56) at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259)

4

0 回答 0