📄 coyoterequest.java
字号:
if (servletPath == null) servletPath = getServletPath(); int pos = servletPath.lastIndexOf('/'); String relative = null; if (pos >= 0) { relative = RequestUtil.normalize (servletPath.substring(0, pos + 1) + path); } else { relative = RequestUtil.normalize(servletPath + path); } return (context.getServletContext().getRequestDispatcher(relative)); } /** * Return the scheme used to make this Request. */ public String getScheme() { return (coyoteRequest.scheme().toString()); } /** * Return the server name responding to this Request. */ public String getServerName() { return (coyoteRequest.serverName().toString()); } /** * Return the server port responding to this Request. */ public int getServerPort() { return (coyoteRequest.getServerPort()); } /** * Was this request received on a secure connection? */ public boolean isSecure() { return (secure); } /** * Remove the specified request attribute if it exists. * * @param name Name of the request attribute to remove */ public void removeAttribute(String name) { Object value = null; boolean found = false; // Remove the specified attribute // Check for read only attribute // requests are per thread so synchronization unnecessary if (readOnlyAttributes.containsKey(name)) { return; } found = attributes.containsKey(name); if (found) { value = attributes.get(name); attributes.remove(name); } else { return; } // Notify interested application event listeners Object listeners[] = context.getApplicationListeners(); if ((listeners == null) || (listeners.length == 0)) return; ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(context.getServletContext(), getRequest(), name, value); for (int i = 0; i < listeners.length; i++) { if (!(listeners[i] instanceof ServletRequestAttributeListener)) continue; ServletRequestAttributeListener listener = (ServletRequestAttributeListener) listeners[i]; try { listener.attributeRemoved(event); } catch (Throwable t) { log(sm.getString("coyoteRequest.attributeEvent"), t); // Error valve will pick this execption up and display it to user attributes.put( Globals.EXCEPTION_ATTR, t ); } } } /** * Set the specified request attribute to the specified value. * * @param name Name of the request attribute to set * @param value The associated value */ public void setAttribute(String name, Object value) { // Name cannot be null if (name == null) throw new IllegalArgumentException (sm.getString("coyoteRequest.setAttribute.namenull")); // Null value is the same as removeAttribute() if (value == null) { removeAttribute(name); return; } Object oldValue = null; boolean replaced = false; // Add or replace the specified attribute // Check for read only attribute // requests are per thread so synchronization unnecessary if (readOnlyAttributes.containsKey(name)) { return; } oldValue = attributes.get(name); if (oldValue != null) { replaced = true; } attributes.put(name, value); // Notify interested application event listeners Object listeners[] = context.getApplicationListeners(); if ((listeners == null) || (listeners.length == 0)) return; ServletRequestAttributeEvent event = null; if (replaced) event = new ServletRequestAttributeEvent(context.getServletContext(), getRequest(), name, oldValue); else event = new ServletRequestAttributeEvent(context.getServletContext(), getRequest(), name, value); for (int i = 0; i < listeners.length; i++) { if (!(listeners[i] instanceof ServletRequestAttributeListener)) continue; ServletRequestAttributeListener listener = (ServletRequestAttributeListener) listeners[i]; try { if (replaced) { listener.attributeReplaced(event); } else { listener.attributeAdded(event); } } catch (Throwable t) { log(sm.getString("coyoteRequest.attributeEvent"), t); // Error valve will pick this execption up and display it to user attributes.put( Globals.EXCEPTION_ATTR, t ); } } } /** * Overrides the name of the character encoding used in the body of * this request. This method must be called prior to reading request * parameters or reading input using <code>getReader()</code>. * * @param enc The character encoding to be used * * @exception UnsupportedEncodingException if the specified encoding * is not supported * * @since Servlet 2.3 */ public void setCharacterEncoding(String enc) throws UnsupportedEncodingException { // Ensure that the specified encoding is valid byte buffer[] = new byte[1]; buffer[0] = (byte) 'a'; String dummy = new String(buffer, enc); // Save the validated encoding coyoteRequest.setCharacterEncoding(enc); } // ---------------------------------------------------- HttpRequest Methods /** * Add a Cookie to the set of Cookies associated with this Request. * * @param cookie The new cookie */ public void addCookie(Cookie cookie) { // For compatibility only int size = 0; if (cookies != null) { size = cookies.length; } Cookie[] newCookies = new Cookie[size + 1]; for (int i = 0; i < size; i++) { newCookies[i] = cookies[i]; } newCookies[size] = cookie; cookies = newCookies; } /** * Add a Header to the set of Headers associated with this Request. * * @param name The new header name * @param value The new header value */ public void addHeader(String name, String value) { // Not used } /** * Add a Locale to the set of preferred Locales for this Request. The * first added Locale will be the first one returned by getLocales(). * * @param locale The new preferred Locale */ public void addLocale(Locale locale) { locales.add(locale); } /** * Add a parameter name and corresponding set of values to this Request. * (This is used when restoring the original request on a form based * login). * * @param name Name of this request parameter * @param values Corresponding values for this request parameter */ public void addParameter(String name, String values[]) { // Not used } /** * Clear the collection of Cookies associated with this Request. */ public void clearCookies() { cookies = null; } /** * Clear the collection of Headers associated with this Request. */ public void clearHeaders() { // Not used } /** * Clear the collection of Locales associated with this Request. */ public void clearLocales() { locales.clear(); } /** * Clear the collection of parameters associated with this Request. */ public void clearParameters() { // Not used } /** * Set the authentication type used for this request, if any; otherwise * set the type to <code>null</code>. Typical values are "BASIC", * "DIGEST", or "SSL". * * @param type The authentication type used */ public void setAuthType(String type) { this.authType = type; } /** * Set the context path for this Request. This will normally be called * when the associated Context is mapping the Request to a particular * Wrapper. * * @param path The context path */ public void setContextPath(String path) { if (path == null) { this.contextPath = ""; } else { this.contextPath = path; } } /** * Set the HTTP request method used for this Request. * * @param method The request method */ public void setMethod(String method) { // Not used } /** * Set the query string for this Request. This will normally be called * by the HTTP Connector, when it parses the request headers. * * @param query The query string */ public void setQueryString(String query) { // Not used } /** * Set the path information for this Request. This will normally be called * when the associated Context is mapping the Request to a particular * Wrapper. * * @param path The path information */ public void setPathInfo(String path) { this.pathInfo = path; } /** * Set a flag indicating whether or not the requested session ID for this * request came in through a cookie. This is normally called by the * HTTP Connector, when it parses the request headers. * * @param flag The new flag */ public void setRequestedSessionCookie(boolean flag) { this.requestedSessionCookie = flag; } /** * Set the requested session ID for this request. This is normally called * by the HTTP Connector, when it parses the request headers. * * @param id The new session id */ public void setRequestedSessionId(String id) { this.requestedSessionId = id; } /** * Set a flag indicating whether or not the requested session ID for this * request came in through a URL. This is normally called by the * HTTP Connector, when it parses the request headers. * * @param flag The new flag */ public void setRequestedSessionURL(boolean flag) { this.requestedSessionURL = flag; } /** * Set the unparsed request URI for this Request. This will normally be * called by the HTTP Connector, when it parses the request headers. * * @param uri The request URI */ public void setRequestURI(String uri) { // Not used } /** * Set the decoded request URI. * * @param uri The decoded request URI */ public void setDecodedRequestURI(String uri) { // Not used } /** * Get the decoded request URI. * * @return the URL decoded request URI */ public String getDecodedRequestURI() { return (coyoteRequest.decodedURI().toString()); } /** * Set the servlet path for this Request. This will normally be called * when the associated Context is mapping the Request to a particular * Wrapper. * * @param path The servlet path */ public void setServletPath(String path) { this.servletPath = path; } /** * Set the Principal who has been authenticated for this Request. This * value is also used to calculate the value to be returned by the * <code>getRemoteUser()</code> method. * * @param principal The user Principal */ public void setUserPrincipal(Principal principal) { this.userPrincipal = principal; } // --------------------------------------------- HttpServletRequest Methods /** * Return the authentication type used for this Request. */ public String getAuthType() { return (authType); } /** * Return the portion of the request URI used to select the Context * of the Request. */ public String getContextPath() { return (contextPath); } /** * Return the set of Cookies received with this Request. */ public Cookie[] getCookies() { return cookies; } /** * Set the set of cookies recieved with this Request. */ public void setCookies(Cookie[] cookies) { this.cookies = cookies; } /** * Return the value of the specified date header, if any; otherwise * return -1. * * @param name Name of the requested date header * * @exception IllegalArgumentException if the specified header value * cannot be converted to a date */ public long getDateHeader(String name) { String value = getHeader(name); if (value == null) return (-1L); // Attempt to convert the date header in a variety of formats long result = FastHttpDateFormat.parseDate(value, formats); if (result != (-1L)) { return result; } throw new IllegalArgumentException(value); } /** * Return the first value of the specified header, if any; otherwise, * return <code>null</code> * * @param name Name of the requested header */ public String getHeader(String name) { return coyoteRequest.getHeader(name); } /** * Return all of the values of the specified header, if any; otherwise, * return an empty enumeration. * * @param name Name of the requested header */ public Enumeration getHeaders(String name) { return coyoteRequest.getMimeHeaders().values(name); } /** * Return the names of all headers received with this request. */ public Enumeration getHeaderNames() { return coyoteRequest.getMimeHeaders().names(); } /** * Return the value of the specified header as an integer, or -1 if there * is no such header for this request. * * @param name Name of the requested header * * @exception IllegalArgumentException if the specified header value * cannot be converted to an integer */ public int getIntHeader(String name) { String value = getHeader(name); if (value == null) { return (-1); } else { return (Integer.parseInt(value)); } } /** * Return the HTTP request method used in this Request. */ public String getMethod() { return coyoteRequest.method().toString();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -