Closed manish-panwar closed 8 years ago
This is the response returned by Mock Server.
{
"statusCode" : 200,
}
This is the request content/header I need access to. I see this in logs, but can't access it in HttpRequest object.
{
"method" : "GET",
"path" : "/Microsoft",
"headers" : [ {
"name" : "Host",
"values" : [ "localhost:8083" ]
}, {
"name" : "User-Agent",
"values" : [ "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36" ]
}, {
"name" : "Postman-Token",
"values" : [ "a27341d9-cdef-e8cf-db99-71ca5d36f082" ]
}, {
"name" : "Cache-Control",
"values" : [ "no-cache" ]
}, {
"name" : "expected-response-file",
"values" : [ "expected-response-file" ]
}, {
"name" : "aw-tenant-code",
"values" : [ "1H2BA4AAAAG5A6UAADQA" ]
}, {
"name" : "Content-Type",
"values" : [ "application/json" ]
}, {
"name" : "Accept",
"values" : [ "*/*" ]
}, {
"name" : "Accept-Encoding",
"values" : [ "gzip, deflate, sdch" ]
}, {
"name" : "Accept-Language",
"values" : [ "en-US,en;q=0.8" ]
}, {
"name" : "Content-Length",
"values" : [ "0" ]
} ],
"keepAlive" : true,
"secure" : false
}
I think all you need to implement is an instance of org.mockserver.mock.action.ExpectationCallback
, this will allow you to dynamically create a response based on data in the request and therefore have a single expectation and instance of org.mockserver.mock.action.ExpectationCallback
that supports all 100s different header-file combinations. For more details see: http://www.mock-server.com/mock_server/creating_expectations.html#callback
I'm going to close this ticket as I think this give you everything you need, please feel free to re-open if you have further queries.
Hello,
I am using maven plugin to start the server and given below is how ExpectationInitializer is implemented.
We have 1000+ scenarios to automate, and we want mock server to respond specific response body & headers based on header value coming from client request(basically client will pass on a header which can be used to determine a file name which contains the expected response that to be returned).
We don't want to have 100s of condition while we can have a generic implementation which can generate the response body based on header key.
So far I could see that HttpRequest object contains only the matcher data, not the actual HTTP request body/headers.
Thanks, Manish