use of org.mockserver.model.NottableString in project wildfly by wildfly.
the class TestingOcspServer method getHttpResponse.
public HttpResponse getHttpResponse(HttpRequest request, HttpOcspServlet servlet) {
byte[] body;
HttpMethod method;
if (request.getBody() == null) {
method = HttpMethod.GET;
body = request.getPath().getValue().split("/ocsp/", 2)[1].getBytes(UTF_8);
} else {
method = HttpMethod.POST;
body = request.getBody().getRawBytes();
}
ByteBuf buffer = Unpooled.wrappedBuffer(body);
FullHttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_0, method, request.getPath().getValue(), buffer);
for (Header header : request.getHeaderList()) {
for (NottableString value : header.getValues()) {
nettyRequest.headers().add(header.getName().getValue(), value.getValue());
}
}
FullHttpResponse nettyResponse;
try {
nettyResponse = servlet.service(nettyRequest, new ServletURI(request.getPath().getValue()), null, SslReverseProxyMode.NONE);
} catch (Exception e) {
throw new RuntimeException(e);
}
HttpResponse response = response().withStatusCode(nettyResponse.status().code()).withBody(nettyResponse.content().array());
for (Map.Entry<String, String> header : nettyResponse.headers()) {
response.withHeader(header.getKey(), header.getValue());
}
return response;
}
Aggregations