if (dispatcher != null) {
dispatcher.forward(request, response);
}
} else {
// otherwise assume it is a short Id
ResourceManager rm = ResourceManager.getInstance();
boolean isQrCode = uri.endsWith(QR_EXTENSION);
String shortId = isQrCode ? uri.substring(1, uri.length() -
QR_EXTENSION.length()) : uri.substring(1);
ShortUrl surl = rm.getUrlManager().getShortUrl(shortId);
if (surl == null) {
// if the short Id was bogus show a "shush" (our fail whale)
httpResponse.sendError(404);
} else if (isQrCode) {
// show QRCode if requested
sendQRCode(httpResponse, surl.getLongUrl());
} else {
// increment counters and redirect!
rm.getCounters().incrementUsage(shortId, new RequestInfo(httpRequest));
String refShortId = surl.getRefShortId();
if (refShortId != null) {
// increment the aggregate link
rm.getCounters().incrementUsage(refShortId,
new RequestInfo(httpRequest));
}
httpResponse.sendRedirect(surl.getLongUrl());
}
}