Polishing
This commit is contained in:
parent
80a0cf71f4
commit
e5c1deea63
|
@ -101,6 +101,7 @@ public class MockMultipartFile implements MultipartFile {
|
|||
this(name, originalFilename, contentType, FileCopyUtils.copyToByteArray(contentStream));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
|
|
|
@ -21,7 +21,6 @@ import java.util.Enumeration;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
|
|
@ -121,11 +121,12 @@ public class ServletHttpHandlerAdapter implements Servlet {
|
|||
this.servletPath = getServletPath(config);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getServletPath(ServletConfig config) {
|
||||
String name = config.getServletName();
|
||||
ServletRegistration registration = config.getServletContext().getServletRegistration(name);
|
||||
Assert.notNull(registration, "ServletRegistration not found for Servlet '" + name + "'.");
|
||||
if (registration == null) {
|
||||
throw new IllegalStateException("ServletRegistration not found for Servlet '" + name + "'");
|
||||
}
|
||||
|
||||
Collection<String> mappings = registration.getMappings();
|
||||
if (mappings.size() == 1) {
|
||||
|
@ -136,16 +137,16 @@ public class ServletHttpHandlerAdapter implements Servlet {
|
|||
if (mapping.endsWith("/*")) {
|
||||
String path = mapping.substring(0, mapping.length() - 2);
|
||||
if (!path.isEmpty()) {
|
||||
logger.info("Found Servlet mapping '" + path + "' for Servlet '" + name + "'.");
|
||||
logger.info("Found Servlet mapping '" + path + "' for Servlet '" + name + "'");
|
||||
}
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Expected a single Servlet mapping -- " +
|
||||
throw new IllegalArgumentException("Expected a single Servlet mapping: " +
|
||||
"either the default Servlet mapping (i.e. '/'), " +
|
||||
"or a path based mapping (e.g. '/*', '/foo/*'). " +
|
||||
"Actual mappings: " + mappings + " for Servlet '" + name + "'.");
|
||||
"Actual mappings: " + mappings + " for Servlet '" + name + "'");
|
||||
}
|
||||
|
||||
|
||||
|
@ -168,18 +169,13 @@ public class ServletHttpHandlerAdapter implements Servlet {
|
|||
this.httpHandler.handle(httpRequest, httpResponse).subscribe(subscriber);
|
||||
}
|
||||
|
||||
protected ServerHttpRequest createRequest(HttpServletRequest request, AsyncContext context)
|
||||
throws IOException {
|
||||
|
||||
Assert.notNull(this.servletPath, "servletPath is not initialized.");
|
||||
|
||||
protected ServerHttpRequest createRequest(HttpServletRequest request, AsyncContext context) throws IOException {
|
||||
Assert.notNull(this.servletPath, "Servlet path is not initialized");
|
||||
return new ServletServerHttpRequest(
|
||||
request, context, this.servletPath, getDataBufferFactory(), getBufferSize());
|
||||
}
|
||||
|
||||
protected ServerHttpResponse createResponse(HttpServletResponse response, AsyncContext context)
|
||||
throws IOException {
|
||||
|
||||
protected ServerHttpResponse createResponse(HttpServletResponse response, AsyncContext context) throws IOException {
|
||||
return new ServletServerHttpResponse(response, context, getDataBufferFactory(), getBufferSize());
|
||||
}
|
||||
|
||||
|
@ -219,25 +215,25 @@ public class ServletHttpHandlerAdapter implements Servlet {
|
|||
private final static AsyncListener ERROR_LISTENER = new AsyncListener() {
|
||||
|
||||
@Override
|
||||
public void onTimeout(AsyncEvent event) throws IOException {
|
||||
public void onTimeout(AsyncEvent event) {
|
||||
AsyncContext context = event.getAsyncContext();
|
||||
runIfAsyncNotComplete(context, context::complete);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(AsyncEvent event) throws IOException {
|
||||
public void onError(AsyncEvent event) {
|
||||
AsyncContext context = event.getAsyncContext();
|
||||
runIfAsyncNotComplete(context, context::complete);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartAsync(AsyncEvent event) throws IOException {
|
||||
// No-op
|
||||
public void onStartAsync(AsyncEvent event) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete(AsyncEvent event) throws IOException {
|
||||
// No-op
|
||||
public void onComplete(AsyncEvent event) {
|
||||
// no-op
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -246,7 +242,7 @@ public class ServletHttpHandlerAdapter implements Servlet {
|
|||
|
||||
private final AsyncContext asyncContext;
|
||||
|
||||
HandlerResultSubscriber(AsyncContext asyncContext) {
|
||||
public HandlerResultSubscriber(AsyncContext asyncContext) {
|
||||
this.asyncContext = asyncContext;
|
||||
}
|
||||
|
||||
|
@ -257,7 +253,7 @@ public class ServletHttpHandlerAdapter implements Servlet {
|
|||
|
||||
@Override
|
||||
public void onNext(Void aVoid) {
|
||||
// no op
|
||||
// no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -40,7 +40,9 @@ class HeaderValueHolder {
|
|||
|
||||
public void setValue(Object value) {
|
||||
this.values.clear();
|
||||
this.values.add(value);
|
||||
if (value != null) {
|
||||
this.values.add(value);
|
||||
}
|
||||
}
|
||||
|
||||
public void addValue(Object value) {
|
||||
|
|
|
@ -21,8 +21,6 @@ import javax.servlet.jsp.PageContext;
|
|||
|
||||
import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Mock implementation of the JSP 2.0 {@link javax.servlet.jsp.el.ExpressionEvaluator}
|
||||
* interface, delegating to the Apache JSTL ExpressionEvaluatorManager.
|
||||
|
@ -57,9 +55,7 @@ public class MockExpressionEvaluator extends javax.servlet.jsp.el.ExpressionEval
|
|||
|
||||
return new javax.servlet.jsp.el.Expression() {
|
||||
@Override
|
||||
public Object evaluate(javax.servlet.jsp.el.VariableResolver variableResolver)
|
||||
throws javax.servlet.jsp.el.ELException {
|
||||
|
||||
public Object evaluate(javax.servlet.jsp.el.VariableResolver variableResolver) throws javax.servlet.jsp.el.ELException {
|
||||
return doEvaluate(expression, expectedType, functionMapper);
|
||||
}
|
||||
};
|
||||
|
@ -67,26 +63,21 @@ public class MockExpressionEvaluator extends javax.servlet.jsp.el.ExpressionEval
|
|||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Object evaluate(String expression, Class expectedType,
|
||||
javax.servlet.jsp.el.VariableResolver variableResolver,
|
||||
public Object evaluate(String expression, Class expectedType, javax.servlet.jsp.el.VariableResolver variableResolver,
|
||||
javax.servlet.jsp.el.FunctionMapper functionMapper) throws javax.servlet.jsp.el.ELException {
|
||||
|
||||
Assert.isNull(variableResolver, "Custom VariableResolver not supported");
|
||||
return doEvaluate(expression, expectedType, functionMapper);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected Object doEvaluate(String expression, Class expectedType,
|
||||
javax.servlet.jsp.el.FunctionMapper functionMapper) throws javax.servlet.jsp.el.ELException {
|
||||
protected Object doEvaluate(String expression, Class expectedType, javax.servlet.jsp.el.FunctionMapper functionMapper)
|
||||
throws javax.servlet.jsp.el.ELException {
|
||||
|
||||
Assert.isNull(functionMapper, "Custom FunctionMapper not supported");
|
||||
try {
|
||||
return ExpressionEvaluatorManager.evaluate(
|
||||
"JSP EL expression", expression, expectedType, this.pageContext);
|
||||
return ExpressionEvaluatorManager.evaluate("JSP EL expression", expression, expectedType, this.pageContext);
|
||||
}
|
||||
catch (JspException ex) {
|
||||
throw new javax.servlet.jsp.el.ELException(
|
||||
"Parsing of JSP EL expression \"" + expression + "\" failed", ex);
|
||||
throw new javax.servlet.jsp.el.ELException("Parsing of JSP EL expression \"" + expression + "\" failed", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,6 @@ import org.springframework.util.ObjectUtils;
|
|||
* @author Juergen Hoeller
|
||||
* @author Rob Winch
|
||||
* @author Rossen Stoyanchev
|
||||
*
|
||||
* @since 2.0.3
|
||||
* @see MockFilterConfig
|
||||
* @see PassThroughFilterChain
|
||||
|
@ -70,7 +69,6 @@ public class MockFilterChain implements FilterChain {
|
|||
|
||||
/**
|
||||
* Create a FilterChain with a Servlet.
|
||||
*
|
||||
* @param servlet the Servlet to invoke
|
||||
* @since 3.2
|
||||
*/
|
||||
|
@ -80,7 +78,6 @@ public class MockFilterChain implements FilterChain {
|
|||
|
||||
/**
|
||||
* Create a {@code FilterChain} with Filter's and a Servlet.
|
||||
*
|
||||
* @param servlet the {@link Servlet} to invoke in this {@link FilterChain}
|
||||
* @param filters the {@link Filter}'s to invoke in this {@link FilterChain}
|
||||
* @since 3.2
|
||||
|
@ -96,6 +93,7 @@ public class MockFilterChain implements FilterChain {
|
|||
return Arrays.asList(allFilters);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the request that {@link #doFilter} has been called with.
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
|
|
|
@ -267,7 +267,7 @@ public class MockPageContext extends PageContext {
|
|||
return this.request.getAttributeNames();
|
||||
case SESSION_SCOPE:
|
||||
HttpSession session = this.request.getSession(false);
|
||||
return (session != null ? session.getAttributeNames() : null);
|
||||
return (session != null ? session.getAttributeNames() : Collections.emptyEnumeration());
|
||||
case APPLICATION_SCOPE:
|
||||
return this.servletContext.getAttributeNames();
|
||||
default:
|
||||
|
|
|
@ -141,6 +141,7 @@ public class MockServletContext implements ServletContext {
|
|||
|
||||
private final Map<String, MediaType> mimeTypes = new LinkedHashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* Create a new {@code MockServletContext}, using no base path and a
|
||||
* {@link DefaultResourceLoader} (i.e. the classpath root as WAR root).
|
||||
|
@ -179,7 +180,7 @@ public class MockServletContext implements ServletContext {
|
|||
*/
|
||||
public MockServletContext(String resourceBasePath, ResourceLoader resourceLoader) {
|
||||
this.resourceLoader = (resourceLoader != null ? resourceLoader : new DefaultResourceLoader());
|
||||
this.resourceBasePath = (resourceBasePath != null ? resourceBasePath : "");
|
||||
this.resourceBasePath = resourceBasePath;
|
||||
|
||||
// Use JVM temp dir as ServletContext temp dir.
|
||||
String tempDir = System.getProperty(TEMP_DIR_SYSTEM_PROPERTY);
|
||||
|
@ -204,7 +205,7 @@ public class MockServletContext implements ServletContext {
|
|||
}
|
||||
|
||||
public void setContextPath(String contextPath) {
|
||||
this.contextPath = (contextPath != null ? contextPath : "");
|
||||
this.contextPath = contextPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
|
@ -28,7 +28,7 @@ import org.springframework.util.Assert;
|
|||
|
||||
/**
|
||||
* Implementation of the {@link javax.servlet.FilterConfig} interface which
|
||||
* simply passes the call through to a given Filter/FilterChain combo
|
||||
* simply passes the call through to a given Filter/FilterChain combination
|
||||
* (indicating the next Filter in the chain along with the FilterChain that it is
|
||||
* supposed to work on) or to a given Servlet (indicating the end of the chain).
|
||||
*
|
||||
|
@ -79,6 +79,7 @@ public class PassThroughFilterChain implements FilterChain {
|
|||
this.filter.doFilter(request, response, this.nextFilterChain);
|
||||
}
|
||||
else {
|
||||
Assert.state(this.servlet != null, "Neither a Filter not a Servlet set");
|
||||
this.servlet.service(request, response);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue