@ -51,7 +51,6 @@ import org.springframework.web.servlet.DispatcherServlet;
@@ -51,7 +51,6 @@ import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.FlashMap ;
import org.springframework.web.servlet.FlashMapManager ;
import org.springframework.web.servlet.support.SessionFlashMapManager ;
import org.springframework.web.util.UriComponents ;
import org.springframework.web.util.UriComponentsBuilder ;
import org.springframework.web.util.UriUtils ;
@ -72,7 +71,7 @@ public class MockHttpServletRequestBuilder
@@ -72,7 +71,7 @@ public class MockHttpServletRequestBuilder
private final HttpMethod method ;
private final UriComponents uriComponents ;
private final URI url ;
private final MultiValueMap < String , Object > headers = new LinkedMultiValueMap < String , Object > ( ) ;
@ -116,14 +115,11 @@ public class MockHttpServletRequestBuilder
@@ -116,14 +115,11 @@ public class MockHttpServletRequestBuilder
* the { @code MockHttpServletRequest } can be plugged in via
* { @link # with ( RequestPostProcessor ) } .
* @param httpMethod the HTTP method ( GET , POST , etc )
* @param urlTemplate a URL template ; the resulting URL will be encoded
* @param urlVariable s zero or more URL variables
* @param url a URL template ; the resulting URL will be encoded
* @param var s zero or more URL variables
* /
MockHttpServletRequestBuilder ( HttpMethod httpMethod , String urlTemplate , Object . . . urlVariables ) {
Assert . notNull ( httpMethod , "httpMethod is required" ) ;
Assert . notNull ( urlTemplate , "uriTemplate is required" ) ;
this . method = httpMethod ;
this . uriComponents = UriComponentsBuilder . fromUriString ( urlTemplate ) . buildAndExpand ( urlVariables ) . encode ( ) ;
MockHttpServletRequestBuilder ( HttpMethod httpMethod , String url , Object . . . vars ) {
this ( httpMethod , UriComponentsBuilder . fromUriString ( url ) . buildAndExpand ( vars ) . encode ( ) . toUri ( ) ) ;
}
/ * *
@ -133,14 +129,14 @@ public class MockHttpServletRequestBuilder
@@ -133,14 +129,14 @@ public class MockHttpServletRequestBuilder
* the { @code MockHttpServletRequest } can be plugged in via
* { @link # with ( RequestPostProcessor ) } .
* @param httpMethod the HTTP method ( GET , POST , etc )
* @param uri the URL
* @param url the URL
* @since 4 . 0 . 3
* /
MockHttpServletRequestBuilder ( HttpMethod httpMethod , URI uri ) {
MockHttpServletRequestBuilder ( HttpMethod httpMethod , URI url ) {
Assert . notNull ( httpMethod , "httpMethod is required" ) ;
Assert . notNull ( uri , "uri is required" ) ;
Assert . notNull ( url , "url is required" ) ;
this . method = httpMethod ;
this . uriComponents = UriComponentsBuilder . fromUri ( uri ) . build ( ) ;
this . url = url ;
}
@ -559,18 +555,18 @@ public class MockHttpServletRequestBuilder
@@ -559,18 +555,18 @@ public class MockHttpServletRequestBuilder
public final MockHttpServletRequest buildRequest ( ServletContext servletContext ) {
MockHttpServletRequest request = createServletRequest ( servletContext ) ;
String requestUri = this . uriComponents . getPath ( ) ;
String requestUri = this . url . getRaw Path ( ) ;
request . setRequestURI ( requestUri ) ;
updatePathRequestProperties ( request , requestUri ) ;
if ( this . uriComponents . getScheme ( ) ! = null ) {
request . setScheme ( this . uriComponents . getScheme ( ) ) ;
if ( this . url . getScheme ( ) ! = null ) {
request . setScheme ( this . url . getScheme ( ) ) ;
}
if ( this . uriComponents . getHost ( ) ! = null ) {
request . setServerName ( uriComponents . getHost ( ) ) ;
if ( this . url . getHost ( ) ! = null ) {
request . setServerName ( this . url . getHost ( ) ) ;
}
if ( this . uriComponents . getPort ( ) ! = - 1 ) {
request . setServerPort ( this . uriComponents . getPort ( ) ) ;
if ( this . url . getPort ( ) ! = - 1 ) {
request . setServerPort ( this . url . getPort ( ) ) ;
}
request . setMethod ( this . method . name ( ) ) ;
@ -582,11 +578,14 @@ public class MockHttpServletRequestBuilder
@@ -582,11 +578,14 @@ public class MockHttpServletRequestBuilder
}
try {
if ( this . uriComponents . getQuery ( ) ! = null ) {
request . setQueryString ( this . uriComponents . getQuery ( ) ) ;
if ( this . url . getRaw Query ( ) ! = null ) {
request . setQueryString ( this . url . getRaw Query ( ) ) ;
}
for ( Entry < String , List < String > > entry : this . uriComponents . getQueryParams ( ) . entrySet ( ) ) {
MultiValueMap < String , String > queryParams =
UriComponentsBuilder . fromUri ( this . url ) . build ( ) . getQueryParams ( ) ;
for ( Entry < String , List < String > > entry : queryParams . entrySet ( ) ) {
for ( String value : entry . getValue ( ) ) {
value = ( value ! = null ) ? UriUtils . decode ( value , "UTF-8" ) : null ;
request . addParameter ( UriUtils . decode ( entry . getKey ( ) , "UTF-8" ) , value ) ;