I want use mockserver to mock request and response. For that I am using mockserver docker image. Following is then docker-compose file example where use mockserver.
mockServer:
image: mockserver/mockserver
container_name: mockhttpserver
ports:
- 1080:1080
Now in order to add expectations. I am using following mockserver java client.
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-client-java</artifactId>
<version>5.11.2</version>
</dependency>
Following is my java code to create mockserverclient and add expections. but when I am running this code its giving me SockedTimeout Exception. Don’t now what wrong with that. Mockserver is running as container and when I telnet to mylocalhost.org 1080 then it successfully return connected but from eclipse it throws exceptions.
MockServerClient client = new MockServerClient("mylocalhost.org", 1080);
client.upsert(
Expectation.when(HttpRequest.request("/login")
.withMethod("get"))
.thenRespond(HttpResponse.response().withStatusCode(200)));
client.close();
Exception :
8:11:18.768 [MockServer-MockServerClient-eventLoop0] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16
08:11:18.768 [MockServer-MockServerClient-eventLoop0] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8
Exception in thread "main" org.mockserver.client.SocketCommunicationException: Response was not received from MockServer after 20000 milliseconds, to wait longer please use "mockserver.maxSocketTimeout" system property or ConfigurationProperties.maxSocketTimeout(long milliseconds)
at org.mockserver.client.NettyHttpClient.sendRequest(NettyHttpClient.java:172)
at org.mockserver.client.MockServerClient.sendRequest(MockServerClient.java:211)
at org.mockserver.client.MockServerClient.sendRequest(MockServerClient.java:244)
at org.mockserver.client.MockServerClient.upsert(MockServerClient.java:1109)