Search in sources :

Example 1 with NottableString

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;
}
Also used : ServletURI(org.xipki.http.servlet.ServletURI) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpResponse(org.mockserver.model.HttpResponse) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) NottableString(org.mockserver.model.NottableString) ByteBuf(io.netty.buffer.ByteBuf) SQLException(java.sql.SQLException) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Header(org.mockserver.model.Header) NottableString(org.mockserver.model.NottableString) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) Map(java.util.Map) HttpMethod(io.netty.handler.codec.http.HttpMethod)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)1 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)1 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)1 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)1 HttpMethod (io.netty.handler.codec.http.HttpMethod)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CertificateException (java.security.cert.CertificateException)1 SQLException (java.sql.SQLException)1 Map (java.util.Map)1 Header (org.mockserver.model.Header)1 HttpResponse (org.mockserver.model.HttpResponse)1 NottableString (org.mockserver.model.NottableString)1 ServletURI (org.xipki.http.servlet.ServletURI)1