*
* @throws IOException
*/
@Override
public void service(Request req, Response res) throws Exception{
MappingData mappingData = null;
try{
// 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
req.setNote(MAPPING_DATA, null);
Adapter a = ((V3Mapper)mapper).getAdapter();
if (a != null){
req.setNote(MAPPED_ADAPTER, a);
a.service(req, res);
return;
}
}
MessageBytes decodedURI = req.decodedURI();
decodedURI.duplicate(req.requestURI());
mappingData = (MappingData) req.getNote(MAPPING_DATA);
if (mappingData == null) {
mappingData = new MappingData();
req.setNote(MAPPING_DATA, mappingData);
}
Adapter adapter = null;
String uriEncoding = (String) grizzlyEmbeddedHttp.getProperty("uriEncoding");
HttpRequestURIDecoder.decode(decodedURI, urlDecoder, uriEncoding, null);
final CharChunk decodedURICC = decodedURI.getCharChunk();
final int semicolon = decodedURICC.indexOf(';', 0);
// Map the request without any trailling.
adapter = mapUriWithSemicolon(req, decodedURI, semicolon, mappingData);
if (adapter == null || adapter instanceof ContainerMapper) {
String ext = decodedURI.toString();
String type = "";
if (ext.indexOf(".") > 0) {
ext = "*" + ext.substring(ext.lastIndexOf("."));
type = ext.substring(ext.lastIndexOf(".") + 1);
}
if (!MimeType.contains(type) && !ext.equals("/")){
initializeFileURLPattern(ext);
mappingData.recycle();
adapter = mapUriWithSemicolon(req, decodedURI, semicolon, mappingData);
} else {
super.service(req, res);
return;
}