I want to intercept requests in my application and one of the scenarios I have come across is that - due to nature of the application some of the services have same request endpoint different payload though and I want to send back different responses at different occurrence. Is there a way to assign order to the intercepted request and send a specific response as per the sequence? or any other mechanism to tell browser-mob that example - for this url with this payload send this response? Because if it is the same url then responses are overridden by the last intercepted request.
I have already tried request with url and contents contains. Check the if condition in code below.
proxy.addRequestFilter((request, contents, messageInfo) -> {
String content = null;
try {
content = URLDecoder.decode(contents.getTextContents(), "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (request.getUri().contains(endpoint) && (content != null && content.contains(contentContains))) {
//Use DefaultFullHttpResponse for posting the json body
final HttpResponse httpResponse = new DefaultFullHttpResponse(request.getProtocolVersion(),
statusCode);
//Close the connection so it doesn't pass through
httpResponse.headers().add("CONNECTION", "Close");
//Specify the content-type and charset
httpResponse.headers().add("Content-Type", "application/json; charset=UTF-8");
//replace the body
HttpObjectUtil.replaceTextHttpEntityBody((FullHttpMessage) httpResponse, response);
return httpResponse;
}
return null;
});
Actual - If the two request have same endpoint the last intercepted request overrides the response I want to send back.
Expected- Some mechanism where Bowsermob is able to register different responses for the request with same end point and send back different response.