MockServer is a mock HTTP server that enables easy mocking of any system you integrate with via HTTP or HTTPS (i.e. services, web sites, etc) 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).
jamesdbloom on master
downgrading jersey version due … (compare)
dependabot[bot] on maven
Bump jetty.version from 9.4.35.… (compare)
Hello Mockserver community.
I would like to know if it is possible to build a Mockserver Expectation where a value of the HTTP Response can be dynamically created based on a value from the HTTP Request. I'm thinking something like capturing a regex match from the request and putting that captured value into the response.
My use case is that I want to match all requests to a particular route, but I want to capture the query parameters. I then want to be able to have these query parameters stored in an HTTP header in my response (in my specific case, the Location
header).
Is this currently possible in Mockserver? I am using the API client right now. Thank you.
Hello I am getting closed web socket connection the very first time the tests are run on a linux machine,[32med-api_1 |[0m 2020-03-20 16:27:17 org.mockserver.log.MockServerEventLog WARNING Client 26f5fe02-ef57-488f-bc8f-74b6c8d118df not found for request
[32med-api_1 |[0m
[32med-api_1 |[0m {
[32med-api_1 |[0m "method" : "GET",
[32med-api_1 |[0m "path" : "/ws/v1/persons",
[32med-api_1 |[0m "queryStringParameters" : {
[32med-api_1 |[0m "uupid" : [ "alice" ]
[32med-api_1 |[0m },
[32med-api_1 |[0m "headers" : {
[32med-api_1 |[0m "accept-encoding" : [ "gzip" ],
[32med-api_1 |[0m "user-agent" : [ "ReactorNetty/0.8.12.RELEASE" ],
[32med-api_1 |[0m "host" : [ "ed-api:1080" ],
[32med-api_1 |[0m "accept" : [ "*/*" ],
[32med-api_1 |[0m "content-length" : [ "0" ],
[32med-api_1 |[0m "WebSocketCorrelationId" : [ "bcf16e0e-035a-426f-8629-e1c35a9125ac" ]
[32med-api_1 |[0m },
[32med-api_1 |[0m "keepAlive" : true,
[32med-api_1 |[0m "secure" : false
[32med-api_1 |[0m }
[32med-api_1 |[0m
[32med-api_1 |[0m client registry only contains
[32med-api_1 |[0m
[32med-api_1 |[0m {26f5fe02-ef57-488f-bc8f-74b6c8d118df=ChannelHandlerContext(CallbackWebSocketServerHandler#0, [id: 0x61d82abe, L:ed-api/192.168.32.4:1080 - R:/192.168.32.6:48448]), 1ae4ae2c-d978-4cb1-9697-167016647d96=ChannelHandlerContext(CallbackWebSocketServerHandler#0, [id: 0xca1b173c, L:ed-api/192.168.32.4:1080 - R:/192.168.32.6:48446]), 8f41ac93-f5f0-4033-8e27-4bd927bae4f0=ChannelHandlerContext(CallbackWebSocketServerHandler#0, [id: 0xb391485f, L:ed-api/192.168.32.4:1080 - R:/192.168.32.6:48444])}
[32med-api_1 |[0m
[32med-api_1 |[0m 2020-03-20 16:27:17 org.mockserver.log.MockServerEventLog WARNING Returning
[32med-api_1 |[0m
[32med-api_1 |[0m {
[32med-api_1 |[0m "statusCode" : 404,
[32med-api_1 |[0m "reasonPhrase" : "Not Found"
[32med-api_1 |[0m }
[32med-api_1 |[0m
[32med-api_1 |[0m because client 26f5fe02-ef57-488f-bc8f-74b6c8d118df has closed web socket connection
[32med-api_1 |[0m 2020-03-20 16:27:17 org.mockserver.log.MockServerEventLog INFO returning response:
So even though the match was found, im getting a 404, because of this, happens only the first time, and runs fine the second time. Any idea why this might happen?
HttpRequest[] recordedRequests = new MockServerClient("serverIp", 1080)
.retrieveRecordedRequests(
request()
);
0
I am facing an issue in apache http configuration.
Requirement :
A request has land on apache with some header.
for example :
Header myToken
Response new Url https://localhost/fetch-r?id=myToken
How can i achieve this in Apache Http 2.4 ?
@here, For an integration test, I am running 5 services, mocked using mockserver by spinning them up with docker compose. Here is my docker compose file:
version: "3.7"
services:
order-management-webapp:
image: mockserver/mockserver:mockserver-5.10.0
command: -logLevel DEBUG -serverPort 1080
ports:
- ${ORDER_MGMT_PORT}:1080
networks:
- default
location-webapp:
image: mockserver/mockserver:mockserver-5.10.0
ports:
- ${LOCATION_PORT}:1080
networks:
- default
availability-webapp:
image: mockserver/mockserver:mockserver-5.10.0
ports:
- ${AVAILABILITY_PORT}:1080
networks:
- default
supplier-webapp:
image: mockserver/mockserver:mockserver-5.10.0
ports:
- ${SUPPLIER_PORT}:1080
networks:
- default
content-webapp:
image: mockserver/mockserver:mockserver-5.10.0
ports:
- ${CONTENT_PORT}:1080
networks:
- default
networks:
default:
name: integration-test-network
I would like to get the logs of order-management-webapp
for which I have increased the log level. How can I do that please?
The mockserver doc does not provide any details on getting logs when using docker-compose and I am very new to Mockserver. Thanks in advance for your answers!
Hi guys
My goal is to setup HTTP server mock in code and then reach this mocked server from remote (in my case from within docker container).
After start of my mocked server (startClientAndServer(1180)
) I can reach it from local host machine, but not from remote (curl -XGET http://host.docker.internal:1180/
from within container leads to "Connection refused" error, whereas I can easily reach another service launched on my host machine)
How should I configure my mock-server in order to make it available from remote?
às
and the incoming is à s
and my request is being made as expected. (Btw i updated mock server version , it was on 5.6.1 now it's on 5.11.0 and use to work well on 5.6.1)
Hi Guys,
Can anyone please tell me How can I create POST request expectations with JSONPATH with multiple fields in request body.
I am able to create expectation for get end point but not sure How I can call endpoint for post request with multiple fields with JsonPath or any other way to create it.
My Post request that I want call in postman.
http://localhost:8080/api/xyz?simulation=false
Body:
{
"alias": "Mister XYZ",
"accountId": "BE122",
"accountType": "IBAN", //this is ENUM
"address": {
"countryCode": "BE"
}
}
And for this I am creating expectation like below
( It created successfully with 201 created ):
PUT: http://localhost:8080/mockserver/expectation
Body:
"httpRequest": {
"path": "/api/xyz",
"method": "POST",
"queryStringParameters": {
"?simulation": ["false"]
},
"headers": {
"Content-Type" : [ "application/json" ],
"Authorization": ["Bearer .+"]
},
"body": [
{
"type": "JSON_PATH",
"jsonPath": "$[?(@.['alias'] == 'Mister XYZ')]"
},
{
"type": "JSON_PATH",
"jsonPath": "$[?(@.['accountId'] == 'BE122')]"
},
{
"type": "JSON_PATH",
"jsonPath": "$[?(@.['accountType'] =~ /(IBAN|BAN|BBAN|OTHER)/)]" //these are ENUMs
}
{
"type": "JSON_PATH",
"jsonPath": "$.['address'].[?(@.['countryCode'] == 'BE')]"
}
]
},
"httpResponse": {
"statusCode": 201,
"headers": {
"Content-Type": ["application/json"]
},
"body": {
"id": "5a0eaf2012a9a12f1c98947a"
}
}
}
Also give me some solution for ENUM type of fields like accountType in above request. How can I handle it?
Please let me know if you want more clarification on this problem.
org.mockserver.logging.MockServerLogger [MockServer-EventLog0] INFO 13030 request:
{
"method" : "GET",
"path" : "/services/rest/server/containers/test_1.0.0/processes",
"queryStringParameters" : {
"pageSize" : [ "1000" ],
"page" : [ "0" ],
"sortOrder" : [ "true" ]
},
"headers" : {
"Host" : [ "localhost:13030" ],
"Connection" : [ "Keep-Alive" ],
"User-Agent" : [ "Apache-HttpClient/4.5.12 (Java/15.0.1)" ],
"Accept-Encoding" : [ "gzip,deflate" ],
"content-length" : [ "0" ]
},
"keepAlive" : true,
"secure" : true
}
didn't match expectation:
{
"id" : "ffce78dc-60a3-4022-af3a-290049ce251b",
"priority" : 0,
"httpRequest" : {
"method" : "GET",
"path" : "/services/rest/server/containers/test_1.0.0/processes/instances",
"queryStringParameters" : {
"page" : [ "0" ],
"status" : [ "1" ],
"pageSize" : [ "1000" ],
"sortOrder" : [ "true" ]
}
},
"times" : {
"unlimited" : true
},
"timeToLive" : {
"unlimited" : true
},
"httpResponse" : {
"statusCode" : 200,
"headers" : {
"content-type" : [ "application/json" ]
},
"body" : ...
the paths seem to be mismatched but I have no idea why