use of javax.servlet.http.ServletMapping in project tomcat by apache.
the class ApplicationContext method getRequestDispatcher.
@Override
public RequestDispatcher getRequestDispatcher(String path) {
// Validate the path argument
if (path == null)
return (null);
if (!path.startsWith("/"))
throw new IllegalArgumentException(sm.getString("applicationContext.requestDispatcher.iae", path));
// Get query string
String queryString = null;
String normalizedPath = path;
int pos = normalizedPath.indexOf('?');
if (pos >= 0) {
queryString = normalizedPath.substring(pos + 1);
normalizedPath = normalizedPath.substring(0, pos);
}
normalizedPath = RequestUtil.normalize(normalizedPath);
if (normalizedPath == null)
return (null);
if (getContext().getDispatchersUseEncodedPaths()) {
// Decode
String decodedPath;
try {
decodedPath = URLDecoder.decode(normalizedPath, "UTF-8");
} catch (UnsupportedEncodingException e) {
// Impossible
return null;
}
// Security check to catch attempts to encode /../ sequences
normalizedPath = RequestUtil.normalize(decodedPath);
if (!decodedPath.equals(normalizedPath)) {
getContext().getLogger().warn(sm.getString("applicationContext.illegalDispatchPath", path), new IllegalArgumentException());
return null;
}
}
pos = normalizedPath.length();
// Use the thread local URI and mapping data
DispatchData dd = dispatchData.get();
if (dd == null) {
dd = new DispatchData();
dispatchData.set(dd);
}
MessageBytes uriMB = dd.uriMB;
uriMB.recycle();
// Use the thread local mapping data
MappingData mappingData = dd.mappingData;
// Map the URI
CharChunk uriCC = uriMB.getCharChunk();
try {
uriCC.append(context.getPath(), 0, context.getPath().length());
/*
* Ignore any trailing path params (separated by ';') for mapping
* purposes
*/
int semicolon = normalizedPath.indexOf(';');
if (pos >= 0 && semicolon > pos) {
semicolon = -1;
}
uriCC.append(normalizedPath, 0, semicolon > 0 ? semicolon : pos);
service.getMapper().map(context, uriMB, mappingData);
if (mappingData.wrapper == null) {
return (null);
}
/*
* Append any trailing path params (separated by ';') that were
* ignored for mapping purposes, so that they're reflected in the
* RequestDispatcher's requestURI
*/
if (semicolon > 0) {
uriCC.append(normalizedPath, semicolon, pos - semicolon);
}
} catch (Exception e) {
// Should never happen
log(sm.getString("applicationContext.mapping.error"), e);
return (null);
}
Wrapper wrapper = mappingData.wrapper;
String wrapperPath = mappingData.wrapperPath.toString();
String pathInfo = mappingData.pathInfo.toString();
ServletMapping mapping = (new ApplicationMapping(mappingData)).getServletMapping();
mappingData.recycle();
String encodedUri = URLEncoder.DEFAULT.encode(uriCC.toString(), "UTF-8");
// Construct a RequestDispatcher to process this request
return new ApplicationDispatcher(wrapper, encodedUri, wrapperPath, pathInfo, queryString, mapping, null);
}
Aggregations