Skip to content

The target server failed to respond #145

Open
@anthonygauthier

Description

@anthonygauthier

Hi so I'm developing a plugin for JMeter that uses fluent-http as a web server to expose a REST API.

I'm currently unable to consume any URL, the server is started on the right port - I was able to check that out with a simple telnet. However, it never sends a response. I've been trying to figure out the problem by reading the documentation but no luck.

Here's my sample code:

public class App {
    private WebServer instance;
    private int port;
    private JMeterContext jMeterContext;

    public App(int p, JMeterContext jc) {
        this.instance = new WebServer().configure(routes -> routes
            .get("/test", new Payload("application/json","{\"hello\":\"world!\"}", 200))
        );
        this.port = p;
        this.jMeterContext = jc;
    }

    /**
     *  Methods to start or stop the API
     */
    public void start() {
        this.instance.start(this.port);
    }

    public void stop() {
        this.instance.stop();
    }
}

Here's my unit test to check the connectivity:

public class TestAppServer {
    private static int PORT = 8080;
    private static String APP_ADDRESS = "http://localhost:" + PORT;

    private App server;

    @Before
    public void startTest() throws Exception {
        this.server = new App(PORT, null);
        this.server.start();
    }

    @Test
    public void testServerConnectivity() throws Exception {
        HttpResponse<JsonNode> response = Unirest.get(APP_ADDRESS + "/test").asJson();
        assertTrue(response.getBody().toString().contains("world"));
    }

    @After
    public void stopTest() throws Exception {
        this.server.stop();
    }
}

Any chance anyone could help me pinpoint the issue here? It's for sure something stupid on my end!

Thanks,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions