fix DispatcherForwardTest

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2022-07-26 13:34:59 +10:00
parent 69c83c76a6
commit ce3c0b7036
2 changed files with 16 additions and 12 deletions

View File

@ -204,11 +204,19 @@ public class Dispatcher implements RequestDispatcher
private class ForwardRequest extends ParameterRequestWrapper
{
private final HttpServletRequest _httpServletRequest;
private final MultiMap<String> _params = new MultiMap<>();
private MultiMap<String> _params;
public ForwardRequest(HttpServletRequest httpRequest)
{
super(httpRequest);
_httpServletRequest = httpRequest;
}
private MultiMap<String> getParams()
{
if (_params != null)
return _params;
_params = new MultiMap<>();
String targetQuery = (_uri == null) ? null : _uri.getQuery();
if (targetQuery != null)
@ -217,16 +225,15 @@ public class Dispatcher implements RequestDispatcher
UrlEncoded.decodeTo(targetQuery, _params, UrlEncoded.ENCODING);
}
Enumeration<String> parameterNames = httpRequest.getParameterNames();
Enumeration<String> parameterNames = _httpServletRequest.getParameterNames();
while (parameterNames.hasMoreElements())
{
String name = parameterNames.nextElement();
String[] parameterValues = httpRequest.getParameterValues(name);
String[] parameterValues = _httpServletRequest.getParameterValues(name);
if (parameterValues != null)
_params.addValues(name, parameterValues);
}
_httpServletRequest = httpRequest;
return _params;
}
@Override
@ -272,25 +279,25 @@ public class Dispatcher implements RequestDispatcher
@Override
public String getParameter(String name)
{
return _params.getValue(name);
return getParams().getValue(name);
}
@Override
public Map<String, String[]> getParameterMap()
{
return Collections.unmodifiableMap(_params.toStringArrayMap());
return Collections.unmodifiableMap(getParams().toStringArrayMap());
}
@Override
public Enumeration<String> getParameterNames()
{
return Collections.enumeration(_params.keySet());
return Collections.enumeration(getParams().keySet());
}
@Override
public String[] getParameterValues(String name)
{
List<String> vals = _params.getValues(name);
List<String> vals = getParams().getValues(name);
if (vals == null)
return null;
return vals.toArray(new String[0]);

View File

@ -29,7 +29,6 @@ import org.eclipse.jetty.server.Server;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
@ -451,7 +450,6 @@ public class DispatcherForwardTest
}
@Test
@Disabled // TODO
public void testContentCanBeReadViaInputStreamAfterForwardWithoutQuery() throws Exception
{
CountDownLatch latch = new CountDownLatch(1);
@ -501,7 +499,6 @@ public class DispatcherForwardTest
}
@Test
@Disabled // TODO
public void testContentCanBeReadViaInputStreamAfterForwardWithQuery() throws Exception
{
CountDownLatch latch = new CountDownLatch(1);