Skip to content

Commit 4fa4886

Browse files
committed
Consistent trace log messages and general polishing
(cherry picked from commit 5626384)
1 parent 46016d0 commit 4fa4886

19 files changed

+77
-82
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,25 +41,26 @@ public Resource resolveResource(HttpServletRequest request, String requestPath,
4141
List<? extends Resource> locations, ResourceResolverChain chain) {
4242

4343
if (logger.isTraceEnabled()) {
44-
logger.trace("Resolving resource: requestPath=\"" + requestPath + "\"");
44+
logger.trace("Resolving resource for request path \"" + requestPath + "\"");
4545
}
4646
return resolveResourceInternal(request, requestPath, locations, chain);
4747
}
4848

49-
protected abstract Resource resolveResourceInternal(HttpServletRequest request, String requestPath,
50-
List<? extends Resource> locations, ResourceResolverChain chain);
51-
5249
@Override
5350
public String resolveUrlPath(String resourceUrlPath, List<? extends Resource> locations,
5451
ResourceResolverChain chain) {
5552

5653
if (logger.isTraceEnabled()) {
57-
logger.trace("Resolving public URL for path=\"" + resourceUrlPath + "\"");
54+
logger.trace("Resolving public URL for resource path \"" + resourceUrlPath + "\"");
5855
}
5956

6057
return resolveUrlPathInternal(resourceUrlPath, locations, chain);
6158
}
6259

