*/
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException {
try {
// Try each Transport until someone takes responsibility
OpenURLRequest openURLRequest = null;
for (int i = 0; openURLRequest == null && i < transports.length; ++i) {
openURLRequest = transports[i].toOpenURLRequest(processor, req);
}
if (openURLRequest == null) {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid Request");
return;
}
// 2009-05-06: rchute Add AccessManager Support
if (am != null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("OpenURLServlet using AccessManager");
}
try {
final String url =
((java.net.URI) openURLRequest.getContextObjects()[0].getReferent().getDescriptors()[0])
.toASCIIString();
if (url.startsWith("http") || url.startsWith("ftp")) {
if (!am.checkAccess(new URL(url).getHost())) {
final int status = HttpServletResponse.SC_FORBIDDEN;
resp.sendError(status);
return;
}
}
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
}
// rchute: Add referrer for possible extension processing
if (req.getHeader("referer") != null) {
final ContextObject[] coa = openURLRequest.getContextObjects();
final ReferringEntity[] rea = coa[0].getReferringEntities();
rea[0].addDescriptor(req.getHeader("referer"));
}
// 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);