ChannelFuture writeFuture = ctx.write(new ChunkedStream(contentStream));
writeFuture.addListener(ChannelFutureListener.CLOSE);
}
private MockHttpServletRequest createServletRequest(HttpRequest httpRequest) {
UriComponents uriComponents = UriComponentsBuilder.fromUriString(httpRequest.getUri()).build();
MockHttpServletRequest servletRequest = new MockHttpServletRequest(this.servletContext);
servletRequest.setRequestURI(uriComponents.getPath());
servletRequest.setPathInfo(uriComponents.getPath());
servletRequest.setMethod(httpRequest.getMethod().getName());
if (uriComponents.getScheme() != null) {
servletRequest.setScheme(uriComponents.getScheme());
}
if (uriComponents.getHost() != null) {
servletRequest.setServerName(uriComponents.getHost());
}
if (uriComponents.getPort() != -1) {
servletRequest.setServerPort(uriComponents.getPort());
}
for (String name : httpRequest.getHeaderNames()) {
for (String value : httpRequest.getHeaders(name)) {
servletRequest.addHeader(name, value);
}
}
servletRequest.setContent(httpRequest.getContent().array());
try {
if (uriComponents.getQuery() != null) {
String query = UriUtils.decode(uriComponents.getQuery(), "UTF-8");
servletRequest.setQueryString(query);
}
for (Entry<String, List<String>> entry : uriComponents.getQueryParams().entrySet()) {
for (String value : entry.getValue()) {
servletRequest.addParameter(
UriUtils.decode(entry.getKey(), "UTF-8"),
UriUtils.decode(value, "UTF-8"));
}