Roar Skullestad
Roar Skullestad

Reputation: 2437

Apache Camel http mock testing fails with Connection refused

I am testing this Camel route:

  from("direct:start")
    .setHeader(Exchange.HTTP_METHOD, constant("GET"))
    .to("http://127.0.0.1:8088/")
    .to("mock:result");

...using this mock server:

mockServer = MockRestServiceServer.createServer(new RestTemplate());

mockServer.expect(
    requestTo("http://127.0.0.1:8088/"))
    .andExpect(method(HttpMethod.GET))
    .andRespond(withStatus(HttpStatus.OK)
        .contentType(MediaType.APPLICATION_JSON)
        .body("")
     );

...but receive:

I/O exception (java.net.ConnectException) caught when processing request: Connection refused: connect

Are there anything obvious I am missing? How can I proceed to find the cause?

Upvotes: 1

Views: 874

Answers (1)

Bedla
Bedla

Reputation: 4919

You cannot use MockRestServiceServer. This does not start real server and therefore can be used only for mocking responses to Spring RestTemplate. Apache Camel does not utilize RestTemplate for sending requests, it uses Apache HttpClient.

You can either:

Upvotes: 2

Related Questions