📄 coyoterequest.java
字号:
*/ public void setResponse(org.apache.catalina.Response response) { this.response = response; } /** * Return the Socket (if any) through which this Request was received. * This should <strong>only</strong> be used to access underlying state * information about this Socket, such as the SSLSession associated with * an SSLSocket. */ public Socket getSocket() { return (socket); } /** * Set the Socket (if any) through which this Request was received. * * @param socket The socket through which this request was received */ public void setSocket(Socket socket) { this.socket = socket; remoteHost = null; remoteAddr = null; } /** * Return the input stream associated with this Request. */ public InputStream getStream() { return inputStream; } /** * Set the input stream associated with this Request. * * @param stream The new input stream */ public void setStream(InputStream stream) { // Ignore } /** * The valve context associated with this request. */ protected ValveContext valveContext = null; /** * Get valve context. */ public ValveContext getValveContext() { return (this.valveContext); } /** * Set valve context. * * @param valveContext New valve context object */ public void setValveContext(ValveContext valveContext) { this.valveContext = valveContext; } /** * The Wrapper within which this Request is being processed. */ protected Wrapper wrapper = null; /** * Return the Wrapper within which this Request is being processed. */ public Wrapper getWrapper() { return (this.wrapper); } /** * Set the Wrapper within which this Request is being processed. This * must be called as soon as the appropriate Wrapper is identified, and * before the Request is ultimately passed to an application servlet. * * @param wrapper The newly associated Wrapper */ public void setWrapper(Wrapper wrapper) { this.wrapper = wrapper; } // ------------------------------------------------- Request Public Methods /** * Create and return a ServletInputStream to read the content * associated with this Request. * * @exception IOException if an input/output error occurs */ public ServletInputStream createInputStream() throws IOException { return inputStream; } /** * Perform whatever actions are required to flush and close the input * stream or reader, in a single operation. * * @exception IOException if an input/output error occurs */ public void finishRequest() throws IOException { // The reader and input stream don't need to be closed } /** * Return the object bound with the specified name to the internal notes * for this request, or <code>null</code> if no such binding exists. * * @param name Name of the note to be returned */ public Object getNote(String name) { return (notes.get(name)); } /** * Return an Iterator containing the String names of all notes bindings * that exist for this request. */ public Iterator getNoteNames() { return (notes.keySet().iterator()); } /** * Remove any object bound to the specified name in the internal notes * for this request. * * @param name Name of the note to be removed */ public void removeNote(String name) { notes.remove(name); } /** * Bind an object to a specified name in the internal notes associated * with this request, replacing any existing binding for this name. * * @param name Name to which the object should be bound * @param value Object to be bound to the specified name */ public void setNote(String name, Object value) { notes.put(name, value); } /** * Set the content length associated with this Request. * * @param length The new content length */ public void setContentLength(int length) { // Not used } /** * Set the content type (and optionally the character encoding) * associated with this Request. For example, * <code>text/html; charset=ISO-8859-4</code>. * * @param type The new content type */ public void setContentType(String type) { // Not used } /** * Set the protocol name and version associated with this Request. * * @param protocol Protocol name and version */ public void setProtocol(String protocol) { // Not used } /** * Set the IP address of the remote client associated with this Request. * * @param remoteAddr The remote IP address */ public void setRemoteAddr(String remoteAddr) { // Not used } /** * Set the fully qualified name of the remote client associated with this * Request. * * @param remoteHost The remote host name */ public void setRemoteHost(String remoteHost) { // Not used } /** * Set the name of the scheme associated with this request. Typical values * are <code>http</code>, <code>https</code>, and <code>ftp</code>. * * @param scheme The scheme */ public void setScheme(String scheme) { // Not used } /** * Set the value to be returned by <code>isSecure()</code> * for this Request. * * @param secure The new isSecure value */ public void setSecure(boolean secure) { this.secure = secure; } /** * Set the name of the server (virtual host) to process this request. * * @param name The server name */ public void setServerName(String name) { coyoteRequest.serverName().setString(name); } /** * Set the port number of the server to process this request. * * @param port The server port */ public void setServerPort(int port) { coyoteRequest.setServerPort(port); } // ------------------------------------------------- ServletRequest Methods /** * Return the specified request attribute if it exists; otherwise, return * <code>null</code>. * * @param name Name of the request attribute to return */ public Object getAttribute(String name) { Object attr=attributes.get(name); if(attr!=null) return(attr); attr = coyoteRequest.getAttribute(name); if(attr != null) return attr; // XXX Should move to Globals if(Constants.SSL_CERTIFICATE_ATTR.equals(name)) { coyoteRequest.action(ActionCode.ACTION_REQ_SSL_CERTIFICATE, null); attr = getAttribute(Globals.CERTIFICATES_ATTR); if(attr != null) attributes.put(name, attr); } return attr; } /** * Return the names of all request attributes for this Request, or an * empty <code>Enumeration</code> if there are none. */ public Enumeration getAttributeNames() { return (new Enumerator(attributes.keySet())); } /** * Return the character encoding for this Request. */ public String getCharacterEncoding() { return (coyoteRequest.getCharacterEncoding()); } /** * Return the content length for this Request. */ public int getContentLength() { return (coyoteRequest.getContentLength()); } /** * Return the content type for this Request. */ public String getContentType() { return (coyoteRequest.getContentType()); } /** * Return the servlet input stream for this Request. The default * implementation returns a servlet input stream created by * <code>createInputStream()</code>. * * @exception IllegalStateException if <code>getReader()</code> has * already been called for this request * @exception IOException if an input/output error occurs */ public ServletInputStream getInputStream() throws IOException { if (usingReader) throw new IllegalStateException (sm.getString("coyoteRequest.getInputStream.ise")); usingInputStream = true; return inputStream; } /** * Return the preferred Locale that the client will accept content in, * based on the value for the first <code>Accept-Language</code> header * that was encountered. If the request did not specify a preferred * language, the server's default Locale is returned. */ public Locale getLocale() { if (!localesParsed) parseLocales(); if (locales.size() > 0) { return ((Locale) locales.get(0)); } else { return (defaultLocale); } } /** * Return the set of preferred Locales that the client will accept * content in, based on the values for any <code>Accept-Language</code> * headers that were encountered. If the request did not specify a * preferred language, the server's default Locale is returned. */ public Enumeration getLocales() { if (!localesParsed) parseLocales(); if (locales.size() > 0) return (new Enumerator(locales)); ArrayList results = new ArrayList(); results.add(defaultLocale); return (new Enumerator(results)); } /** * Return the value of the specified request parameter, if any; otherwise, * return <code>null</code>. If there is more than one value defined, * return only the first one. * * @param name Name of the desired request parameter */ public String getParameter(String name) { if (!requestParametersParsed) parseRequestParameters(); return coyoteRequest.getParameters().getParameter(name); } /** * Returns a <code>Map</code> of the parameters of this request. * Request parameters are extra information sent with the request. * For HTTP servlets, parameters are contained in the query string * or posted form data. * * @return A <code>Map</code> containing parameter names as keys * and parameter values as map values. */ public Map getParameterMap() { if (parameterMap.isLocked()) return parameterMap; Enumeration enum = getParameterNames(); while (enum.hasMoreElements()) { String name = enum.nextElement().toString(); String[] values = getParameterValues(name); parameterMap.put(name, values); } parameterMap.setLocked(true); return parameterMap; } /** * Return the names of all defined request parameters for this request. */ public Enumeration getParameterNames() { if (!requestParametersParsed) parseRequestParameters(); return coyoteRequest.getParameters().getParameterNames(); } /** * Return the defined values for the specified request parameter, if any; * otherwise, return <code>null</code>. * * @param name Name of the desired request parameter */ public String[] getParameterValues(String name) { if (!requestParametersParsed) parseRequestParameters(); return coyoteRequest.getParameters().getParameterValues(name); } /** * Return the protocol and version used to make this Request. */ public String getProtocol() { return coyoteRequest.protocol().toString(); } /** * Read the Reader wrapping the input stream for this Request. The * default implementation wraps a <code>BufferedReader</code> around the * servlet input stream returned by <code>createInputStream()</code>. * * @exception IllegalStateException if <code>getInputStream()</code> * has already been called for this request * @exception IOException if an input/output error occurs */ public BufferedReader getReader() throws IOException { if (usingInputStream) throw new IllegalStateException (sm.getString("coyoteRequest.getReader.ise")); usingReader = true; return reader; } /** * Return the real path of the specified virtual path. * * @param path Path to be translated * * @deprecated As of version 2.1 of the Java Servlet API, use * <code>ServletContext.getRealPath()</code>. */ public String getRealPath(String path) { if (context == null) return (null); ServletContext servletContext = context.getServletContext(); if (servletContext == null) return (null); else { try { return (servletContext.getRealPath(path)); } catch (IllegalArgumentException e) { return (null); } } } /** * Return the remote IP address making this Request. */ public String getRemoteAddr() { if (remoteAddr == null) { if (socket != null) { InetAddress inet = socket.getInetAddress(); remoteAddr = inet.getHostAddress(); } else { coyoteRequest.action (ActionCode.ACTION_REQ_HOST_ADDR_ATTRIBUTE, coyoteRequest); remoteAddr = coyoteRequest.remoteAddr().toString(); } } return remoteAddr; } /** * Return the remote host name making this Request. */ public String getRemoteHost() { if (remoteHost == null) { if (!connector.getEnableLookups()) { remoteHost = getRemoteAddr(); } else if (socket != null) { InetAddress inet = socket.getInetAddress(); remoteHost = inet.getHostName(); } else { coyoteRequest.action (ActionCode.ACTION_REQ_HOST_ATTRIBUTE, coyoteRequest); remoteHost = coyoteRequest.remoteHost().toString(); } } return remoteHost; } /** * Return a RequestDispatcher that wraps the resource at the specified * path, which may be interpreted as relative to the current request path. * * @param path Path of the resource to be wrapped */ public RequestDispatcher getRequestDispatcher(String path) { if (context == null) return (null); // If the path is already context-relative, just pass it through if (path == null) return (null); else if (path.startsWith("/")) return (context.getServletContext().getRequestDispatcher(path)); // Convert a request-relative path to a context-relative one String servletPath = (String) getAttribute(Globals.INCLUDE_SERVLET_PATH_ATTR);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -