324110 Merge async dispatch parameters
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2228 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
2dcf4b2c43
commit
9e728c5d52
|
@ -18,6 +18,7 @@ jetty-7.2-SNAPSHOT
|
|||
+ 323196 org.mortbay properties to org.eclipse
|
||||
+ 323435 MovedContextHandler permanent redirection
|
||||
+ 323464 IPv6 localhost with no Host header
|
||||
+ 324110 Merge async dispatch parameters
|
||||
+ JETTY-912 added per exchange timeout api
|
||||
+ JETTY-1245 Do not use direct buffers with NIO SSL
|
||||
+ JETTY-1249 Apply max idle time to all connectors
|
||||
|
|
|
@ -218,7 +218,7 @@ public class Dispatcher implements RequestDispatcher
|
|||
final String old_query=baseRequest.getQueryString();
|
||||
final Attributes old_attr=baseRequest.getAttributes();
|
||||
final DispatcherType old_type=baseRequest.getDispatcherType();
|
||||
MultiMap old_params=baseRequest.getParameters();
|
||||
MultiMap<String> old_params=baseRequest.getParameters();
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -240,77 +240,7 @@ public class Dispatcher implements RequestDispatcher
|
|||
old_params=baseRequest.getParameters();
|
||||
}
|
||||
|
||||
// extract parameters from dispatch query
|
||||
MultiMap parameters=new MultiMap();
|
||||
UrlEncoded.decodeTo(query,parameters,request.getCharacterEncoding());
|
||||
|
||||
boolean merge_old_query = false;
|
||||
|
||||
// Have we evaluated parameters
|
||||
if( old_params == null )
|
||||
{
|
||||
// no - so force parameters to be evaluated
|
||||
baseRequest.getParameterNames();
|
||||
old_params = baseRequest.getParameters();
|
||||
}
|
||||
|
||||
// Are there any existing parameters?
|
||||
if (old_params!=null && old_params.size()>0)
|
||||
{
|
||||
// Merge parameters; new parameters of the same name take precedence.
|
||||
Iterator iter = old_params.entrySet().iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
Map.Entry entry = (Map.Entry)iter.next();
|
||||
String name=(String)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 (old_query != null && old_query.length()>0)
|
||||
{
|
||||
if ( merge_old_query )
|
||||
{
|
||||
StringBuilder overridden_query_string = new StringBuilder();
|
||||
MultiMap overridden_old_query = new MultiMap();
|
||||
UrlEncoded.decodeTo(old_query,overridden_old_query,request.getCharacterEncoding());
|
||||
|
||||
MultiMap overridden_new_query = new MultiMap();
|
||||
UrlEncoded.decodeTo(query,overridden_new_query,request.getCharacterEncoding());
|
||||
|
||||
Iterator iter = overridden_old_query.entrySet().iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
Map.Entry entry = (Map.Entry)iter.next();
|
||||
String name=(String)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(LazyList.get(values, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
query = query + overridden_query_string;
|
||||
}
|
||||
else
|
||||
{
|
||||
query=query+"&"+old_query;
|
||||
}
|
||||
}
|
||||
|
||||
baseRequest.setParameters(parameters);
|
||||
baseRequest.setQueryString(query);
|
||||
baseRequest.mergeQueryString(query);
|
||||
}
|
||||
|
||||
ForwardAttributes attr = new ForwardAttributes(old_attr);
|
||||
|
@ -336,12 +266,9 @@ public class Dispatcher implements RequestDispatcher
|
|||
attr._servletPath=old_servlet_path;
|
||||
}
|
||||
|
||||
|
||||
|
||||
baseRequest.setRequestURI(_uri);
|
||||
baseRequest.setContextPath(_contextHandler.getContextPath());
|
||||
baseRequest.setAttributes(attr);
|
||||
baseRequest.setQueryString(query);
|
||||
|
||||
_contextHandler.handle(_path,baseRequest, (HttpServletRequest)request, (HttpServletResponse)response);
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletContext;
|
||||
|
@ -683,7 +684,7 @@ public class Request implements HttpServletRequest
|
|||
/**
|
||||
* @return Returns the parameters.
|
||||
*/
|
||||
public MultiMap getParameters()
|
||||
public MultiMap<String> getParameters()
|
||||
{
|
||||
return _parameters;
|
||||
}
|
||||
|
@ -696,7 +697,7 @@ public class Request implements HttpServletRequest
|
|||
{
|
||||
if (!_paramsExtracted)
|
||||
extractParameters();
|
||||
List vals = _parameters.getValues(name);
|
||||
List<Object> vals = _parameters.getValues(name);
|
||||
if (vals==null)
|
||||
return null;
|
||||
return (String[])vals.toArray(new String[vals.size()]);
|
||||
|
@ -1635,7 +1636,7 @@ public class Request implements HttpServletRequest
|
|||
/**
|
||||
* @param parameters The parameters to set.
|
||||
*/
|
||||
public void setParameters(MultiMap parameters)
|
||||
public void setParameters(MultiMap<String> parameters)
|
||||
{
|
||||
_parameters= (parameters==null)?_baseParameters:parameters;
|
||||
if (_paramsExtracted && _parameters==null)
|
||||
|
@ -1840,5 +1841,76 @@ public class Request implements HttpServletRequest
|
|||
return (_handled?"[":"(")+getMethod()+" "+_uri+(_handled?"]@":")@")+hashCode()+" "+super.toString();
|
||||
}
|
||||
|
||||
|
||||
public void mergeQueryString(String query)
|
||||
{
|
||||
// extract parameters from dispatch query
|
||||
MultiMap<String> parameters=new MultiMap<String>();
|
||||
UrlEncoded.decodeTo(query,parameters,getCharacterEncoding());
|
||||
|
||||
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,getCharacterEncoding());
|
||||
|
||||
MultiMap<String> overridden_new_query = new MultiMap<String>();
|
||||
UrlEncoded.decodeTo(query,overridden_new_query,getCharacterEncoding());
|
||||
|
||||
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(LazyList.get(values, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
query = query + overridden_query_string;
|
||||
}
|
||||
else
|
||||
{
|
||||
query=query+"&"+_queryString;
|
||||
}
|
||||
}
|
||||
|
||||
setParameters(parameters);
|
||||
setQueryString(query);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -365,6 +365,7 @@ public class Server extends HandlerWrapper implements Attributes
|
|||
|
||||
final Request baseRequest=connection.getRequest();
|
||||
final String path=state.getPath();
|
||||
|
||||
if (path!=null)
|
||||
{
|
||||
// this is a dispatch with a path
|
||||
|
@ -378,7 +379,8 @@ public class Server extends HandlerWrapper implements Attributes
|
|||
baseRequest.setUri(uri);
|
||||
baseRequest.setRequestURI(null);
|
||||
baseRequest.setPathInfo(baseRequest.getRequestURI());
|
||||
baseRequest.setQueryString(uri.getQuery());
|
||||
if (uri.getQuery()!=null)
|
||||
baseRequest.mergeQueryString(uri.getQuery());
|
||||
}
|
||||
|
||||
final String target=baseRequest.getPathInfo();
|
||||
|
@ -393,6 +395,7 @@ public class Server extends HandlerWrapper implements Attributes
|
|||
}
|
||||
else
|
||||
handle(target, baseRequest, request, response);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -173,9 +173,9 @@ public class DispatcherTest
|
|||
assertEquals( null, request.getAttribute(Dispatcher.FORWARD_PATH_INFO));
|
||||
assertEquals( "do=assertforward&do=more&test=1", request.getAttribute(Dispatcher.FORWARD_QUERY_STRING) );
|
||||
|
||||
List expectedAttributeNames = Arrays.asList(Dispatcher.FORWARD_REQUEST_URI, Dispatcher.FORWARD_CONTEXT_PATH,
|
||||
List<String> expectedAttributeNames = Arrays.asList(Dispatcher.FORWARD_REQUEST_URI, Dispatcher.FORWARD_CONTEXT_PATH,
|
||||
Dispatcher.FORWARD_SERVLET_PATH, Dispatcher.FORWARD_QUERY_STRING);
|
||||
List requestAttributeNames = Collections.list(request.getAttributeNames());
|
||||
List<String> requestAttributeNames = Collections.list(request.getAttributeNames());
|
||||
assertTrue(requestAttributeNames.containsAll(expectedAttributeNames));
|
||||
|
||||
assertEquals(null, request.getPathInfo());
|
||||
|
|
|
@ -71,7 +71,7 @@ public class MultiMap<K> implements ConcurrentMap<K,Object>
|
|||
* @param name The entry key.
|
||||
* @return Unmodifieable List of values.
|
||||
*/
|
||||
public List getValues(Object name)
|
||||
public List<Object> getValues(Object name)
|
||||
{
|
||||
return LazyList.getList(_map.get(name),true);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue