String requestUrl,
String queryString,
String item,
OutputStream outputStream,
NHttpServerConnection conn) throws Exception {
OverflowBlob temporaryData = new OverflowBlob(256, 4048, "_nhttp", ".dat");
try {
CarbonHttpRequest carbonHttpRequest = new CarbonHttpRequest(
"GET", requestUri, requestUrl);
String uri = request.getRequestLine().getUri();
// setting the parameters for nhttp transport
int pos = uri.indexOf("?");
if (pos != -1) {
StringTokenizer st = new StringTokenizer(uri.substring(pos + 1), "&");
while (st.hasMoreTokens()) {
String param = st.nextToken();
pos = param.indexOf("=");
if (pos != -1) {
carbonHttpRequest.setParameter(
param.substring(0, pos), param.substring(pos + 1));
} else {
carbonHttpRequest.setParameter(param, null);
}
}
}
carbonHttpRequest.setContextPath(cfgCtx.getServiceContextPath());
carbonHttpRequest.setQueryString(queryString);
CarbonHttpResponse carbonHttpResponse = new CarbonHttpResponse(
temporaryData.getOutputStream());
(getRequestProcessors.get(item)).process(carbonHttpRequest,
carbonHttpResponse, cfgCtx);
// adding headers
Map<String, String> responseHeaderMap = carbonHttpResponse.getHeaders();
for (Object key : responseHeaderMap.keySet()) {
Object value = responseHeaderMap.get(key);
response.addHeader(key.toString(), value.toString());
}
// setting status code
response.setStatusCode(carbonHttpResponse.getStatusCode());
// setting error codes
if (carbonHttpResponse.isError()) {
if (carbonHttpResponse.getStatusMessage() != null) {
response.setStatusLine(response.getProtocolVersion(),
carbonHttpResponse.getStatusCode(),
carbonHttpResponse.getStatusMessage());
} else {
response.setStatusLine(response.getProtocolVersion(),
carbonHttpResponse.getStatusCode());
}
}
if (carbonHttpResponse.isRedirect()) {
response.addHeader("Location", carbonHttpResponse.getRedirect());
response.setStatusLine(response.getProtocolVersion(), 302);
}
serverHandler.commitResponseHideExceptions(conn, response);
temporaryData.writeTo(outputStream);
try {
outputStream.flush();
outputStream.close();
} catch (Exception ignored) {}
} finally {
temporaryData.release();
}
}