Upgrade to HtmlUnit 2.25 and Jackson 2.9 PR1
Includes Log4J 2.8.1 and Selenium 3.2 as well. Issue: SPR-15319
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,6 +19,8 @@ package org.springframework.test.web.servlet.htmlunit;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
@@ -59,7 +61,7 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||
* Internal class used to transform a {@link WebRequest} into a
|
||||
* {@link MockHttpServletRequest} using Spring MVC Test's {@link RequestBuilder}.
|
||||
*
|
||||
* <p>By default the first path segment of the URL is used as the contextPath.
|
||||
* <p>By default the first path segment of the URL is used as the context path.
|
||||
* To override this default see {@link #setContextPath(String)}.
|
||||
*
|
||||
* @author Rob Winch
|
||||
@@ -71,6 +73,7 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
|
||||
|
||||
private static final Pattern LOCALE_PATTERN = Pattern.compile("^\\s*(\\w{2})(?:-(\\w{2}))?(?:;q=(\\d+\\.\\d+))?$");
|
||||
|
||||
|
||||
private final Map<String, MockHttpSession> sessions;
|
||||
|
||||
private final WebClient webClient;
|
||||
@@ -98,23 +101,23 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
|
||||
Assert.notNull(sessions, "Sessions Map must not be null");
|
||||
Assert.notNull(webClient, "WebClient must not be null");
|
||||
Assert.notNull(webRequest, "WebRequest must not be null");
|
||||
|
||||
this.sessions = sessions;
|
||||
this.webClient = webClient;
|
||||
this.webRequest = webRequest;
|
||||
}
|
||||
|
||||
|
||||
public MockHttpServletRequest buildRequest(ServletContext servletContext) {
|
||||
String charset = getCharset();
|
||||
Charset charset = getCharset();
|
||||
String httpMethod = this.webRequest.getHttpMethod().name();
|
||||
UriComponents uriComponents = uriComponents();
|
||||
|
||||
MockHttpServletRequest request = new HtmlUnitMockHttpServletRequest(
|
||||
servletContext, httpMethod, uriComponents.getPath());
|
||||
parent(request, this.parentBuilder);
|
||||
request.setServerName(uriComponents.getHost()); // needs to be first for additional headers
|
||||
request.setServerName(uriComponents.getHost()); // needs to be first for additional headers
|
||||
authType(request);
|
||||
request.setCharacterEncoding(charset);
|
||||
request.setCharacterEncoding(charset.name());
|
||||
content(request, charset);
|
||||
contextPath(request, uriComponents);
|
||||
contentType(request);
|
||||
@@ -132,6 +135,11 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
|
||||
return postProcess(request);
|
||||
}
|
||||
|
||||
private Charset getCharset() {
|
||||
Charset charset = this.webRequest.getCharset();
|
||||
return (charset != null ? charset : StandardCharsets.ISO_8859_1);
|
||||
}
|
||||
|
||||
private MockHttpServletRequest postProcess(MockHttpServletRequest request) {
|
||||
if (this.parentPostProcessor != null) {
|
||||
request = this.parentPostProcessor.postProcessRequest(request);
|
||||
@@ -220,17 +228,12 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
|
||||
}
|
||||
}
|
||||
|
||||
private void content(MockHttpServletRequest request, String charset) {
|
||||
private void content(MockHttpServletRequest request, Charset charset) {
|
||||
String requestBody = this.webRequest.getRequestBody();
|
||||
if (requestBody == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
request.setContent(requestBody.getBytes(charset));
|
||||
}
|
||||
catch (UnsupportedEncodingException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
request.setContent(requestBody.getBytes(charset));
|
||||
}
|
||||
|
||||
private void contentType(MockHttpServletRequest request) {
|
||||
@@ -301,14 +304,6 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
|
||||
}
|
||||
}
|
||||
|
||||
private String getCharset() {
|
||||
String charset = this.webRequest.getCharset();
|
||||
if (charset == null) {
|
||||
return "ISO-8859-1";
|
||||
}
|
||||
return charset;
|
||||
}
|
||||
|
||||
private String header(String headerName) {
|
||||
return this.webRequest.getAdditionalHeaders().get(headerName);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user