Browse Source

Polishing

pull/1610/head
Juergen Hoeller 8 years ago
parent
commit
640c8ff693
  1. 6
      spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java
  2. 12
      spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java
  3. 6
      spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java
  4. 11
      spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterBatchUpdateUtils.java
  5. 6
      spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplate.java
  6. 24
      spring-web/src/test/java/org/springframework/http/HttpRangeTests.java
  7. 42
      spring-web/src/test/java/org/springframework/web/client/HttpMessageConverterExtractorTests.java
  8. 18
      spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistry.java
  9. 5
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PathResourceResolver.java
  10. 10
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java
  11. 28
      spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandlerTests.java
  12. 6
      spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompEndpointRegistry.java
  13. 2
      spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketConfigurationSupport.java
  14. 8
      spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupport.java

6
spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java

@ -47,7 +47,7 @@ public class ByteArrayResource extends AbstractResource { @@ -47,7 +47,7 @@ public class ByteArrayResource extends AbstractResource {
/**
* Create a new ByteArrayResource.
* Create a new {@code ByteArrayResource}.
* @param byteArray the byte array to wrap
*/
public ByteArrayResource(byte[] byteArray) {
@ -55,7 +55,7 @@ public class ByteArrayResource extends AbstractResource { @@ -55,7 +55,7 @@ public class ByteArrayResource extends AbstractResource {
}
/**
* Create a new ByteArrayResource.
* Create a new {@code ByteArrayResource} with a description.
* @param byteArray the byte array to wrap
* @param description where the byte array comes from
*/
@ -65,6 +65,7 @@ public class ByteArrayResource extends AbstractResource { @@ -65,6 +65,7 @@ public class ByteArrayResource extends AbstractResource {
this.description = (description != null ? description : "");
}
/**
* Return the underlying byte array.
*/
@ -72,7 +73,6 @@ public class ByteArrayResource extends AbstractResource { @@ -72,7 +73,6 @@ public class ByteArrayResource extends AbstractResource {
return this.byteArray;
}
/**
* This implementation always returns {@code true}.
*/

12
spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 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.
@ -755,7 +755,7 @@ public interface JdbcOperations { @@ -755,7 +755,7 @@ public interface JdbcOperations {
* list of arguments to bind to the query, expecting a SqlRowSet.
* <p>The results will be mapped to an SqlRowSet which holds the data in a
* disconnected fashion. This wrapper will translate any SQLExceptions thrown.
* <p>Note that that, for the default implementation, JDBC RowSet support needs to
* <p>Note that, for the default implementation, JDBC RowSet support needs to
* be available at runtime: by default, Sun's {@code com.sun.rowset.CachedRowSetImpl}
* class is used, which is part of JDK 1.5+ and also available separately as part of
* Sun's JDBC RowSet Implementations download (rowset.jar).
@ -778,7 +778,7 @@ public interface JdbcOperations { @@ -778,7 +778,7 @@ public interface JdbcOperations {
* list of arguments to bind to the query, expecting a SqlRowSet.
* <p>The results will be mapped to an SqlRowSet which holds the data in a
* disconnected fashion. This wrapper will translate any SQLExceptions thrown.
* <p>Note that that, for the default implementation, JDBC RowSet support needs to
* <p>Note that, for the default implementation, JDBC RowSet support needs to
* be available at runtime: by default, Sun's {@code com.sun.rowset.CachedRowSetImpl}
* class is used, which is part of JDK 1.5+ and also available separately as part of
* Sun's JDBC RowSet Implementations download (rowset.jar).
@ -882,7 +882,7 @@ public interface JdbcOperations { @@ -882,7 +882,7 @@ public interface JdbcOperations {
* @param batchArgs the List of Object arrays containing the batch of arguments for the query
* @return an array containing the numbers of rows affected by each update in the batch
*/
public int[] batchUpdate(String sql, List<Object[]> batchArgs) throws DataAccessException;
int[] batchUpdate(String sql, List<Object[]> batchArgs) throws DataAccessException;
/**
* Execute a batch using the supplied SQL statement with the batch of supplied arguments.
@ -892,7 +892,7 @@ public interface JdbcOperations { @@ -892,7 +892,7 @@ public interface JdbcOperations {
* (constants from {@code java.sql.Types})
* @return an array containing the numbers of rows affected by each update in the batch
*/
public int[] batchUpdate(String sql, List<Object[]> batchArgs, int[] argTypes) throws DataAccessException;
int[] batchUpdate(String sql, List<Object[]> batchArgs, int[] argTypes) throws DataAccessException;
/**
* Execute multiple batches using the supplied SQL statement with the collect of supplied arguments.
@ -905,7 +905,7 @@ public interface JdbcOperations { @@ -905,7 +905,7 @@ public interface JdbcOperations {
* @return an array containing for each batch another array containing the numbers of rows affected
* by each update in the batch
*/
public <T> int[][] batchUpdate(String sql, Collection<T> batchArgs, int batchSize,
<T> int[][] batchUpdate(String sql, Collection<T> batchArgs, int batchSize,
ParameterizedPreparedStatementSetter<T> pss) throws DataAccessException;

6
spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java

@ -429,6 +429,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { @@ -429,6 +429,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
if (logger.isDebugEnabled()) {
logger.debug("Executing SQL statement [" + sql + "]");
}
class ExecuteStatementCallback implements StatementCallback<Object>, SqlProvider {
@Override
public Object doInStatement(Statement stmt) throws SQLException {
@ -440,6 +441,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { @@ -440,6 +441,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
return sql;
}
}
execute(new ExecuteStatementCallback());
}
@ -450,6 +452,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { @@ -450,6 +452,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
if (logger.isDebugEnabled()) {
logger.debug("Executing SQL query [" + sql + "]");
}
class QueryStatementCallback implements StatementCallback<T>, SqlProvider {
@Override
public T doInStatement(Statement stmt) throws SQLException {
@ -471,6 +474,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { @@ -471,6 +474,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
return sql;
}
}
return execute(new QueryStatementCallback());
}
@ -521,6 +525,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { @@ -521,6 +525,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
if (logger.isDebugEnabled()) {
logger.debug("Executing SQL update [" + sql + "]");
}
class UpdateStatementCallback implements StatementCallback<Integer>, SqlProvider {
@Override
public Integer doInStatement(Statement stmt) throws SQLException {
@ -535,6 +540,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { @@ -535,6 +540,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
return sql;
}
}
return execute(new UpdateStatementCallback());
}

11
spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterBatchUpdateUtils.java

@ -1,5 +1,5 @@ @@ -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.
@ -24,30 +24,31 @@ import org.springframework.jdbc.core.BatchUpdateUtils; @@ -24,30 +24,31 @@ import org.springframework.jdbc.core.BatchUpdateUtils;
import org.springframework.jdbc.core.JdbcOperations;
/**
* Generic utility methods for working with JDBC batch statements using named parameters. Mainly for internal use
* within the framework.
* Generic utility methods for working with JDBC batch statements using named parameters.
* Mainly for internal use within the framework.
*
* @author Thomas Risberg
* @since 3.0
*/
public class NamedParameterBatchUpdateUtils extends BatchUpdateUtils {
public static int[] executeBatchUpdateWithNamedParameters(final ParsedSql parsedSql,
final SqlParameterSource[] batchArgs, JdbcOperations jdbcOperations) {
if (batchArgs.length <= 0) {
return new int[] {0};
}
String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, batchArgs[0]);
return jdbcOperations.batchUpdate(
sqlToUse,
new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
Object[] values = NamedParameterUtils.buildValueArray(parsedSql, batchArgs[i], null);
int[] columnTypes = NamedParameterUtils.buildSqlTypeArray(parsedSql, batchArgs[i]);
setStatementParameters(values, ps, columnTypes);
}
@Override
public int getBatchSize() {
return batchArgs.length;

6
spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplate.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 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.
@ -331,8 +331,8 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations @@ -331,8 +331,8 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
@Override
public int[] batchUpdate(String sql, SqlParameterSource[] batchArgs) {
ParsedSql parsedSql = getParsedSql(sql);
return NamedParameterBatchUpdateUtils.executeBatchUpdateWithNamedParameters(parsedSql, batchArgs, getJdbcOperations());
return NamedParameterBatchUpdateUtils.executeBatchUpdateWithNamedParameters(
getParsedSql(sql), batchArgs, getJdbcOperations());
}
/**

24
spring-web/src/test/java/org/springframework/http/HttpRangeTests.java

@ -1,5 +1,5 @@ @@ -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.
@ -40,57 +40,57 @@ import static org.mockito.Mockito.mock; @@ -40,57 +40,57 @@ import static org.mockito.Mockito.mock;
public class HttpRangeTests {
@Test(expected = IllegalArgumentException.class)
public void invalidFirstPosition() throws Exception {
public void invalidFirstPosition() {
HttpRange.createByteRange(-1);
}
@Test(expected = IllegalArgumentException.class)
public void invalidLastLessThanFirst() throws Exception {
public void invalidLastLessThanFirst() {
HttpRange.createByteRange(10, 9);
}
@Test(expected = IllegalArgumentException.class)
public void invalidSuffixLength() throws Exception {
public void invalidSuffixLength() {
HttpRange.createSuffixRange(-1);
}
@Test
public void byteRange() throws Exception {
public void byteRange() {
HttpRange range = HttpRange.createByteRange(0, 499);
assertEquals(0, range.getRangeStart(1000));
assertEquals(499, range.getRangeEnd(1000));
}
@Test
public void byteRangeWithoutLastPosition() throws Exception {
public void byteRangeWithoutLastPosition() {
HttpRange range = HttpRange.createByteRange(9500);
assertEquals(9500, range.getRangeStart(10000));
assertEquals(9999, range.getRangeEnd(10000));
}
@Test
public void byteRangeOfZeroLength() throws Exception {
public void byteRangeOfZeroLength() {
HttpRange range = HttpRange.createByteRange(9500, 9500);
assertEquals(9500, range.getRangeStart(10000));
assertEquals(9500, range.getRangeEnd(10000));
}
@Test
public void suffixRange() throws Exception {
public void suffixRange() {
HttpRange range = HttpRange.createSuffixRange(500);
assertEquals(500, range.getRangeStart(1000));
assertEquals(999, range.getRangeEnd(1000));
}
@Test
public void suffixRangeShorterThanRepresentation() throws Exception {
public void suffixRangeShorterThanRepresentation() {
HttpRange range = HttpRange.createSuffixRange(500);
assertEquals(0, range.getRangeStart(350));
assertEquals(349, range.getRangeEnd(350));
}
@Test
public void parseRanges() throws Exception {
public void parseRanges() {
List<HttpRange> ranges = HttpRange.parseRanges("bytes=0-0,500-,-1");
assertEquals(3, ranges.size());
assertEquals(0, ranges.get(0).getRangeStart(1000));
@ -138,8 +138,8 @@ public class HttpRangeTests { @@ -138,8 +138,8 @@ public class HttpRangeTests {
@Test(expected = IllegalArgumentException.class)
@SuppressWarnings("unchecked")
public void toResourceRegionExceptionLength() {
ByteArrayResource resource = mock(ByteArrayResource.class);
public void toResourceRegionExceptionLength() throws IOException {
InputStreamResource resource = mock(InputStreamResource.class);
given(resource.contentLength()).willThrow(IOException.class);
HttpRange range = HttpRange.createByteRange(0, 9);
range.toResourceRegion(resource);

42
spring-web/src/test/java/org/springframework/web/client/HttpMessageConverterExtractorTests.java

@ -1,11 +1,11 @@ @@ -1,11 +1,11 @@
/*
* Copyright 2002-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@ -22,7 +22,6 @@ import java.lang.reflect.Type; @@ -22,7 +22,6 @@ import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.ParameterizedTypeReference;
@ -46,43 +45,36 @@ public class HttpMessageConverterExtractorTests { @@ -46,43 +45,36 @@ public class HttpMessageConverterExtractorTests {
private HttpMessageConverterExtractor<?> extractor;
private ClientHttpResponse response;
private final ClientHttpResponse response = mock(ClientHttpResponse.class);
@Before
public void createMocks() {
response = mock(ClientHttpResponse.class);
}
@Test
public void noContent() throws IOException {
HttpMessageConverter<?> converter = mock(HttpMessageConverter.class);
extractor = new HttpMessageConverterExtractor<String>(String.class, createConverterList(converter));
extractor = new HttpMessageConverterExtractor<>(String.class, createConverterList(converter));
given(response.getStatusCode()).willReturn(HttpStatus.NO_CONTENT);
Object result = extractor.extractData(response);
assertNull(result);
}
@Test
public void notModified() throws IOException {
HttpMessageConverter<?> converter = mock(HttpMessageConverter.class);
extractor = new HttpMessageConverterExtractor<String>(String.class, createConverterList(converter));
extractor = new HttpMessageConverterExtractor<>(String.class, createConverterList(converter));
given(response.getStatusCode()).willReturn(HttpStatus.NOT_MODIFIED);
Object result = extractor.extractData(response);
assertNull(result);
}
@Test
public void informational() throws IOException {
HttpMessageConverter<?> converter = mock(HttpMessageConverter.class);
extractor = new HttpMessageConverterExtractor<String>(String.class, createConverterList(converter));
extractor = new HttpMessageConverterExtractor<>(String.class, createConverterList(converter));
given(response.getStatusCode()).willReturn(HttpStatus.CONTINUE);
Object result = extractor.extractData(response);
assertNull(result);
}
@ -91,12 +83,11 @@ public class HttpMessageConverterExtractorTests { @@ -91,12 +83,11 @@ public class HttpMessageConverterExtractorTests {
HttpMessageConverter<?> converter = mock(HttpMessageConverter.class);
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentLength(0);
extractor = new HttpMessageConverterExtractor<String>(String.class, createConverterList(converter));
extractor = new HttpMessageConverterExtractor<>(String.class, createConverterList(converter));
given(response.getStatusCode()).willReturn(HttpStatus.OK);
given(response.getHeaders()).willReturn(responseHeaders);
Object result = extractor.extractData(response);
assertNull(result);
}
@ -104,10 +95,10 @@ public class HttpMessageConverterExtractorTests { @@ -104,10 +95,10 @@ public class HttpMessageConverterExtractorTests {
@SuppressWarnings("unchecked")
public void emptyMessageBody() throws IOException {
HttpMessageConverter<String> converter = mock(HttpMessageConverter.class);
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(converter);
HttpHeaders responseHeaders = new HttpHeaders();
extractor = new HttpMessageConverterExtractor<String>(String.class, createConverterList(converter));
extractor = new HttpMessageConverterExtractor<>(String.class, createConverterList(converter));
given(response.getStatusCode()).willReturn(HttpStatus.OK);
given(response.getHeaders()).willReturn(responseHeaders);
given(response.getBody()).willReturn(new ByteArrayInputStream("".getBytes()));
@ -120,13 +111,13 @@ public class HttpMessageConverterExtractorTests { @@ -120,13 +111,13 @@ public class HttpMessageConverterExtractorTests {
@SuppressWarnings("unchecked")
public void normal() throws IOException {
HttpMessageConverter<String> converter = mock(HttpMessageConverter.class);
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(converter);
HttpHeaders responseHeaders = new HttpHeaders();
MediaType contentType = MediaType.TEXT_PLAIN;
responseHeaders.setContentType(contentType);
String expected = "Foo";
extractor = new HttpMessageConverterExtractor<String>(String.class, converters);
extractor = new HttpMessageConverterExtractor<>(String.class, converters);
given(response.getStatusCode()).willReturn(HttpStatus.OK);
given(response.getHeaders()).willReturn(responseHeaders);
given(response.getBody()).willReturn(new ByteArrayInputStream(expected.getBytes()));
@ -134,7 +125,6 @@ public class HttpMessageConverterExtractorTests { @@ -134,7 +125,6 @@ public class HttpMessageConverterExtractorTests {
given(converter.read(eq(String.class), any(HttpInputMessage.class))).willReturn(expected);
Object result = extractor.extractData(response);
assertEquals(expected, result);
}
@ -142,12 +132,12 @@ public class HttpMessageConverterExtractorTests { @@ -142,12 +132,12 @@ public class HttpMessageConverterExtractorTests {
@SuppressWarnings("unchecked")
public void cannotRead() throws IOException {
HttpMessageConverter<String> converter = mock(HttpMessageConverter.class);
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(converter);
HttpHeaders responseHeaders = new HttpHeaders();
MediaType contentType = MediaType.TEXT_PLAIN;
responseHeaders.setContentType(contentType);
extractor = new HttpMessageConverterExtractor<String>(String.class, converters);
extractor = new HttpMessageConverterExtractor<>(String.class, converters);
given(response.getStatusCode()).willReturn(HttpStatus.OK);
given(response.getHeaders()).willReturn(responseHeaders);
given(response.getBody()).willReturn(new ByteArrayInputStream("Foobar".getBytes()));
@ -175,13 +165,11 @@ public class HttpMessageConverterExtractorTests { @@ -175,13 +165,11 @@ public class HttpMessageConverterExtractorTests {
given(converter.read(eq(type), eq(null), any(HttpInputMessage.class))).willReturn(expected);
Object result = extractor.extractData(response);
assertEquals(expected, result);
}
private List<HttpMessageConverter<?>> createConverterList(
HttpMessageConverter<?> converter) {
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>(1);
private List<HttpMessageConverter<?>> createConverterList(HttpMessageConverter<?> converter) {
List<HttpMessageConverter<?>> converters = new ArrayList<>(1);
converters.add(converter);
return converters;
}

18
spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistry.java

@ -1,5 +1,5 @@ @@ -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.
@ -90,8 +90,7 @@ public class ResourceHandlerRegistry { @@ -90,8 +90,7 @@ public class ResourceHandlerRegistry {
/**
* A variant of
* {@link #ResourceHandlerRegistry(ApplicationContext, ServletContext, ContentNegotiationManager)}
* that also accepts the {@link UrlPathHelper} used for mapping requests
* to static resources.
* that also accepts the {@link UrlPathHelper} used for mapping requests to static resources.
* @since 4.3.13
*/
public ResourceHandlerRegistry(ApplicationContext applicationContext, ServletContext servletContext,
@ -106,13 +105,12 @@ public class ResourceHandlerRegistry { @@ -106,13 +105,12 @@ public class ResourceHandlerRegistry {
/**
* Add a resource handler for serving static resources based on the specified URL path
* patterns. The handler will be invoked for every incoming request that matches to
* one of the specified path patterns.
* <p>Patterns like {@code "/static/**"} or {@code "/css/{filename:\\w+\\.css}"}
* are allowed. See {@link org.springframework.util.AntPathMatcher} for more details on the
* syntax.
* @return A {@link ResourceHandlerRegistration} to use to further configure the
* Add a resource handler for serving static resources based on the specified URL path patterns.
* The handler will be invoked for every incoming request that matches to one of the specified
* path patterns.
* <p>Patterns like {@code "/static/**"} or {@code "/css/{filename:\\w+\\.css}"} are allowed.
* See {@link org.springframework.util.AntPathMatcher} for more details on the syntax.
* @return a {@link ResourceHandlerRegistration} to use to further configure the
* registered resource handler
*/
public ResourceHandlerRegistration addResourceHandler(String... pathPatterns) {

5
spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PathResourceResolver.java

@ -92,7 +92,6 @@ public class PathResourceResolver extends AbstractResourceResolver { @@ -92,7 +92,6 @@ public class PathResourceResolver extends AbstractResourceResolver {
* <p><strong>Note:</strong> the charset is used only if the
* {@link #setUrlPathHelper urlPathHelper} property is also configured and
* its {@code urlDecode} property is set to true.
* @param locationCharsets charsets by location
* @since 4.3.13
*/
public void setLocationCharsets(Map<Resource, Charset> locationCharsets) {
@ -105,14 +104,13 @@ public class PathResourceResolver extends AbstractResourceResolver { @@ -105,14 +104,13 @@ public class PathResourceResolver extends AbstractResourceResolver {
* @since 4.3.13
*/
public Map<Resource, Charset> getLocationCharsets() {
return Collections.unmodifiableMap(locationCharsets);
return Collections.unmodifiableMap(this.locationCharsets);
}
/**
* Provide a reference to the {@link UrlPathHelper} used to map requests to
* static resources. This helps to derive information about the lookup path
* such as whether it is decoded or not.
* @param urlPathHelper a reference to the path helper
* @since 4.3.13
*/
public void setUrlPathHelper(UrlPathHelper urlPathHelper) {
@ -127,6 +125,7 @@ public class PathResourceResolver extends AbstractResourceResolver { @@ -127,6 +125,7 @@ public class PathResourceResolver extends AbstractResourceResolver {
return this.urlPathHelper;
}
@Override
protected Resource resolveResourceInternal(HttpServletRequest request, String requestPath,
List<? extends Resource> locations, ResourceResolverChain chain) {

10
spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java

@ -1,5 +1,5 @@ @@ -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.
@ -152,10 +152,9 @@ public class ResourceHttpRequestHandler extends WebContentGenerator @@ -152,10 +152,9 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
* {@link org.springframework.core.io.UrlResource URL resources} such as a
* file or an HTTP URL location and is used in {@link PathResourceResolver}
* to correctly encode paths relative to the location.
* <p><strong>Note:</strong> the charset is used only if the
* <p><strong>Note:</strong> The charset is used only if the
* {@link #setUrlPathHelper urlPathHelper} property is also configured and
* its {@code urlDecode} property is set to true.
* @param locationCharsets charsets by location
* its {@code urlDecode} property is set to {@code true}.
* @since 4.3.13
*/
public void setLocationCharsets(Map<Resource,Charset> locationCharsets) {
@ -168,7 +167,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator @@ -168,7 +167,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
* @since 4.3.13
*/
public Map<Resource, Charset> getLocationCharsets() {
return Collections.unmodifiableMap(locationCharsets);
return Collections.unmodifiableMap(this.locationCharsets);
}
/**
@ -281,7 +280,6 @@ public class ResourceHttpRequestHandler extends WebContentGenerator @@ -281,7 +280,6 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
* Provide a reference to the {@link UrlPathHelper} used to map requests to
* static resources. This helps to derive information about the lookup path
* such as whether it is decoded or not.
* @param urlPathHelper a reference to the path helper
* @since 4.3.13
*/
public void setUrlPathHelper(UrlPathHelper urlPathHelper) {

28
spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandlerTests.java

@ -1,5 +1,5 @@ @@ -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.
@ -48,7 +48,7 @@ import org.springframework.web.servlet.HandlerMapping; @@ -48,7 +48,7 @@ import org.springframework.web.servlet.HandlerMapping;
import static org.junit.Assert.*;
/**
* Unit tests for ResourceHttpRequestHandler.
* Unit tests for {@link ResourceHttpRequestHandler}.
*
* @author Keith Donald
* @author Jeremy Grelle
@ -67,7 +67,7 @@ public class ResourceHttpRequestHandlerTests { @@ -67,7 +67,7 @@ public class ResourceHttpRequestHandlerTests {
@Before
public void setUp() throws Exception {
public void setup() throws Exception {
dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
@ -86,6 +86,7 @@ public class ResourceHttpRequestHandlerTests { @@ -86,6 +86,7 @@ public class ResourceHttpRequestHandlerTests {
this.response = new MockHttpServletResponse();
}
@Test
public void getResource() throws Exception {
this.request.setAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, "foo.css");
@ -240,7 +241,7 @@ public class ResourceHttpRequestHandlerTests { @@ -240,7 +241,7 @@ public class ResourceHttpRequestHandlerTests {
assertEquals("function foo() { console.log(\"hello world\"); }", this.response.getContentAsString());
}
@Test // SPR-13658
@Test // SPR-13658
public void getResourceWithRegisteredMediaType() throws Exception {
ContentNegotiationManagerFactoryBean factory = new ContentNegotiationManagerFactoryBean();
factory.addMediaType("css", new MediaType("foo", "bar"));
@ -261,7 +262,7 @@ public class ResourceHttpRequestHandlerTests { @@ -261,7 +262,7 @@ public class ResourceHttpRequestHandlerTests {
assertEquals("h1 { color:red; }", this.response.getContentAsString());
}
@Test // SPR-14577
@Test // SPR-14577
public void getMediaTypeWithFavorPathExtensionOff() throws Exception {
ContentNegotiationManagerFactoryBean factory = new ContentNegotiationManagerFactoryBean();
factory.setFavorPathExtension(false);
@ -282,18 +283,16 @@ public class ResourceHttpRequestHandlerTests { @@ -282,18 +283,16 @@ public class ResourceHttpRequestHandlerTests {
assertEquals("text/html", this.response.getContentType());
}
@Test // SPR-14368
@Test // SPR-14368
public void getResourceWithMediaTypeResolvedThroughServletContext() throws Exception {
MockServletContext servletContext = new MockServletContext() {
@Override
public String getMimeType(String filePath) {
return "foo/bar";
}
@Override
public String getVirtualServerName() {
return null;
return "";
}
};
@ -606,8 +605,7 @@ public class ResourceHttpRequestHandlerTests { @@ -606,8 +605,7 @@ public class ResourceHttpRequestHandlerTests {
assertEquals("t.", ranges[11]);
}
// SPR-14005
@Test
@Test // SPR-14005
public void doOverwriteExistingCacheControlHeaders() throws Exception {
this.request.setAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, "foo.css");
this.response.setHeader("Cache-Control", "no-store");
@ -618,10 +616,6 @@ public class ResourceHttpRequestHandlerTests { @@ -618,10 +616,6 @@ public class ResourceHttpRequestHandlerTests {
}
private long dateHeaderAsLong(String responseHeaderName) throws Exception {
return dateFormat.parse(this.response.getHeader(responseHeaderName)).getTime();
}
private long resourceLastModified(String resourceName) throws IOException {
return new ClassPathResource(resourceName, getClass()).getFile().lastModified();
}
@ -631,6 +625,10 @@ public class ResourceHttpRequestHandlerTests { @@ -631,6 +625,10 @@ public class ResourceHttpRequestHandlerTests {
return dateFormat.format(lastModified);
}
private long dateHeaderAsLong(String responseHeaderName) throws Exception {
return dateFormat.parse(this.response.getHeader(responseHeaderName)).getTime();
}
private static class TestServletContext extends MockServletContext {

6
spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompEndpointRegistry.java

@ -1,5 +1,5 @@ @@ -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.
@ -146,10 +146,8 @@ public class WebMvcStompEndpointRegistry implements StompEndpointRegistry { @@ -146,10 +146,8 @@ public class WebMvcStompEndpointRegistry implements StompEndpointRegistry {
this.stompHandler.setApplicationEventPublisher(applicationContext);
}
/**
* Return a handler mapping with the mapped ViewControllers; or {@code null}
* in case of no registrations.
* Return a handler mapping with the mapped ViewControllers.
*/
public AbstractHandlerMapping getHandlerMapping() {
Map<String, Object> urlMap = new LinkedHashMap<String, Object>();

2
spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketConfigurationSupport.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 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.

8
spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupport.java

@ -54,8 +54,8 @@ public abstract class WebSocketMessageBrokerConfigurationSupport extends Abstrac @@ -54,8 +54,8 @@ public abstract class WebSocketMessageBrokerConfigurationSupport extends Abstrac
@Override
protected SimpAnnotationMethodMessageHandler createAnnotationMethodMessageHandler() {
return new WebSocketAnnotationMethodMessageHandler(clientInboundChannel(),
clientOutboundChannel(), brokerMessagingTemplate());
return new WebSocketAnnotationMethodMessageHandler(
clientInboundChannel(), clientOutboundChannel(), brokerMessagingTemplate());
}
@Override
@ -72,8 +72,8 @@ public abstract class WebSocketMessageBrokerConfigurationSupport extends Abstrac @@ -72,8 +72,8 @@ public abstract class WebSocketMessageBrokerConfigurationSupport extends Abstrac
@SuppressWarnings("deprecation")
public HandlerMapping stompWebSocketHandlerMapping() {
WebSocketHandler handler = decorateWebSocketHandler(subProtocolWebSocketHandler());
WebMvcStompEndpointRegistry registry = new WebMvcStompEndpointRegistry(handler,
getTransportRegistration(), userSessionRegistry(), messageBrokerTaskScheduler());
WebMvcStompEndpointRegistry registry = new WebMvcStompEndpointRegistry(
handler, getTransportRegistration(), userSessionRegistry(), messageBrokerTaskScheduler());
registry.setApplicationContext(getApplicationContext());
registerStompEndpoints(registry);
return registry.getHandlerMapping();

Loading…
Cancel
Save