if (uriInPath > 0) {
String pathInfo = url.substring(uriInPath + httpContextURILength);
// Prepare the mock request
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
request.setServerName(site.getHostname(environment).getURL().getHost());
request.setServerPort(site.getHostname(environment).getURL().getPort());
request.setMethod(site.getHostname(environment).getURL().getProtocol());
if (language != null)
request.addPreferredLocale(new Locale(language));
request.setAttribute(WebloungeRequest.PAGE, page);
request.setAttribute(WebloungeRequest.COMPOSER, composer);
request.setAttribute(WebloungeRequest.PAGELET, pagelet);
request.setPathInfo(pathInfo);
request.setRequestURI(UrlUtils.concat(httpContextURI, pathInfo));
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
return response.getContentAsString();
} else {