60+
61+
protected abstract Resource resolveResourceInternal(HttpServletRequest request, String requestPath,
62+
List<? extends Resource> locations, ResourceResolverChain chain);
63+
6364
protected abstract String resolveUrlPathInternal(String resourceUrlPath,
6465
List<? extends Resource> locations, ResourceResolverChain chain);
6566

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@
2020
import java.io.IOException;
2121
import java.io.StringWriter;
2222
import java.nio.charset.Charset;
23-
import java.util.Arrays;
23+
import java.util.Collections;
2424
import java.util.HashMap;
2525
import java.util.Map;
2626
import java.util.Scanner;
@@ -97,9 +97,7 @@ public Resource transform(HttpServletRequest request, Resource resource, Resourc
9797
throws IOException {
9898

9999
resource = transformerChain.transform(request, resource);
100-
101-
String filename = resource.getFilename();
102-
if (!this.fileExtension.equals(StringUtils.getFilenameExtension(filename))) {
100+
if (!this.fileExtension.equals(StringUtils.getFilenameExtension(resource.getFilename()))) {
103101
return resource;
104102
}
105103

@@ -138,7 +136,7 @@ public Resource transform(HttpServletRequest request, Resource resource, Resourc
138136
String hash = hashBuilder.build();
139137
contentWriter.write("\n" + "# Hash: " + hash);
140138
if (logger.isTraceEnabled()) {
141-
logger.trace("AppCache file: [" + resource.getFilename()+ "] Hash: [" + hash + "]");
139+
logger.trace("AppCache file: [" + resource.getFilename()+ "] hash: [" + hash + "]");
142140
}
143141

144142
return new TransformedResource(resource, contentWriter.toString().getBytes(DEFAULT_CHARSET));
@@ -170,15 +168,16 @@ public String transform(String line, HashBuilder builder, Resource resource,
170168

171169
private class CacheSection implements SectionTransformer {
172170

173-
private final String COMMENT_DIRECTIVE = "#";
171+
private static final String COMMENT_DIRECTIVE = "#";
174172

175173
@Override
176174
public String transform(String line, HashBuilder builder, Resource resource,
177175
ResourceTransformerChain transformerChain, HttpServletRequest request) throws IOException {
178176

179177
if (isLink(line) && !hasScheme(line)) {
180178
ResourceResolverChain resolverChain = transformerChain.getResolverChain();
181-
Resource appCacheResource = resolverChain.resolveResource(null, line, Arrays.asList(resource));
179+
Resource appCacheResource =
180+
resolverChain.resolveResource(null, line, Collections.singletonList(resource));
182181
String path = resolveUrlPath(line, request, resource, transformerChain);
183182
builder.appendResource(appCacheResource);
184183
if (logger.isTraceEnabled()) {

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,25 @@ public class CachingResourceResolver extends AbstractResourceResolver {
4242

4343
private final Cache cache;
4444

45+
4546
public CachingResourceResolver(CacheManager cacheManager, String cacheName) {
4647
this(cacheManager.getCache(cacheName));
4748
}
4849

4950
public CachingResourceResolver(Cache cache) {
50-
Assert.notNull(cache, "'cache' is required");
51+
Assert.notNull(cache, "Cache is required");
5152
this.cache = cache;
5253
}
5354

55+
5456
/**
5557
* Return the configured {@code Cache}.
5658
*/
5759
public Cache getCache() {
5860
return this.cache;
5961
}
6062

63+
6164
@Override
6265
protected Resource resolveResourceInternal(HttpServletRequest request, String requestPath,
6366
List<? extends Resource> locations, ResourceResolverChain chain) {
@@ -67,15 +70,15 @@ protected Resource resolveResourceInternal(HttpServletRequest request, String re
6770

6871
if (resource != null) {
6972
if (logger.isTraceEnabled()) {
70-
logger.trace("Found match");
73+
logger.trace("Found match: " + resource);
7174
}
7275
return resource;
7376
}
7477

7578
resource = chain.resolveResource(request, requestPath, locations);
7679
if (resource != null) {
7780
if (logger.isTraceEnabled()) {
78-
logger.trace("Putting resolved resource in cache");
81+
logger.trace("Putting resolved resource in cache: " + resource);
7982
}
8083
this.cache.put(key, resource);
8184
}
@@ -104,15 +107,15 @@ protected String resolveUrlPathInternal(String resourceUrlPath,
104107

105108
if (resolvedUrlPath != null) {
106109
if (logger.isTraceEnabled()) {
107-
logger.trace("Found match");
110+
logger.trace("Found match: \"" + resolvedUrlPath + "\"");
108111
}
109112
return resolvedUrlPath;
110113
}
111114

112115
resolvedUrlPath = chain.resolveUrlPath(resourceUrlPath, locations);
113116
if (resolvedUrlPath != null) {
114117
if (logger.isTraceEnabled()) {
115-
logger.trace("Putting resolved resource URL path in cache");
118+
logger.trace("Putting resolved resource URL path in cache: \"" + resolvedUrlPath + "\"");
116119
}
117120
this.cache.put(key, resolvedUrlPath);
118121
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ public class CachingResourceTransformer implements ResourceTransformer {
4242

4343
private final Cache cache;
4444

45+
4546
public CachingResourceTransformer(CacheManager cacheManager, String cacheName) {
4647
this(cacheManager.getCache(cacheName));
4748
}
4849

4950
public CachingResourceTransformer(Cache cache) {
50-
Assert.notNull(cache, "'cache' is required");
51+
Assert.notNull(cache, "Cache is required");
5152
this.cache = cache;
5253
}
5354

@@ -59,22 +60,23 @@ public Cache getCache() {
5960
return this.cache;
6061
}
6162

63+
6264
@Override
6365
public Resource transform(HttpServletRequest request, Resource resource, ResourceTransformerChain transformerChain)
6466
throws IOException {
6567

6668
Resource transformed = this.cache.get(resource, Resource.class);
6769
if (transformed != null) {
6870
if (logger.isTraceEnabled()) {
69-
logger.trace("Found match");
71+
logger.trace("Found match: " + transformed);
7072
}
7173
return transformed;
7274
}
7375

7476
transformed = transformerChain.transform(request, resource);
7577

7678
if (logger.isTraceEnabled()) {
77-
logger.trace("Putting transformed resource in cache");
79+
logger.trace("Putting transformed resource in cache: " + transformed);
7880
}
7981
this.cache.put(resource, transformed);
8082

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.web.servlet.resource;
1718

1819
import java.io.IOException;
@@ -33,20 +34,18 @@
3334
*/
3435
public class ContentVersionStrategy extends AbstractVersionStrategy {
3536

36-
3737
public ContentVersionStrategy() {
3838
super(new FileNameVersionPathStrategy());
3939
}
4040

41-
4241
@Override
4342
public String getResourceVersion(Resource resource) {
4443
try {
4544
byte[] content = FileCopyUtils.copyToByteArray(resource.getInputStream());
4645
return DigestUtils.md5DigestAsHex(content);
4746
}
4847
catch (IOException ex) {
49-
throw new IllegalStateException("Failed to calculate hash for resource [" + resource + "]", ex);
48+
throw new IllegalStateException("Failed to calculate hash for " + resource, ex);
5049
}
5150
}
5251

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@
2323
import org.springframework.core.io.Resource;
2424
import org.springframework.util.Assert;
2525

26-
2726
/**
2827
* A default implementation of {@link ResourceResolverChain} for invoking a list
2928
* of {@link ResourceResolver}s.
@@ -53,6 +52,7 @@ public Resource resolveResource(HttpServletRequest request, String requestPath,
5352
if (resolver == null) {
5453
return null;
5554
}
55+
5656
try {
5757
return resolver.resolveResource(request, requestPath, locations, this);
5858
}
@@ -67,6 +67,7 @@ public String resolveUrlPath(String resourcePath, List<? extends Resource> locat
6767
if (resolver == null) {
6868
return null;
6969
}
70+
7071
try {
7172
return resolver.resolveUrlPath(resourcePath, locations, this);
7273
}
@@ -76,7 +77,6 @@ public String resolveUrlPath(String resourcePath, List<? extends Resource> locat
7677
}
7778

7879
private ResourceResolver getNext() {
79-
8080
Assert.state(this.index <= this.resolvers.size(),
8181
"Current index exceeds the number of configured ResourceResolver's");
8282

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,8 +25,8 @@
2525
import org.springframework.util.Assert;
2626

2727
/**
28-
* A default implementation of {@link ResourceTransformerChain} for invoking a list
29-
* of {@link ResourceTransformer}s.
28+
* A default implementation of {@link ResourceTransformerChain} for invoking
29+
* a list of {@link ResourceTransformer}s.
3030
*
3131
* @author Rossen Stoyanchev
3232
* @since 4.1
@@ -39,10 +39,11 @@ class DefaultResourceTransformerChain implements ResourceTransformerChain {
3939

4040
private int index = -1;
4141

42+
4243
public DefaultResourceTransformerChain(ResourceResolverChain resolverChain,
4344
List<ResourceTransformer> transformers) {
4445

45-
Assert.notNull(resolverChain, "'resolverChain' is required");
46+
Assert.notNull(resolverChain, "ResourceResolverChain is required");
4647
this.resolverChain = resolverChain;
4748
if (transformers != null) {
4849
this.transformers.addAll(transformers);
@@ -54,12 +55,14 @@ public ResourceResolverChain getResolverChain() {
5455
return this.resolverChain;
5556
}
5657

58+
5759
@Override
5860
public Resource transform(HttpServletRequest request, Resource resource) throws IOException {
5961
ResourceTransformer transformer = getNext();
6062
if (transformer == null) {
6163
return resource;
6264
}
65+
6366
try {
6467
return transformer.transform(request, resource, this);
6568
}
@@ -69,7 +72,6 @@ public Resource transform(HttpServletRequest request, Resource resource) throws
6972
}
7073

7174
private ResourceTransformer getNext() {
72-
7375
Assert.state(this.index <= this.transformers.size(),
7476
"Current index exceeds the number of configured ResourceTransformer's");
7577

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -117,7 +117,7 @@ public void handleRequest(HttpServletRequest request, HttpServletResponse respon
117117
RequestDispatcher rd = this.servletContext.getNamedDispatcher(this.defaultServletName);
118118
if (rd == null) {
119119
throw new IllegalStateException("A RequestDispatcher could not be located for the default servlet '" +
120-
this.defaultServletName +"'");
120+
this.defaultServletName + "'");
121121
}
122122
rd.forward(request, response);
123123
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@
1818

1919
import org.springframework.core.io.Resource;
2020

21-
2221
/**
2322
* Interface for a resource descriptor that describes the encoding
2423
* applied to the entire resource content.
@@ -39,6 +38,6 @@ public interface EncodedResource extends Resource {
3938
* @see <a href="http://tools.ietf.org/html/rfc7231#section-3.1.2.1">HTTP/1.1: Semantics
4039
* and Content, section 3.1.2.1</a>
4140
*/
42-
public String getContentEncoding();
41+
String getContentEncoding();
4342

4443
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.web.servlet.resource;
1718

1819
import org.springframework.core.io.Resource;
@@ -34,6 +35,7 @@ public class FixedVersionStrategy extends AbstractVersionStrategy {
3435

3536
private final String version;
3637

38+
3739
/**
3840
* Create a new FixedVersionStrategy with the given version string.
3941
* @param version the fixed version string to use

0 commit comments

Comments
 (0)