Mercurial Hosting > luan
changeset 997:7d28be82ab75
simplify Request
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 18 Oct 2016 22:43:17 -0600 |
parents | d9cfec64899c |
children | bf176925e00f |
files | src/org/eclipse/jetty/server/Request.java src/org/eclipse/jetty/server/Server.java src/org/eclipse/jetty/server/handler/ContextHandler.java src/org/eclipse/jetty/server/handler/RequestLogHandler.java src/org/eclipse/jetty/server/handler/ResourceHandler.java |
diffstat | 5 files changed, 90 insertions(+), 667 deletions(-) [+] |
line wrap: on
line diff
diff -r d9cfec64899c -r 7d28be82ab75 src/org/eclipse/jetty/server/Request.java --- a/src/org/eclipse/jetty/server/Request.java Tue Oct 18 21:22:53 2016 -0600 +++ b/src/org/eclipse/jetty/server/Request.java Tue Oct 18 22:43:17 2016 -0600 @@ -122,24 +122,20 @@ */ public final class Request implements HttpServletRequest { - public static final String __MULTIPART_CONFIG_ELEMENT = "org.eclipse.multipartConfig"; - public static final String __MULTIPART_INPUT_STREAM = "org.eclipse.multiPartInputStream"; - public static final String __MULTIPART_CONTEXT = "org.eclipse.multiPartContext"; private static final Logger LOG = LoggerFactory.getLogger(Request.class); - private static final String __ASYNC_FWD = "org.eclipse.asyncfwd"; private static final Collection __defaultLocale = Collections.singleton(Locale.getDefault()); private static final int __NONE = 0, _STREAM = 1, __READER = 2; private volatile Attributes _attributes; private MultiMap<String> _baseParameters; private String _characterEncoding; - protected AbstractHttpConnection _connection; + protected final AbstractHttpConnection _connection; public ContextHandler _contextHandler = null; private String _contextPath; private CookieCutter _cookies; private boolean _cookiesExtracted = false; - private EndPoint _endp; + private final EndPoint _endp; private boolean _handled = false; private int _inputState = __NONE; private String _method; @@ -151,34 +147,24 @@ private String _queryString; private BufferedReader _reader; private String _readerEncoding; - private String _remoteAddr; - private String _remoteHost; private String _requestURI; private String _scheme = URIUtil.HTTP; private String _serverName; - private String _servletPath; private long _timeStamp; - private long _dispatchTime; - private Buffer _timeStampBuffer; private HttpURI _uri; - /* ------------------------------------------------------------ */ - public Request() - { - } - - /* ------------------------------------------------------------ */ public Request(AbstractHttpConnection connection) { - setConnection(connection); + _connection = connection; + _endp = connection.getEndPoint(); } /* ------------------------------------------------------------ */ /** * Extract Parameters from query string and/or form _content. */ - public void extractParameters() + private void extractParameters() { if (_baseParameters == null) _baseParameters = new MultiMap(16); @@ -264,28 +250,6 @@ _parameters.add(name,LazyList.get(values,i)); } } - - if (content_type != null && content_type.length()>0 && content_type.startsWith("multipart/form-data") && getAttribute(__MULTIPART_CONFIG_ELEMENT)!=null) - { - try - { - getParts(); - } - catch (IOException e) - { - if (LOG.isDebugEnabled()) - LOG.warn("",e); - else - LOG.warn(e.toString()); - } - catch (ServletException e) - { - if (LOG.isDebugEnabled()) - LOG.warn("",e); - else - LOG.warn(e.toString()); - } - } } finally { @@ -295,29 +259,19 @@ } } - /* ------------------------------------------------------------ */ + @Override public AsyncContext getAsyncContext() { throw new UnsupportedOperationException(); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#getAttribute(java.lang.String) - */ + @Override public Object getAttribute(String name) { - if ("org.eclipse.jetty.io.EndPoint.maxIdleTime".equalsIgnoreCase(name)) - return new Long(getConnection().getEndPoint().getMaxIdleTime()); - - Object attr = (_attributes == null)?null:_attributes.getAttribute(name); - return attr; + return (_attributes == null)?null:_attributes.getAttribute(name); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#getAttributeNames() - */ + @Override public Enumeration getAttributeNames() { if (_attributes == null) @@ -326,82 +280,37 @@ return AttributesMap.getAttributeNamesCopy(_attributes); } - /* ------------------------------------------------------------ */ - /* - */ - public Attributes getAttributes() - { - if (_attributes == null) - _attributes = new AttributesMap(); - return _attributes; - } - - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.http.HttpServletRequest#getAuthType() - */ + @Override public String getAuthType() { return null; } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#getCharacterEncoding() - */ + @Override public String getCharacterEncoding() { return _characterEncoding; } - /* ------------------------------------------------------------ */ - /** - * @return Returns the connection. - */ - public AbstractHttpConnection getConnection() - { - return _connection; - } - - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#getContentLength() - */ + @Override public int getContentLength() { return (int)_connection._requestFields.getLongField(HttpHeaders.CONTENT_LENGTH_BUFFER); } - public long getContentRead() - { - if (_connection == null) - return -1; - - return _connection._parser.getContentRead(); - } - - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#getContentType() - */ + @Override public String getContentType() { return _connection._requestFields.getStringField(HttpHeaders.CONTENT_TYPE_BUFFER); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.http.HttpServletRequest#getContextPath() - */ + @Override public String getContextPath() { return _contextPath; } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.http.HttpServletRequest#getCookies() - */ + @Override public Cookie[] getCookies() { if (_cookiesExtracted) @@ -427,10 +336,7 @@ return _cookies == null?null:_cookies.getCookies(); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.http.HttpServletRequest#getDateHeader(java.lang.String) - */ + @Override public long getDateHeader(String name) { return _connection._requestFields.getDateField(name); @@ -442,28 +348,19 @@ throw new UnsupportedOperationException(); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.http.HttpServletRequest#getHeader(java.lang.String) - */ + @Override public String getHeader(String name) { return _connection._requestFields.getStringField(name); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.http.HttpServletRequest#getHeaderNames() - */ + @Override public Enumeration getHeaderNames() { return _connection._requestFields.getFieldNames(); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.http.HttpServletRequest#getHeaders(java.lang.String) - */ + @Override public Enumeration getHeaders(String name) { Enumeration e = _connection._requestFields.getValues(name); @@ -472,19 +369,7 @@ return e; } - /* ------------------------------------------------------------ */ - /** - * @return Returns the inputState. - */ - public int getInputState() - { - return _inputState; - } - - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#getInputStream() - */ + @Override public ServletInputStream getInputStream() throws IOException { if (_inputState != __NONE && _inputState != _STREAM) @@ -493,28 +378,19 @@ return _connection.getInputStream(); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.http.HttpServletRequest#getIntHeader(java.lang.String) - */ + @Override public int getIntHeader(String name) { return (int)_connection._requestFields.getLongField(name); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#getLocalAddr() - */ + @Override public String getLocalAddr() { - return _endp == null?null:_endp.getLocalAddr(); + return _endp.getLocalAddr(); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#getLocale() - */ + @Override public Locale getLocale() { Enumeration enm = _connection._requestFields.getValues( "Accept-Language", ", \t" ); @@ -547,10 +423,7 @@ return Locale.getDefault(); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#getLocales() - */ + @Override public Enumeration getLocales() { @@ -591,43 +464,28 @@ return Collections.enumeration(LazyList.getList(langs)); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#getLocalName() - */ + @Override public String getLocalName() { - if (_endp == null) - return null; - String local = _endp.getLocalAddr(); if (local != null && local.indexOf(':') >= 0) local = "[" + local + "]"; return local; } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#getLocalPort() - */ + @Override public int getLocalPort() { - return _endp == null?0:_endp.getLocalPort(); + return _endp.getLocalPort(); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.http.HttpServletRequest#getMethod() - */ + @Override public String getMethod() { return _method; } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#getParameter(java.lang.String) - */ + @Override public String getParameter(String name) { if (!_paramsExtracted) @@ -635,10 +493,7 @@ return (String)_parameters.getValue(name,0); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#getParameterMap() - */ + @Override public Map getParameterMap() { if (!_paramsExtracted) @@ -647,10 +502,7 @@ return Collections.unmodifiableMap(_parameters.toStringArrayMap()); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#getParameterNames() - */ + @Override public Enumeration getParameterNames() { if (!_paramsExtracted) @@ -658,19 +510,7 @@ return Collections.enumeration(_parameters.keySet()); } - /* ------------------------------------------------------------ */ - /** - * @return Returns the parameters. - */ - public MultiMap<String> getParameters() - { - return _parameters; - } - - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#getParameterValues(java.lang.String) - */ + @Override public String[] getParameterValues(String name) { if (!_paramsExtracted) @@ -681,10 +521,7 @@ return vals.toArray(new String[vals.size()]); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.http.HttpServletRequest#getPathInfo() - */ + @Override public String getPathInfo() { return _pathInfo; @@ -696,19 +533,13 @@ return null; } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#getProtocol() - */ + @Override public String getProtocol() { return _protocol; } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.http.HttpServletRequest#getQueryString() - */ + @Override public String getQueryString() { if (_queryString == null && _uri != null) @@ -718,10 +549,7 @@ return _queryString; } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#getReader() - */ + @Override public BufferedReader getReader() throws IOException { if (_inputState != __NONE && _inputState != __READER) @@ -757,45 +585,28 @@ return null; } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#getRemoteAddr() - */ + @Override public String getRemoteAddr() { - if (_remoteAddr != null) - return _remoteAddr; - return _endp == null?null:_endp.getRemoteAddr(); + return _endp.getRemoteAddr(); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#getRemoteHost() - */ + @Override public String getRemoteHost() { return getRemoteAddr(); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#getRemotePort() - */ + @Override public int getRemotePort() { - return _endp == null?0:_endp.getRemotePort(); + return _endp.getRemotePort(); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.http.HttpServletRequest#getRemoteUser() - */ + @Override public String getRemoteUser() { - Principal p = getUserPrincipal(); - if (p == null) - return null; - return p.getName(); + return null; } @Override @@ -804,19 +615,13 @@ throw new UnsupportedOperationException(); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.http.HttpServletRequest#getRequestedSessionId() - */ + @Override public String getRequestedSessionId() { throw new UnsupportedOperationException(); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.http.HttpServletRequest#getRequestURI() - */ + @Override public String getRequestURI() { if (_requestURI == null && _uri != null) @@ -824,10 +629,7 @@ return _requestURI; } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.http.HttpServletRequest#getRequestURL() - */ + @Override public StringBuffer getRequestURL() { final StringBuffer url = new StringBuffer(48); @@ -851,12 +653,6 @@ } /* ------------------------------------------------------------ */ - public Response getResponse() - { - return _connection._response; - } - - /* ------------------------------------------------------------ */ /** * Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and, but it does not include a * path. @@ -885,19 +681,13 @@ return url; } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#getScheme() - */ + @Override public String getScheme() { return _scheme; } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#getServerName() - */ + @Override public String getServerName() { // Return already determined host @@ -935,8 +725,7 @@ { try { - if (_connection != null) - _connection._generator.sendError(HttpStatus.BAD_REQUEST_400,"Bad Host header",null,true); + _connection._generator.sendError(HttpStatus.BAD_REQUEST_400,"Bad Host header",null,true); } catch (IOException e1) { @@ -956,13 +745,10 @@ } // Return host from connection - if (_connection != null) - { - _serverName = getLocalName(); - _port = getLocalPort(); - if (_serverName != null && !StringUtil.ALL_INTERFACES.equals(_serverName)) - return _serverName; - } + _serverName = getLocalName(); + _port = getLocalPort(); + if (_serverName != null && !StringUtil.ALL_INTERFACES.equals(_serverName)) + return _serverName; // Return the local host try @@ -976,10 +762,7 @@ return _serverName; } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#getServerPort() - */ + @Override public int getServerPort() { if (_port <= 0) @@ -992,7 +775,7 @@ if (_serverName != null && _uri != null) _port = _uri.getPort(); else - _port = _endp == null?0:_endp.getLocalPort(); + _port = _endp.getLocalPort(); } } @@ -1011,36 +794,19 @@ throw new UnsupportedOperationException(); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.http.HttpServletRequest#getServletPath() - */ + @Override public String getServletPath() { - if (_servletPath == null) - _servletPath = ""; - return _servletPath; + throw new UnsupportedOperationException(); } - /* ------------------------------------------------------------ */ - public ServletResponse getServletResponse() + @Override + public HttpSession getSession() { - return _connection.getResponse(); + throw new UnsupportedOperationException(); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.http.HttpServletRequest#getSession() - */ - public HttpSession getSession() - { - return getSession(true); - } - - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.http.HttpServletRequest#getSession(boolean) - */ + @Override public HttpSession getSession(boolean create) { throw new UnsupportedOperationException(); @@ -1059,19 +825,6 @@ /* ------------------------------------------------------------ */ /** - * Get Request TimeStamp - * - * @return The time that the request was received. - */ - public Buffer getTimeStampBuffer() - { - if (_timeStampBuffer == null && _timeStamp > 0) - _timeStampBuffer = formatBuffer(_timeStamp); - return _timeStampBuffer; - } - - /* ------------------------------------------------------------ */ - /** * @return Returns the uri. */ public HttpURI getUri() @@ -1079,103 +832,65 @@ return _uri; } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.http.HttpServletRequest#getUserPrincipal() - */ + @Override public Principal getUserPrincipal() { return null; } - /* ------------------------------------------------------------ */ - /** - * Get timestamp of the request dispatch - * - * @return timestamp - */ - public long getDispatchTime() - { - return _dispatchTime; - } - - /* ------------------------------------------------------------ */ public boolean isHandled() { return _handled; } + @Override public boolean isAsyncStarted() { return false; } - + @Override public boolean isAsyncSupported() { return false; } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromCookie() - */ + @Override public boolean isRequestedSessionIdFromCookie() { throw new UnsupportedOperationException(); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromUrl() - */ + @Override public boolean isRequestedSessionIdFromUrl() { throw new UnsupportedOperationException(); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromURL() - */ + @Override public boolean isRequestedSessionIdFromURL() { throw new UnsupportedOperationException(); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdValid() - */ + @Override public boolean isRequestedSessionIdValid() { throw new UnsupportedOperationException(); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#isSecure() - */ + @Override public boolean isSecure() { return _connection.getConnector().isConfidential(); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.http.HttpServletRequest#isUserInRole(java.lang.String) - */ + @Override public boolean isUserInRole(String role) { return false; } - /* ------------------------------------------------------------ */ - public HttpSession recoverNewSession(Object key) - { - throw new UnsupportedOperationException(); - } - protected void recycle() { if (_inputState == __READER) @@ -1211,9 +926,7 @@ _queryString = null; _requestURI = null; _scheme = URIUtil.HTTP; - _servletPath = null; _timeStamp = 0; - _timeStampBuffer = null; _uri = null; if (_baseParameters != null) _baseParameters.clear(); @@ -1222,10 +935,7 @@ _inputState = __NONE; } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#removeAttribute(java.lang.String) - */ + @Override public void removeAttribute(String name) { if (_attributes != null) @@ -1241,6 +951,7 @@ * * @see javax.servlet.ServletRequest#setAttribute(java.lang.String, java.lang.Object) */ + @Override public void setAttribute(String name, Object value) { if (_attributes == null) @@ -1248,10 +959,7 @@ _attributes.setAttribute(name,value); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#setCharacterEncoding(java.lang.String) - */ + @Override public void setCharacterEncoding(String encoding) throws UnsupportedEncodingException { if (_inputState != __NONE) @@ -1265,358 +973,118 @@ "".getBytes(encoding); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#setCharacterEncoding(java.lang.String) - */ public void setCharacterEncodingUnchecked(String encoding) { _characterEncoding = encoding; } - /* ------------------------------------------------------------ */ - // final so we can safely call this from constructor - protected final void setConnection(AbstractHttpConnection connection) - { - _connection = connection; - _endp = connection.getEndPoint(); - } - - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletRequest#getContentType() - */ - public void setContentType(String contentType) - { - _connection._requestFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,contentType); - - } - - /* ------------------------------------------------------------ */ - /** - * Sets the "context path" for this request - * - * @see HttpServletRequest#getContextPath() - */ public void setContextPath(String contextPath) { _contextPath = contextPath; } - /* ------------------------------------------------------------ */ - /** - * @param cookies - * The cookies to set. - */ +/* public void setCookies(Cookie[] cookies) { if (_cookies == null) _cookies = new CookieCutter(); _cookies.setCookies(cookies); } +*/ - /* ------------------------------------------------------------ */ public void setHandled(boolean h) { _handled = h; } - /* ------------------------------------------------------------ */ - /** - * @param method - * The method to set. - */ public void setMethod(String method) { _method = method; } - /* ------------------------------------------------------------ */ - /** - * @param parameters - * The parameters to set. - */ - public void setParameters(MultiMap<String> parameters) + private void setParameters(MultiMap<String> parameters) { _parameters = (parameters == null)?_baseParameters:parameters; if (_paramsExtracted && _parameters == null) throw new IllegalStateException(); } - /* ------------------------------------------------------------ */ - /** - * @param pathInfo - * The pathInfo to set. - */ public void setPathInfo(String pathInfo) { _pathInfo = pathInfo; } - /* ------------------------------------------------------------ */ - /** - * @param protocol - * The protocol to set. - */ public void setProtocol(String protocol) { _protocol = protocol; } - /* ------------------------------------------------------------ */ - /** - * @param queryString - * The queryString to set. - */ - public void setQueryString(String queryString) - { - _queryString = queryString; - } - - /* ------------------------------------------------------------ */ - /** - * @param addr - * The address to set. - */ - public void setRemoteAddr(String addr) - { - _remoteAddr = addr; - } - - /* ------------------------------------------------------------ */ - /** - * @param host - * The host to set. - */ - public void setRemoteHost(String host) - { - _remoteHost = host; - } - - /* ------------------------------------------------------------ */ - /** - * @param requestURI - * The requestURI to set. - */ public void setRequestURI(String requestURI) { _requestURI = requestURI; } - /* ------------------------------------------------------------ */ - /** - * @param scheme - * The scheme to set. - */ public void setScheme(String scheme) { _scheme = scheme; } - /* ------------------------------------------------------------ */ - /** - * @param host - * The host to set. - */ - public void setServerName(String host) - { - _serverName = host; - } - - /* ------------------------------------------------------------ */ - /** - * @param port - * The port to set. - */ - public void setServerPort(int port) - { - _port = port; - } - - /* ------------------------------------------------------------ */ - /** - * @param servletPath - * The servletPath to set. - */ - public void setServletPath(String servletPath) - { - _servletPath = servletPath; - } - - /* ------------------------------------------------------------ */ public void setTimeStamp(long ts) { _timeStamp = ts; } - /* ------------------------------------------------------------ */ - /** - * @param uri - * The uri to set. - */ public void setUri(HttpURI uri) { _uri = uri; } - /* ------------------------------------------------------------ */ - /** - * Set timetstamp of request dispatch - * - * @param value - * timestamp - */ - public void setDispatchTime(long value) - { - _dispatchTime = value; - } - - /* ------------------------------------------------------------ */ + @Override public AsyncContext startAsync() throws IllegalStateException { throw new UnsupportedOperationException(); } - /* ------------------------------------------------------------ */ + @Override public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) throws IllegalStateException { throw new UnsupportedOperationException(); } - /* ------------------------------------------------------------ */ @Override public String toString() { return (_handled?"[":"(") + getMethod() + " " + _uri + (_handled?"]@":")@") + hashCode() + " " + super.toString(); } - /* ------------------------------------------------------------ */ + @Override public boolean authenticate(HttpServletResponse response) throws IOException, ServletException { throw new UnsupportedOperationException(); } - /* ------------------------------------------------------------ */ + @Override public Part getPart(String name) throws IOException, ServletException { throw new UnsupportedOperationException(); } - /* ------------------------------------------------------------ */ + @Override public Collection<Part> getParts() throws IOException, ServletException { throw new UnsupportedOperationException(); } - /* ------------------------------------------------------------ */ + @Override public void login(String username, String password) throws ServletException { throw new UnsupportedOperationException(); } - /* ------------------------------------------------------------ */ + @Override public void logout() throws ServletException { throw new UnsupportedOperationException(); } - - /* ------------------------------------------------------------ */ - /** - * Merge in a new query string. The query string is merged with the existing parameters and {@link #setParameters(MultiMap)} and - * {@link #setQueryString(String)} are called with the result. The merge is according to the rules of the servlet dispatch forward method. - * - * @param query - * The query string to merge into the request. - */ - public void mergeQueryString(String query) - { - // extract parameters from dispatch query - MultiMap<String> parameters = new MultiMap<String>(); - UrlEncoded.decodeTo(query,parameters, StringUtil.__UTF8); //have to assume UTF-8 because we can't know otherwise - - boolean merge_old_query = false; - - // Have we evaluated parameters - if (!_paramsExtracted) - extractParameters(); - - // Are there any existing parameters? - if (_parameters != null && _parameters.size() > 0) - { - // Merge parameters; new parameters of the same name take precedence. - Iterator<Entry<String, Object>> iter = _parameters.entrySet().iterator(); - while (iter.hasNext()) - { - Map.Entry<String, Object> entry = iter.next(); - String name = entry.getKey(); - - // If the names match, we will need to remake the query string - if (parameters.containsKey(name)) - merge_old_query = true; - - // Add the old values to the new parameter map - Object values = entry.getValue(); - for (int i = 0; i < LazyList.size(values); i++) - parameters.add(name,LazyList.get(values,i)); - } - } - - if (_queryString != null && _queryString.length() > 0) - { - if (merge_old_query) - { - StringBuilder overridden_query_string = new StringBuilder(); - MultiMap<String> overridden_old_query = new MultiMap<String>(); - UrlEncoded.decodeTo(_queryString,overridden_old_query,null);//decode using any queryencoding set for the request - - - MultiMap<String> overridden_new_query = new MultiMap<String>(); - UrlEncoded.decodeTo(query,overridden_new_query,StringUtil.__UTF8); //have to assume utf8 as we cannot know otherwise - - Iterator<Entry<String, Object>> iter = overridden_old_query.entrySet().iterator(); - while (iter.hasNext()) - { - Map.Entry<String, Object> entry = iter.next(); - String name = entry.getKey(); - if (!overridden_new_query.containsKey(name)) - { - Object values = entry.getValue(); - for (int i = 0; i < LazyList.size(values); i++) - { - overridden_query_string.append("&").append(name).append("=").append((Object)LazyList.get(values,i)); - } - } - } - - query = query + overridden_query_string; - } - else - { - query = query + "&" + _queryString; - } - } - - setParameters(parameters); - setQueryString(query); - } - - - private static Buffer _buffer; - private static String _last; - private static final DateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US); - static { - dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); - } - - private static Buffer formatBuffer(long date) { - synchronized(dateFormat) { - String d = dateFormat.format(date); - if (d==_last) - return _buffer; - _last=d; - _buffer=new ByteArrayBuffer(d); - return _buffer; - } - } }
diff -r d9cfec64899c -r 7d28be82ab75 src/org/eclipse/jetty/server/Server.java --- a/src/org/eclipse/jetty/server/Server.java Tue Oct 18 21:22:53 2016 -0600 +++ b/src/org/eclipse/jetty/server/Server.java Tue Oct 18 22:43:17 2016 -0600 @@ -142,9 +142,9 @@ */ public void handle(AbstractHttpConnection connection) throws IOException, ServletException { - final String target=connection.getRequest().getPathInfo(); - final Request request=connection.getRequest(); - final Response response=connection.getResponse(); + final String target = connection.getRequest().getPathInfo(); + final Request request = connection.getRequest(); + final Response response = connection.getResponse(); if (LOG.isDebugEnabled()) {
diff -r d9cfec64899c -r 7d28be82ab75 src/org/eclipse/jetty/server/handler/ContextHandler.java --- a/src/org/eclipse/jetty/server/handler/ContextHandler.java Tue Oct 18 21:22:53 2016 -0600 +++ b/src/org/eclipse/jetty/server/handler/ContextHandler.java Tue Oct 18 22:43:17 2016 -0600 @@ -184,11 +184,7 @@ @Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - if (LOG.isDebugEnabled()) - LOG.debug("scope {}|{}|{} @ {}",baseRequest.getContextPath(),baseRequest.getServletPath(),baseRequest.getPathInfo(),this); - String old_context_path = null; - String old_servlet_path = null; String old_path_info = null; String pathInfo = target; @@ -221,7 +217,6 @@ try { old_context_path = baseRequest.getContextPath(); - old_servlet_path = baseRequest.getServletPath(); old_path_info = baseRequest.getPathInfo(); // Update the paths @@ -232,13 +227,9 @@ baseRequest.setContextPath(""); else baseRequest.setContextPath(_contextPath); - baseRequest.setServletPath(null); baseRequest.setPathInfo(pathInfo); } - if (LOG.isDebugEnabled()) - LOG.debug("context={}|{}|{} @ {}",baseRequest.getContextPath(),baseRequest.getServletPath(), baseRequest.getPathInfo(),this); - try { super.handle(target,baseRequest,request,response); @@ -257,7 +248,6 @@ // reset the context and servlet path. baseRequest._contextHandler = oldContextHandler; baseRequest.setContextPath(old_context_path); - baseRequest.setServletPath(old_servlet_path); baseRequest.setPathInfo(old_path_info); } }
diff -r d9cfec64899c -r 7d28be82ab75 src/org/eclipse/jetty/server/handler/RequestLogHandler.java --- a/src/org/eclipse/jetty/server/handler/RequestLogHandler.java Tue Oct 18 21:22:53 2016 -0600 +++ b/src/org/eclipse/jetty/server/handler/RequestLogHandler.java Tue Oct 18 22:43:17 2016 -0600 @@ -61,8 +61,6 @@ public void handle(String target, final Request baseRequest, HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException { - baseRequest.setDispatchTime(System.currentTimeMillis()); - try { super.handle(target, baseRequest, request, response); @@ -112,7 +110,6 @@ public boolean logLatency = false; public boolean logCookies = false; public boolean logServer = false; - public boolean logDispatch = false; private transient OutputStream _out; private transient DateFormat dateFormat; @@ -217,17 +214,10 @@ } } - if (logDispatch || logLatency) + if (logLatency) { long now = System.currentTimeMillis(); - if (logDispatch) - { - long d = request.getDispatchTime(); - buf.append(' '); - buf.append(now - (d==0 ? request.getTimeStamp():d)); - } - if (logLatency) { buf.append(' ');
diff -r d9cfec64899c -r 7d28be82ab75 src/org/eclipse/jetty/server/handler/ResourceHandler.java --- a/src/org/eclipse/jetty/server/handler/ResourceHandler.java Tue Oct 18 21:22:53 2016 -0600 +++ b/src/org/eclipse/jetty/server/handler/ResourceHandler.java Tue Oct 18 22:43:17 2016 -0600 @@ -252,8 +252,9 @@ _cacheControl=cacheControl==null?null:new ByteArrayBuffer(cacheControl); } - private Resource getResource(Request request,String path) throws MalformedURLException + private Resource getResource(Request request) throws MalformedURLException { + String path = request.getPathInfo(); if (path==null || !path.startsWith("/")) throw new MalformedURLException(path); @@ -281,32 +282,6 @@ return null; } - private Resource getResource(Request request) throws MalformedURLException - { - String servletPath; - String pathInfo; - Boolean included = request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI) != null; - if (included != null && included.booleanValue()) - { - servletPath = (String)request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH); - pathInfo = (String)request.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO); - - if (servletPath == null && pathInfo == null) - { - servletPath = request.getServletPath(); - pathInfo = request.getPathInfo(); - } - } - else - { - servletPath = request.getServletPath(); - pathInfo = request.getPathInfo(); - } - - String pathInContext = URIUtil.addPaths(servletPath,pathInfo); - return getResource(request,pathInContext); - } - /* ------------------------------------------------------------ */ public String[] getWelcomeFiles()