if (req.getHeader("referer") != null)
openURLRequest.getContextObjects()[0].getReferringEntities()[0].addDescriptor(req.getHeader("referer"));
// rchute: Add requester for possible extension processing
openURLRequest.getContextObjects()[0].getRequesters()[0].addDescriptor(req.getRemoteAddr());
// Process the ContextObjects
OpenURLResponse result = processor.resolve(openURLRequest);
// See if anyone handled the request
int status;
if (result == null) {
status = HttpServletResponse.SC_NOT_FOUND;
} else {
status = result.getStatus();
Cookie[] cookies = result.getCookies();
if (cookies != null) {
for (int i=0; i< cookies.length; ++i) {
resp.addCookie(cookies[i]);
}
}
Map sessionMap = result.getSessionMap();
if (sessionMap != null) {
HttpSession session = req.getSession(true);
Iterator iter = sessionMap.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Entry) iter.next();
session.setAttribute((String) entry.getKey(), entry.getValue());
}
}
Map headerMap = result.getHeaderMap();
if (headerMap != null) {
Iterator iter = headerMap.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Entry) iter.next();
resp.setHeader((String) entry.getKey(),
(String) entry.getValue());
}
}
}
// Allow the processor to generate a variety of response types
switch (status) {
case HttpServletResponse.SC_MOVED_TEMPORARILY:
resp.sendRedirect(
resp.encodeRedirectURL(
result.getRedirectURL()));
break;
case HttpServletResponse.SC_SEE_OTHER:
case HttpServletResponse.SC_MOVED_PERMANENTLY:
resp.setStatus(status);
resp.setHeader("Location", result.getRedirectURL());
break;
case HttpServletResponse.SC_NOT_FOUND:
resp.sendError(status);
break;
default:
OutputStream out = resp.getOutputStream();
resp.setStatus(status);
resp.setContentType(result.getContentType());
InputStream is = result.getInputStream();
byte[] bytes = new byte[1024];
int len;
while ((len = is.read(bytes)) != -1) {
out.write(bytes, 0, len);
}