mock-server / mockserver

MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby. MockServer also includes a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding).
http://mock-server.com
Apache License 2.0
4.54k stars 1.06k forks source link

NoHttpResponseException with request forwarding #832

Closed lxp1250 closed 2 years ago

lxp1250 commented 3 years ago

I am using 5.11.1 version and observed the same issue. I would like to know why this happens and what could be the fix.

` public class MockServerExample {

/* Set up service endpoint */
public static String HOST = "127.0.0.1";
public static int PORT = 1080;

public static void start() {
        startClientAndServer(PORT);
        createExpectations();
}

private static void createExpectation() {

        new MockServerClient(HOST, PORT)
                .when(
                        request()
                                .withPath("/path1/ping")
                )
                .forward(
                        forward()
                                .withHost("127.0.0.1")
                                .withPort(9000)
                );

        new MockServerClient(HOST, PORT)
                .when(
                        request()
                                .withPath("/path2")
                )
                .forward(
                        forwardOverriddenRequest(
                                request()
                                        .withPath("/path2")
                                        .withSocketAddress("127.0.0.1", 60000, SocketAddress.Scheme.HTTP)
                        )
                );`

It is basically testing request forwarding. Upon receiving the request, it forwards to localhost:60000 with same path. In the @beforeClass, it calls start().

The error I got is: DEBUG 19:36:31.880 [main] o.a.http.impl.execchain.RetryExec: The target server failed to respond ! org.apache.http.NoHttpResponseException: The target server failed to respond ! at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:141) ~[httpclient-4.5.9.jar:4.5.9] ! at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56) ~[httpclient-4.5.9.jar:4.5.9] ! at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259) ~[httpcore-4.4.11.jar:4.4.11] ...

lxp1250 commented 3 years ago

I verified if I change the forward to response, mocked server is able to return response successfully.

jamesdbloom commented 2 years ago

It looks like the problem is that there is nothing listening on 127.0.0.1:6000.