Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The target server failed to respond #145

Open
anthonygauthier opened this issue Sep 6, 2018 · 0 comments
Open

The target server failed to respond #145

anthonygauthier opened this issue Sep 6, 2018 · 0 comments

Comments

@anthonygauthier
Copy link

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,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant