use of org.xipki.http.servlet.ServletURI 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;
}
use of org.xipki.http.servlet.ServletURI in project xipki by xipki.
the class ServletListener method getServlet.
public Object[] getServlet(String rawPath) throws URISyntaxException {
String alias = null;
String uriText = null;
for (String m : aliases) {
if (m.equals("/")) {
alias = m;
uriText = rawPath;
break;
}
if (rawPath.startsWith(m)) {
int len = rawPath.length();
int mlen = m.length();
if (len == mlen) {
uriText = "/";
alias = m;
} else {
char ch = rawPath.charAt(mlen);
if (ch == '/') {
uriText = (len == mlen + 1) ? "/" : rawPath.substring(mlen);
alias = m;
} else if (ch == '?') {
uriText = rawPath.substring(mlen);
alias = m;
}
}
}
if (alias != null) {
break;
}
}
if (alias == null) {
return null;
}
ServletURI servletUri = ServletURIPool.getServletURI(uriText);
HttpServlet servlet = aliasServletMap.get(alias);
return new Object[] { servletUri, servlet };
}
Aggregations