use of javax.servlet.http.HttpServletMapping in project Payara by payara.
the class StandardContext method getRequestDispatcher.
/**
* Return a <code>RequestDispatcher</code> instance that acts as a
* wrapper for the resource at the given path. The path must begin
* with a "/" and is interpreted as relative to the current context root.
*/
@Override
public RequestDispatcher getRequestDispatcher(String path) {
// Validate the path argument
if (path == null) {
return null;
}
if (!path.startsWith("/") && !path.isEmpty()) {
String msg = MessageFormat.format(rb.getString(LogFacade.INCORRECT_OR_NOT_EMPTY_PATH), path);
throw new IllegalArgumentException(msg);
}
// Get query string
String queryString = null;
int pos = path.indexOf('?');
if (pos >= 0) {
queryString = path.substring(pos + 1);
path = path.substring(0, pos);
}
path = RequestUtil.normalize(path);
if (path == null)
return (null);
pos = path.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();
// Retrieve the thread local mapping data
MappingData mappingData = dd.mappingData;
// Map the URI
CharChunk uriCC = uriMB.getCharChunk();
try {
uriCC.append(getPath(), 0, getPath().length());
/*
* Ignore any trailing path params (separated by ';') for mapping
* purposes
*/
int semicolon = path.indexOf(';');
if (pos >= 0 && semicolon > pos) {
semicolon = -1;
}
uriCC.append(path, 0, semicolon > 0 ? semicolon : pos);
getMapper().map(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(path, semicolon, pos - semicolon);
}
} catch (Exception e) {
// Should never happen
log.log(Level.WARNING, LogFacade.MAPPING_ERROR_EXCEPTION, e);
return (null);
}
Wrapper wrapper = (Wrapper) mappingData.wrapper;
String wrapperPath = mappingData.wrapperPath.toString();
String pathInfo = mappingData.pathInfo.toString();
HttpServletMapping mappingForDispatch = new MappingImpl(mappingData);
mappingData.recycle();
// Construct a RequestDispatcher to process this request
return new ApplicationDispatcher(wrapper, mappingForDispatch, uriCC.toString(), wrapperPath, pathInfo, queryString, null);
}
use of javax.servlet.http.HttpServletMapping in project Payara by payara.
the class ApplicationHttpRequest method initSpecialAttributes.
/**
* Initializes the special attributes of this request wrapper.
*
* @param requestUri The request URI
* @param contextPath The context path
* @param servletPath The servlet path
* @param pathInfo The path info
* @param queryString The query string
*/
void initSpecialAttributes(String requestUri, String contextPath, String servletPath, String pathInfo, String queryString) {
specialAttributes = new HashMap<String, Object>(5);
HttpServletMapping originalMapping;
switch(dispatcherType) {
case INCLUDE:
specialAttributes.put(RequestDispatcher.INCLUDE_REQUEST_URI, requestUri);
specialAttributes.put(RequestDispatcher.INCLUDE_CONTEXT_PATH, contextPath);
specialAttributes.put(RequestDispatcher.INCLUDE_SERVLET_PATH, servletPath);
specialAttributes.put(RequestDispatcher.INCLUDE_MAPPING, mappingForDispatch);
specialAttributes.put(RequestDispatcher.INCLUDE_PATH_INFO, pathInfo);
specialAttributes.put(RequestDispatcher.INCLUDE_QUERY_STRING, queryString);
break;
case FORWARD:
case ERROR:
specialAttributes.put(RequestDispatcher.FORWARD_REQUEST_URI, requestUri);
specialAttributes.put(RequestDispatcher.FORWARD_CONTEXT_PATH, contextPath);
specialAttributes.put(RequestDispatcher.FORWARD_SERVLET_PATH, servletPath);
specialAttributes.put(RequestDispatcher.FORWARD_PATH_INFO, pathInfo);
specialAttributes.put(RequestDispatcher.FORWARD_QUERY_STRING, queryString);
// Safe to cast because we received it in the ctor as HttpServletRequest
originalMapping = ((HttpServletRequest) getRequest()).getHttpServletMapping();
specialAttributes.put(RequestDispatcher.FORWARD_MAPPING, originalMapping);
break;
case ASYNC:
specialAttributes.put(AsyncContext.ASYNC_REQUEST_URI, requestUri);
specialAttributes.put(AsyncContext.ASYNC_CONTEXT_PATH, contextPath);
specialAttributes.put(AsyncContext.ASYNC_SERVLET_PATH, servletPath);
// Safe to cast because we received it in the ctor as HttpServletRequest
originalMapping = ((HttpServletRequest) getRequest()).getHttpServletMapping();
specialAttributes.put(AsyncContext.ASYNC_MAPPING, originalMapping);
specialAttributes.put(AsyncContext.ASYNC_PATH_INFO, pathInfo);
specialAttributes.put(AsyncContext.ASYNC_QUERY_STRING, queryString);
break;
default:
// REQUEST
break;
}
}
Aggregations