Browse Source

Consistent trace log messages and general polishing

(cherry picked from commit 5626384)
pull/941/head
Juergen Hoeller 10 years ago
parent
commit
4fa4886e70
  1. 13
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/AbstractResourceResolver.java
  2. 15
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/AppCacheManifestTransformer.java
  3. 13
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/CachingResourceResolver.java
  4. 8
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/CachingResourceTransformer.java
  5. 7
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ContentVersionStrategy.java
  6. 6
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/DefaultResourceResolverChain.java
  7. 12
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/DefaultResourceTransformerChain.java
  8. 4
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/DefaultServletHttpRequestHandler.java
  9. 5
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/EncodedResource.java
  10. 4
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/FixedVersionStrategy.java
  11. 10
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/GzipResourceResolver.java
  12. 9
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceResolver.java
  13. 5
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceResolverChain.java
  14. 6
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceTransformer.java
  15. 6
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceTransformerChain.java
  16. 10
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceTransformerSupport.java
  17. 12
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/TransformedResource.java
  18. 3
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionPathStrategy.java
  19. 11
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionStrategy.java

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -41,25 +41,26 @@ public abstract class AbstractResourceResolver implements ResourceResolver {
List<? extends Resource> locations, ResourceResolverChain chain) { List<? extends Resource> locations, ResourceResolverChain chain) {
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
logger.trace("Resolving resource: requestPath=\"" + requestPath + "\""); logger.trace("Resolving resource for request path \"" + requestPath + "\"");
} }
return resolveResourceInternal(request, requestPath, locations, chain); return resolveResourceInternal(request, requestPath, locations, chain);
} }
protected abstract Resource resolveResourceInternal(HttpServletRequest request, String requestPath,
List<? extends Resource> locations, ResourceResolverChain chain);
@Override @Override
public String resolveUrlPath(String resourceUrlPath, List<? extends Resource> locations, public String resolveUrlPath(String resourceUrlPath, List<? extends Resource> locations,
ResourceResolverChain chain) { ResourceResolverChain chain) {
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
logger.trace("Resolving public URL for path=\"" + resourceUrlPath + "\""); logger.trace("Resolving public URL for resource path \"" + resourceUrlPath + "\"");
} }
return resolveUrlPathInternal(resourceUrlPath, locations, chain); return resolveUrlPathInternal(resourceUrlPath, locations, chain);
} }
protected abstract Resource resolveResourceInternal(HttpServletRequest request, String requestPath,
List<? extends Resource> locations, ResourceResolverChain chain);
protected abstract String resolveUrlPathInternal(String resourceUrlPath, protected abstract String resolveUrlPathInternal(String resourceUrlPath,
List<? extends Resource> locations, ResourceResolverChain chain); List<? extends Resource> locations, ResourceResolverChain chain);

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,7 +20,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.Arrays; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Scanner; import java.util.Scanner;
@ -97,9 +97,7 @@ public class AppCacheManifestTransformer extends ResourceTransformerSupport {
throws IOException { throws IOException {
resource = transformerChain.transform(request, resource); resource = transformerChain.transform(request, resource);
if (!this.fileExtension.equals(StringUtils.getFilenameExtension(resource.getFilename()))) {
String filename = resource.getFilename();
if (!this.fileExtension.equals(StringUtils.getFilenameExtension(filename))) {
return resource; return resource;
} }
@ -138,7 +136,7 @@ public class AppCacheManifestTransformer extends ResourceTransformerSupport {
String hash = hashBuilder.build(); String hash = hashBuilder.build();
contentWriter.write("\n" + "# Hash: " + hash); contentWriter.write("\n" + "# Hash: " + hash);
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
logger.trace("AppCache file: [" + resource.getFilename()+ "] Hash: [" + hash + "]"); logger.trace("AppCache file: [" + resource.getFilename()+ "] hash: [" + hash + "]");
} }
return new TransformedResource(resource, contentWriter.toString().getBytes(DEFAULT_CHARSET)); return new TransformedResource(resource, contentWriter.toString().getBytes(DEFAULT_CHARSET));
@ -170,7 +168,7 @@ public class AppCacheManifestTransformer extends ResourceTransformerSupport {
private class CacheSection implements SectionTransformer { private class CacheSection implements SectionTransformer {
private final String COMMENT_DIRECTIVE = "#"; private static final String COMMENT_DIRECTIVE = "#";
@Override @Override
public String transform(String line, HashBuilder builder, Resource resource, public String transform(String line, HashBuilder builder, Resource resource,
@ -178,7 +176,8 @@ public class AppCacheManifestTransformer extends ResourceTransformerSupport {
if (isLink(line) && !hasScheme(line)) { if (isLink(line) && !hasScheme(line)) {
ResourceResolverChain resolverChain = transformerChain.getResolverChain(); ResourceResolverChain resolverChain = transformerChain.getResolverChain();
Resource appCacheResource = resolverChain.resolveResource(null, line, Arrays.asList(resource)); Resource appCacheResource =
resolverChain.resolveResource(null, line, Collections.singletonList(resource));
String path = resolveUrlPath(line, request, resource, transformerChain); String path = resolveUrlPath(line, request, resource, transformerChain);
builder.appendResource(appCacheResource); builder.appendResource(appCacheResource);
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {

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

@ -42,15 +42,17 @@ public class CachingResourceResolver extends AbstractResourceResolver {
private final Cache cache; private final Cache cache;
public CachingResourceResolver(CacheManager cacheManager, String cacheName) { public CachingResourceResolver(CacheManager cacheManager, String cacheName) {
this(cacheManager.getCache(cacheName)); this(cacheManager.getCache(cacheName));
} }
public CachingResourceResolver(Cache cache) { public CachingResourceResolver(Cache cache) {
Assert.notNull(cache, "'cache' is required"); Assert.notNull(cache, "Cache is required");
this.cache = cache; this.cache = cache;
} }
/** /**
* Return the configured {@code Cache}. * Return the configured {@code Cache}.
*/ */
@ -58,6 +60,7 @@ public class CachingResourceResolver extends AbstractResourceResolver {
return this.cache; return this.cache;
} }
@Override @Override
protected Resource resolveResourceInternal(HttpServletRequest request, String requestPath, protected Resource resolveResourceInternal(HttpServletRequest request, String requestPath,
List<? extends Resource> locations, ResourceResolverChain chain) { List<? extends Resource> locations, ResourceResolverChain chain) {
@ -67,7 +70,7 @@ public class CachingResourceResolver extends AbstractResourceResolver {
if (resource != null) { if (resource != null) {
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
logger.trace("Found match"); logger.trace("Found match: " + resource);
} }
return resource; return resource;
} }
@ -75,7 +78,7 @@ public class CachingResourceResolver extends AbstractResourceResolver {
resource = chain.resolveResource(request, requestPath, locations); resource = chain.resolveResource(request, requestPath, locations);
if (resource != null) { if (resource != null) {
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
logger.trace("Putting resolved resource in cache"); logger.trace("Putting resolved resource in cache: " + resource);
} }
this.cache.put(key, resource); this.cache.put(key, resource);
} }
@ -104,7 +107,7 @@ public class CachingResourceResolver extends AbstractResourceResolver {
if (resolvedUrlPath != null) { if (resolvedUrlPath != null) {
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
logger.trace("Found match"); logger.trace("Found match: \"" + resolvedUrlPath + "\"");
} }
return resolvedUrlPath; return resolvedUrlPath;
} }
@ -112,7 +115,7 @@ public class CachingResourceResolver extends AbstractResourceResolver {
resolvedUrlPath = chain.resolveUrlPath(resourceUrlPath, locations); resolvedUrlPath = chain.resolveUrlPath(resourceUrlPath, locations);
if (resolvedUrlPath != null) { if (resolvedUrlPath != null) {
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
logger.trace("Putting resolved resource URL path in cache"); logger.trace("Putting resolved resource URL path in cache: \"" + resolvedUrlPath + "\"");
} }
this.cache.put(key, resolvedUrlPath); this.cache.put(key, resolvedUrlPath);
} }

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

@ -42,12 +42,13 @@ public class CachingResourceTransformer implements ResourceTransformer {
private final Cache cache; private final Cache cache;
public CachingResourceTransformer(CacheManager cacheManager, String cacheName) { public CachingResourceTransformer(CacheManager cacheManager, String cacheName) {
this(cacheManager.getCache(cacheName)); this(cacheManager.getCache(cacheName));
} }
public CachingResourceTransformer(Cache cache) { public CachingResourceTransformer(Cache cache) {
Assert.notNull(cache, "'cache' is required"); Assert.notNull(cache, "Cache is required");
this.cache = cache; this.cache = cache;
} }
@ -59,6 +60,7 @@ public class CachingResourceTransformer implements ResourceTransformer {
return this.cache; return this.cache;
} }
@Override @Override
public Resource transform(HttpServletRequest request, Resource resource, ResourceTransformerChain transformerChain) public Resource transform(HttpServletRequest request, Resource resource, ResourceTransformerChain transformerChain)
throws IOException { throws IOException {
@ -66,7 +68,7 @@ public class CachingResourceTransformer implements ResourceTransformer {
Resource transformed = this.cache.get(resource, Resource.class); Resource transformed = this.cache.get(resource, Resource.class);
if (transformed != null) { if (transformed != null) {
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
logger.trace("Found match"); logger.trace("Found match: " + transformed);
} }
return transformed; return transformed;
} }
@ -74,7 +76,7 @@ public class CachingResourceTransformer implements ResourceTransformer {
transformed = transformerChain.transform(request, resource); transformed = transformerChain.transform(request, resource);
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
logger.trace("Putting transformed resource in cache"); logger.trace("Putting transformed resource in cache: " + transformed);
} }
this.cache.put(resource, transformed); this.cache.put(resource, transformed);

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.web.servlet.resource; package org.springframework.web.servlet.resource;
import java.io.IOException; import java.io.IOException;
@ -33,12 +34,10 @@ import org.springframework.util.FileCopyUtils;
*/ */
public class ContentVersionStrategy extends AbstractVersionStrategy { public class ContentVersionStrategy extends AbstractVersionStrategy {
public ContentVersionStrategy() { public ContentVersionStrategy() {
super(new FileNameVersionPathStrategy()); super(new FileNameVersionPathStrategy());
} }
@Override @Override
public String getResourceVersion(Resource resource) { public String getResourceVersion(Resource resource) {
try { try {
@ -46,7 +45,7 @@ public class ContentVersionStrategy extends AbstractVersionStrategy {
return DigestUtils.md5DigestAsHex(content); return DigestUtils.md5DigestAsHex(content);
} }
catch (IOException ex) { catch (IOException ex) {
throw new IllegalStateException("Failed to calculate hash for resource [" + resource + "]", ex); throw new IllegalStateException("Failed to calculate hash for " + resource, ex);
} }
} }

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,7 +23,6 @@ import javax.servlet.http.HttpServletRequest;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
* A default implementation of {@link ResourceResolverChain} for invoking a list * A default implementation of {@link ResourceResolverChain} for invoking a list
* of {@link ResourceResolver}s. * of {@link ResourceResolver}s.
@ -53,6 +52,7 @@ class DefaultResourceResolverChain implements ResourceResolverChain {
if (resolver == null) { if (resolver == null) {
return null; return null;
} }
try { try {
return resolver.resolveResource(request, requestPath, locations, this); return resolver.resolveResource(request, requestPath, locations, this);
} }
@ -67,6 +67,7 @@ class DefaultResourceResolverChain implements ResourceResolverChain {
if (resolver == null) { if (resolver == null) {
return null; return null;
} }
try { try {
return resolver.resolveUrlPath(resourcePath, locations, this); return resolver.resolveUrlPath(resourcePath, locations, this);
} }
@ -76,7 +77,6 @@ class DefaultResourceResolverChain implements ResourceResolverChain {
} }
private ResourceResolver getNext() { private ResourceResolver getNext() {
Assert.state(this.index <= this.resolvers.size(), Assert.state(this.index <= this.resolvers.size(),
"Current index exceeds the number of configured ResourceResolver's"); "Current index exceeds the number of configured ResourceResolver's");

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -25,8 +25,8 @@ import org.springframework.core.io.Resource;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
* A default implementation of {@link ResourceTransformerChain} for invoking a list * A default implementation of {@link ResourceTransformerChain} for invoking
* of {@link ResourceTransformer}s. * a list of {@link ResourceTransformer}s.
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @since 4.1 * @since 4.1
@ -39,10 +39,11 @@ class DefaultResourceTransformerChain implements ResourceTransformerChain {
private int index = -1; private int index = -1;
public DefaultResourceTransformerChain(ResourceResolverChain resolverChain, public DefaultResourceTransformerChain(ResourceResolverChain resolverChain,
List<ResourceTransformer> transformers) { List<ResourceTransformer> transformers) {
Assert.notNull(resolverChain, "'resolverChain' is required"); Assert.notNull(resolverChain, "ResourceResolverChain is required");
this.resolverChain = resolverChain; this.resolverChain = resolverChain;
if (transformers != null) { if (transformers != null) {
this.transformers.addAll(transformers); this.transformers.addAll(transformers);
@ -54,12 +55,14 @@ class DefaultResourceTransformerChain implements ResourceTransformerChain {
return this.resolverChain; return this.resolverChain;
} }
@Override @Override
public Resource transform(HttpServletRequest request, Resource resource) throws IOException { public Resource transform(HttpServletRequest request, Resource resource) throws IOException {
ResourceTransformer transformer = getNext(); ResourceTransformer transformer = getNext();
if (transformer == null) { if (transformer == null) {
return resource; return resource;
} }
try { try {
return transformer.transform(request, resource, this); return transformer.transform(request, resource, this);
} }
@ -69,7 +72,6 @@ class DefaultResourceTransformerChain implements ResourceTransformerChain {
} }
private ResourceTransformer getNext() { private ResourceTransformer getNext() {
Assert.state(this.index <= this.transformers.size(), Assert.state(this.index <= this.transformers.size(),
"Current index exceeds the number of configured ResourceTransformer's"); "Current index exceeds the number of configured ResourceTransformer's");

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -117,7 +117,7 @@ public class DefaultServletHttpRequestHandler implements HttpRequestHandler, Ser
RequestDispatcher rd = this.servletContext.getNamedDispatcher(this.defaultServletName); RequestDispatcher rd = this.servletContext.getNamedDispatcher(this.defaultServletName);
if (rd == null) { if (rd == null) {
throw new IllegalStateException("A RequestDispatcher could not be located for the default servlet '" + throw new IllegalStateException("A RequestDispatcher could not be located for the default servlet '" +
this.defaultServletName +"'"); this.defaultServletName + "'");
} }
rd.forward(request, response); rd.forward(request, response);
} }

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,7 +18,6 @@ package org.springframework.web.servlet.resource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
/** /**
* Interface for a resource descriptor that describes the encoding * Interface for a resource descriptor that describes the encoding
* applied to the entire resource content. * applied to the entire resource content.
@ -39,6 +38,6 @@ public interface EncodedResource extends Resource {
* @see <a href="http://tools.ietf.org/html/rfc7231#section-3.1.2.1">HTTP/1.1: Semantics * @see <a href="http://tools.ietf.org/html/rfc7231#section-3.1.2.1">HTTP/1.1: Semantics
* and Content, section 3.1.2.1</a> * and Content, section 3.1.2.1</a>
*/ */
public String getContentEncoding(); String getContentEncoding();
} }

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.web.servlet.resource; package org.springframework.web.servlet.resource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
@ -34,6 +35,7 @@ public class FixedVersionStrategy extends AbstractVersionStrategy {
private final String version; private final String version;
/** /**
* Create a new FixedVersionStrategy with the given version string. * Create a new FixedVersionStrategy with the given version string.
* @param version the fixed version string to use * @param version the fixed version string to use

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

@ -27,7 +27,6 @@ import javax.servlet.http.HttpServletRequest;
import org.springframework.core.io.AbstractResource; import org.springframework.core.io.AbstractResource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
/** /**
* A {@code ResourceResolver} that delegates to the chain to locate a resource * A {@code ResourceResolver} that delegates to the chain to locate a resource
* and then attempts to find a variation with the ".gz" extension. * and then attempts to find a variation with the ".gz" extension.
@ -42,7 +41,6 @@ import org.springframework.core.io.Resource;
*/ */
public class GzipResourceResolver extends AbstractResourceResolver { public class GzipResourceResolver extends AbstractResourceResolver {
@Override @Override
protected Resource resolveResourceInternal(HttpServletRequest request, String requestPath, protected Resource resolveResourceInternal(HttpServletRequest request, String requestPath,
List<? extends Resource> locations, ResourceResolverChain chain) { List<? extends Resource> locations, ResourceResolverChain chain) {
@ -58,8 +56,8 @@ public class GzipResourceResolver extends AbstractResourceResolver {
return gzipped; return gzipped;
} }
} }
catch (IOException e) { catch (IOException ex) {
logger.trace("No gzipped resource for [" + resource.getFilename() + "]", e); logger.trace("No gzipped resource for [" + resource.getFilename() + "]", ex);
} }
return resource; return resource;
@ -67,7 +65,7 @@ public class GzipResourceResolver extends AbstractResourceResolver {
private boolean isGzipAccepted(HttpServletRequest request) { private boolean isGzipAccepted(HttpServletRequest request) {
String value = request.getHeader("Accept-Encoding"); String value = request.getHeader("Accept-Encoding");
return ((value != null) && value.toLowerCase().contains("gzip")); return (value != null && value.toLowerCase().contains("gzip"));
} }
@Override @Override
@ -84,13 +82,11 @@ public class GzipResourceResolver extends AbstractResourceResolver {
private final Resource gzipped; private final Resource gzipped;
public GzippedResource(Resource original) throws IOException { public GzippedResource(Resource original) throws IOException {
this.original = original; this.original = original;
this.gzipped = original.createRelative(original.getFilename() + ".gz"); this.gzipped = original.createRelative(original.getFilename() + ".gz");
} }
public InputStream getInputStream() throws IOException { public InputStream getInputStream() throws IOException {
return this.gzipped.getInputStream(); return this.gzipped.getInputStream();
} }

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -25,8 +25,8 @@ import org.springframework.core.io.Resource;
* A strategy for resolving a request to a server-side resource. * A strategy for resolving a request to a server-side resource.
* *
* <p>Provides mechanisms for resolving an incoming request to an actual * <p>Provides mechanisms for resolving an incoming request to an actual
* {@link org.springframework.core.io.Resource} and for obtaining the public * {@link org.springframework.core.io.Resource} and for obtaining the
* URL path that clients should use when requesting the resource. * public URL path that clients should use when requesting the resource.
* *
* @author Jeremy Grelle * @author Jeremy Grelle
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
@ -39,7 +39,6 @@ public interface ResourceResolver {
/** /**
* Resolve the supplied request and request path to a {@link Resource} that * Resolve the supplied request and request path to a {@link Resource} that
* exists under one of the given resource locations. * exists under one of the given resource locations.
*
* @param request the current request * @param request the current request
* @param requestPath the portion of the request path to use * @param requestPath the portion of the request path to use
* @param locations the locations to search in when looking up resources * @param locations the locations to search in when looking up resources
@ -53,9 +52,7 @@ public interface ResourceResolver {
* Resolve the externally facing <em>public</em> URL path for clients to use * Resolve the externally facing <em>public</em> URL path for clients to use
* to access the resource that is located at the given <em>internal</em> * to access the resource that is located at the given <em>internal</em>
* resource path. * resource path.
*
* <p>This is useful when rendering URL links to clients. * <p>This is useful when rendering URL links to clients.
*
* @param resourcePath the internal resource path * @param resourcePath the internal resource path
* @param locations the locations to search in when looking up resources * @param locations the locations to search in when looking up resources
* @param chain the chain of resolvers to delegate to * @param chain the chain of resolvers to delegate to

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -35,7 +35,6 @@ public interface ResourceResolverChain {
/** /**
* Resolve the supplied request and request path to a {@link Resource} that * Resolve the supplied request and request path to a {@link Resource} that
* exists under one of the given resource locations. * exists under one of the given resource locations.
*
* @param request the current request * @param request the current request
* @param requestPath the portion of the request path to use * @param requestPath the portion of the request path to use
* @param locations the locations to search in when looking up resources * @param locations the locations to search in when looking up resources
@ -47,9 +46,7 @@ public interface ResourceResolverChain {
* Resolve the externally facing <em>public</em> URL path for clients to use * Resolve the externally facing <em>public</em> URL path for clients to use
* to access the resource that is located at the given <em>internal</em> * to access the resource that is located at the given <em>internal</em>
* resource path. * resource path.
*
* <p>This is useful when rendering URL links to clients. * <p>This is useful when rendering URL links to clients.
*
* @param resourcePath the internal resource path * @param resourcePath the internal resource path
* @param locations the locations to search in when looking up resources * @param locations the locations to search in when looking up resources
* @return the resolved public URL path or {@code null} if unresolved * @return the resolved public URL path or {@code null} if unresolved

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.web.servlet.resource;
package org.springframework.web.servlet.resource;
import java.io.IOException; import java.io.IOException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -32,12 +32,10 @@ public interface ResourceTransformer {
/** /**
* Transform the given resource. * Transform the given resource.
*
* @param request the current request * @param request the current request
* @param resource the resource to transform * @param resource the resource to transform
* @param transformerChain the chain of remaining transformers to delegate to * @param transformerChain the chain of remaining transformers to delegate to
* @return the transformed resource, never {@code null} * @return the transformed resource, never {@code null}
*
* @throws IOException if the transformation fails * @throws IOException if the transformation fails
*/ */
Resource transform(HttpServletRequest request, Resource resource, ResourceTransformerChain transformerChain) Resource transform(HttpServletRequest request, Resource resource, ResourceTransformerChain transformerChain)

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -39,12 +39,10 @@ public interface ResourceTransformerChain {
/** /**
* Transform the given resource. * Transform the given resource.
*
* @param request the current request * @param request the current request
* @param resource the candidate resource to transform * @param resource the candidate resource to transform
* @return the transformed or the same resource, never {@code null} * @return the transformed or the same resource, never {@code null}
* * @throws IOException if transformation fails
* @throws java.io.IOException if transformation fails
*/ */
Resource transform(HttpServletRequest request, Resource resource) throws IOException; Resource transform(HttpServletRequest request, Resource resource) throws IOException;

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.web.servlet.resource; package org.springframework.web.servlet.resource;
import java.util.Arrays; import java.util.Collections;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
@ -38,7 +39,6 @@ public abstract class ResourceTransformerSupport implements ResourceTransformer
* URL of links in a transformed resource (e.g. import links in a CSS file). * URL of links in a transformed resource (e.g. import links in a CSS file).
* This is required only for links expressed as full paths, i.e. including * This is required only for links expressed as full paths, i.e. including
* context and servlet path, and not for relative links. * context and servlet path, and not for relative links.
*
* <p>By default this property is not set. In that case if a * <p>By default this property is not set. In that case if a
* {@code ResourceUrlProvider} is needed an attempt is made to find the * {@code ResourceUrlProvider} is needed an attempt is made to find the
* {@code ResourceUrlProvider} exposed through the * {@code ResourceUrlProvider} exposed through the
@ -65,7 +65,6 @@ public abstract class ResourceTransformerSupport implements ResourceTransformer
* contains links to other resources. Such links need to be replaced with the * contains links to other resources. Such links need to be replaced with the
* public facing link as determined by the resource resolver chain (e.g. the * public facing link as determined by the resource resolver chain (e.g. the
* public URL may have a version inserted). * public URL may have a version inserted).
*
* @param resourcePath the path to a resource that needs to be re-written * @param resourcePath the path to a resource that needs to be re-written
* @param request the current request * @param request the current request
* @param resource the resource being transformed * @param resource the resource being transformed
@ -82,7 +81,8 @@ public abstract class ResourceTransformerSupport implements ResourceTransformer
} }
else { else {
// try resolving as relative path // try resolving as relative path
return transformerChain.getResolverChain().resolveUrlPath(resourcePath, Arrays.asList(resource)); return transformerChain.getResolverChain().resolveUrlPath(
resourcePath, Collections.singletonList(resource));
} }
} }

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,9 +22,9 @@ import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
/** /**
* An extension of {@link org.springframework.core.io.ByteArrayResource} that a * An extension of {@link org.springframework.core.io.ByteArrayResource}
* {@link ResourceTransformer} can use to represent an original resource * that a {@link ResourceTransformer} can use to represent an original
* preserving all other information except the content. * resource preserving all other information except the content.
* *
* @author Jeremy Grelle * @author Jeremy Grelle
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
@ -43,9 +43,9 @@ public class TransformedResource extends ByteArrayResource {
try { try {
this.lastModified = original.lastModified(); this.lastModified = original.lastModified();
} }
catch (IOException e) { catch (IOException ex) {
// should never happen // should never happen
throw new IllegalArgumentException(e); throw new IllegalArgumentException(ex);
} }
} }

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.web.servlet.resource; package org.springframework.web.servlet.resource;
/** /**

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -13,13 +13,14 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.web.servlet.resource; package org.springframework.web.servlet.resource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
/** /**
* An extension of {@link VersionPathStrategy} that adds a method to determine the * An extension of {@link VersionPathStrategy} that adds a method
* actual version of a {@link org.springframework.core.io.Resource Resource}. * to determine the actual version of a {@link Resource}.
* *
* @author Brian Clozel * @author Brian Clozel
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
@ -29,9 +30,9 @@ import org.springframework.core.io.Resource;
public interface VersionStrategy extends VersionPathStrategy { public interface VersionStrategy extends VersionPathStrategy {
/** /**
* Get the version for the given resource. * Determine the version for the given resource.
* @param resource the resource to check * @param resource the resource to check
* @return the version, never {@code null} * @return the version (never {@code null})
*/ */
String getResourceVersion(Resource resource); String getResourceVersion(Resource resource);

Loading…
Cancel
Save