// rchute: Add requester for possible extension processing
final ContextObject[] coa = openURLRequest.getContextObjects();
coa[0].getRequesters()[0].addDescriptor(req.getRemoteAddr());
// Process the ContextObjects
final OpenURLResponse result = processor.resolve(openURLRequest);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("OpenURLRequestProcessor resolving to a result");
}
// See if anyone handled the request
int status;
if (result == null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("OpenURLRequestProcessor didn't find result");
}
status = HttpServletResponse.SC_NOT_FOUND;
} else {
status = result.getStatus();
final Cookie[] cookies = result.getCookies();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("OpenURLRequestProcessor status: {}", status);
}
if (cookies != null) {
for (int i = 0; i < cookies.length; ++i) {
resp.addCookie(cookies[i]);
}
}
final Map<?, ?> sessionMap = result.getSessionMap();
if (sessionMap != null) {
final HttpSession session = req.getSession(true);
final Iterator<?> iter = sessionMap.entrySet().iterator();
while (iter.hasNext()) {
final Map.Entry<?, ?> entry = (Entry<?, ?>) iter.next();
final String key = (String) entry.getKey();
final String value = (String) entry.getValue();
session.setAttribute(key, value);
}
}
final Map<?, ?> headerMap = result.getHeaderMap();
if (headerMap != null) {
final Iterator<?> iter = headerMap.entrySet().iterator();
while (iter.hasNext()) {
final 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());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Redirect URL: {}", result.getRedirectURL());
}
break;
case HttpServletResponse.SC_NOT_FOUND:
final String id = req.getParameter("rft_id");
resp.sendError(status, id != null ? id + " not found" : "");
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("RFT_ID ({}) not found", id);
}
break;
default:
final OutputStream out = resp.getOutputStream();
resp.setStatus(status);
resp.setContentType(result.getContentType());
final InputStream is = result.getInputStream();
final byte[] bytes = new byte[1024];
int len;
while ((len = is.read(bytes)) != -1) {
out.write(bytes, 0, len);