*
* @throws IOException
*/
@Override
public void service(final Request request, final Response response) throws Exception {
MappingData mappingData;
try {
request.addAfterServiceListener(afterServiceListener);
// If we have only one Adapter deployed, invoke that Adapter
// directly.
// TODO: Not sure that will works with JRuby.
if (!mapMultipleAdapter && mapper instanceof V3Mapper) {
// Remove the MappingData as we might delegate the request
// to be serviced directly by the WebContainer
final HttpHandler httpHandler = ((V3Mapper) mapper).getHttpHandler();
if (httpHandler != null) {
request.setNote(MAPPING_DATA, null);
// req.setNote(MAPPED_ADAPTER, a);
httpHandler.service(request, response);
return;
}
}
final DataChunk decodedURI = request.getRequest()
.getRequestURIRef().getDecodedRequestURIBC(isAllowEncodedSlash());
mappingData = request.getNote(MAPPING_DATA);
if (mappingData == null) {
mappingData = new MappingData();
request.setNote(MAPPING_DATA, mappingData);
} else {
mappingData.recycle();
}
HttpHandler httpService;
final CharChunk decodedURICC = decodedURI.getCharChunk();
final int semicolon = decodedURICC.indexOf(';', 0);
// Map the request without any trailling.
httpService = mapUriWithSemicolon(request, decodedURI, semicolon, mappingData);
if (httpService == null || httpService instanceof ContainerMapper) {
String ext = decodedURI.toString();
String type = "";
if (ext.lastIndexOf(".") > 0) {
ext = "*" + ext.substring(ext.lastIndexOf("."));
type = ext.substring(ext.lastIndexOf(".") + 1);
}
if (!MimeType.contains(type) && !"/".equals(ext)) {
initializeFileURLPattern(ext);
mappingData.recycle();
httpService = mapUriWithSemicolon(request, decodedURI, semicolon, mappingData);
} else {
super.service(request, response);
return;
}