Polishing
This commit is contained in:
parent
356eaef20e
commit
0968e47b04
|
|
@ -18,7 +18,6 @@ package org.springframework.util;
|
|||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Base64;
|
||||
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
|
||||
import org.springframework.lang.UsesJava8;
|
||||
|
|
@ -106,6 +105,7 @@ public abstract class Base64Utils {
|
|||
* @return the encoded byte array (or {@code null} if the input was {@code null})
|
||||
* @throws IllegalStateException if Base64 encoding between byte arrays is not
|
||||
* supported, i.e. neither Java 8 nor Apache Commons Codec is present at runtime
|
||||
* @since 4.2.4
|
||||
*/
|
||||
public static byte[] encodeUrlSafe(byte[] src) {
|
||||
assertDelegateAvailable();
|
||||
|
|
@ -119,6 +119,7 @@ public abstract class Base64Utils {
|
|||
* @return the original byte array (or {@code null} if the input was {@code null})
|
||||
* @throws IllegalStateException if Base64 encoding between byte arrays is not
|
||||
* supported, i.e. neither Java 8 nor Apache Commons Codec is present at runtime
|
||||
* @since 4.2.4
|
||||
*/
|
||||
public static byte[] decodeUrlSafe(byte[] src) {
|
||||
assertDelegateAvailable();
|
||||
|
|
@ -252,9 +253,11 @@ public abstract class Base64Utils {
|
|||
|
||||
static class CommonsCodecBase64Delegate implements Base64Delegate {
|
||||
|
||||
private final org.apache.commons.codec.binary.Base64 base64 = new org.apache.commons.codec.binary.Base64();
|
||||
private final org.apache.commons.codec.binary.Base64 base64 =
|
||||
new org.apache.commons.codec.binary.Base64();
|
||||
|
||||
private final org.apache.commons.codec.binary.Base64 base64UrlSafe = new org.apache.commons.codec.binary.Base64(0, null, true);
|
||||
private final org.apache.commons.codec.binary.Base64 base64UrlSafe =
|
||||
new org.apache.commons.codec.binary.Base64(0, null, true);
|
||||
|
||||
@Override
|
||||
public byte[] encode(byte[] src) {
|
||||
|
|
|
|||
|
|
@ -54,9 +54,9 @@ public class ResourceUrlEncodingFilter extends OncePerRequestFilter {
|
|||
|
||||
private static class ResourceUrlEncodingResponseWrapper extends HttpServletResponseWrapper {
|
||||
|
||||
private HttpServletRequest request;
|
||||
private final HttpServletRequest request;
|
||||
|
||||
/* Cache the index of the path within the DispatcherServlet mapping. */
|
||||
/* Cache the index of the path within the DispatcherServlet mapping */
|
||||
private Integer indexLookupPath;
|
||||
|
||||
public ResourceUrlEncodingResponseWrapper(HttpServletRequest request, HttpServletResponse wrapped) {
|
||||
|
|
@ -71,6 +71,7 @@ public class ResourceUrlEncodingFilter extends OncePerRequestFilter {
|
|||
logger.debug("Request attribute exposing ResourceUrlProvider not found");
|
||||
return super.encodeURL(url);
|
||||
}
|
||||
|
||||
initIndexLookupPath(resourceUrlProvider);
|
||||
if (url.length() >= this.indexLookupPath) {
|
||||
String prefix = url.substring(0, this.indexLookupPath);
|
||||
|
|
@ -82,12 +83,13 @@ public class ResourceUrlEncodingFilter extends OncePerRequestFilter {
|
|||
return super.encodeURL(prefix + lookupPath + suffix);
|
||||
}
|
||||
}
|
||||
|
||||
return super.encodeURL(url);
|
||||
}
|
||||
|
||||
private ResourceUrlProvider getResourceUrlProvider() {
|
||||
String name = ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR;
|
||||
return (ResourceUrlProvider) this.request.getAttribute(name);
|
||||
return (ResourceUrlProvider) this.request.getAttribute(
|
||||
ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR);
|
||||
}
|
||||
|
||||
private void initIndexLookupPath(ResourceUrlProvider urlProvider) {
|
||||
|
|
@ -107,7 +109,7 @@ public class ResourceUrlEncodingFilter extends OncePerRequestFilter {
|
|||
|
||||
private int getQueryParamsIndex(String url) {
|
||||
int index = url.indexOf("?");
|
||||
return index > 0 ? index : url.length();
|
||||
return (index > 0 ? index : url.length());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -34,20 +34,19 @@ public class ResourceUrlProviderExposingInterceptor extends HandlerInterceptorAd
|
|||
/**
|
||||
* Name of the request attribute that holds the {@link ResourceUrlProvider}.
|
||||
*/
|
||||
public static final String RESOURCE_URL_PROVIDER_ATTR = ResourceUrlProvider.class.getName().toString();
|
||||
|
||||
public static final String RESOURCE_URL_PROVIDER_ATTR = ResourceUrlProvider.class.getName();
|
||||
|
||||
private final ResourceUrlProvider resourceUrlProvider;
|
||||
|
||||
|
||||
public ResourceUrlProviderExposingInterceptor(ResourceUrlProvider resourceUrlProvider) {
|
||||
Assert.notNull(resourceUrlProvider, "'resourceUrlProvider' is required");
|
||||
Assert.notNull(resourceUrlProvider, "ResourceUrlProvider is required");
|
||||
this.resourceUrlProvider = resourceUrlProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
|
||||
Object handler) throws Exception {
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
||||
throws Exception {
|
||||
|
||||
request.setAttribute(RESOURCE_URL_PROVIDER_ATTR, this.resourceUrlProvider);
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Reference in New Issue