Polishing
This commit is contained in:
@@ -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.
|
||||
@@ -395,12 +395,7 @@ public class FormHttpMessageConverter implements HttpMessageConverter<MultiValue
|
||||
* or a newly built {@link HttpEntity} wrapper for that part
|
||||
*/
|
||||
protected HttpEntity<?> getHttpEntity(Object part) {
|
||||
if (part instanceof HttpEntity) {
|
||||
return (HttpEntity<?>) part;
|
||||
}
|
||||
else {
|
||||
return new HttpEntity<Object>(part);
|
||||
}
|
||||
return (part instanceof HttpEntity ? (HttpEntity<?>) part : new HttpEntity<Object>(part));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -415,7 +410,7 @@ public class FormHttpMessageConverter implements HttpMessageConverter<MultiValue
|
||||
if (part instanceof Resource) {
|
||||
Resource resource = (Resource) part;
|
||||
String filename = resource.getFilename();
|
||||
if (this.multipartCharset != null) {
|
||||
if (filename != null && this.multipartCharset != null) {
|
||||
filename = MimeDelegate.encode(filename, this.multipartCharset.name());
|
||||
}
|
||||
return filename;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -67,14 +67,14 @@ public interface GenericHttpMessageConverter<T> extends HttpMessageConverter<T>
|
||||
|
||||
/**
|
||||
* Indicates whether the given class can be written by this converter.
|
||||
* This method should perform the same checks than
|
||||
* <p>This method should perform the same checks than
|
||||
* {@link HttpMessageConverter#canWrite(Class, MediaType)} with additional ones
|
||||
* related to the generic type.
|
||||
* @param type the (potentially generic) type to test for writability, can be
|
||||
* {@code null} if not specified.
|
||||
* @param type the (potentially generic) type to test for writability
|
||||
* (can be {@code null} if not specified)
|
||||
* @param clazz the source object class to test for writability
|
||||
* @param mediaType the media type to write, can be {@code null} if not specified.
|
||||
* Typically the value of an {@code Accept} header.
|
||||
* @param mediaType the media type to write (can be {@code null} if not specified);
|
||||
* typically the value of an {@code Accept} header.
|
||||
* @return {@code true} if writable; {@code false} otherwise
|
||||
* @since 4.2
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -35,8 +35,8 @@ public interface HttpMessageConverter<T> {
|
||||
/**
|
||||
* Indicates whether the given class can be read by this converter.
|
||||
* @param clazz the class to test for readability
|
||||
* @param mediaType the media type to read, can be {@code null} if not specified.
|
||||
* Typically the value of a {@code Content-Type} header.
|
||||
* @param mediaType the media type to read (can be {@code null} if not specified);
|
||||
* typically the value of a {@code Content-Type} header.
|
||||
* @return {@code true} if readable; {@code false} otherwise
|
||||
*/
|
||||
boolean canRead(Class<?> clazz, MediaType mediaType);
|
||||
@@ -44,8 +44,8 @@ public interface HttpMessageConverter<T> {
|
||||
/**
|
||||
* Indicates whether the given class can be written by this converter.
|
||||
* @param clazz the class to test for writability
|
||||
* @param mediaType the media type to write, can be {@code null} if not specified.
|
||||
* Typically the value of an {@code Accept} header.
|
||||
* @param mediaType the media type to write (can be {@code null} if not specified);
|
||||
* typically the value of an {@code Accept} header.
|
||||
* @return {@code true} if writable; {@code false} otherwise
|
||||
*/
|
||||
boolean canWrite(Class<?> clazz, MediaType mediaType);
|
||||
|
||||
@@ -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.
|
||||
@@ -24,7 +24,6 @@ import com.google.gson.GsonBuilder;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
|
||||
/**
|
||||
* A {@link FactoryBean} for creating a Google Gson 2.x {@link Gson} instance.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -187,10 +187,9 @@ public class Jaxb2CollectionHttpMessageConverter<T extends Collection>
|
||||
try {
|
||||
return (T) collectionClass.newInstance();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalArgumentException(
|
||||
"Could not instantiate collection class [" +
|
||||
collectionClass.getName() + "]: " + ex.getMessage());
|
||||
"Could not instantiate collection class: " + collectionClass.getName(), ex);
|
||||
}
|
||||
}
|
||||
else if (List.class == collectionClass) {
|
||||
@@ -230,6 +229,7 @@ public class Jaxb2CollectionHttpMessageConverter<T extends Collection>
|
||||
@Override
|
||||
public void write(T t, Type type, MediaType contentType, HttpOutputMessage outputMessage)
|
||||
throws IOException, HttpMessageNotWritableException {
|
||||
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -71,6 +71,7 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter {
|
||||
|
||||
private final UrlPathHelper pathHelper;
|
||||
|
||||
|
||||
public ForwardedHeaderFilter() {
|
||||
this.pathHelper = new UrlPathHelper();
|
||||
this.pathHelper.setUrlDecode(false);
|
||||
@@ -143,8 +144,7 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter {
|
||||
String prefix = getForwardedPrefix(request);
|
||||
this.contextPath = (prefix != null ? prefix : request.getContextPath());
|
||||
this.requestUri = this.contextPath + pathHelper.getPathWithinApplication(request);
|
||||
this.requestUrl = this.scheme + "://" + this.host +
|
||||
(port == -1 ? "" : ":" + port) + this.requestUri;
|
||||
this.requestUrl = this.scheme + "://" + this.host + (port == -1 ? "" : ":" + port) + this.requestUri;
|
||||
this.headers = initHeaders(request);
|
||||
}
|
||||
|
||||
@@ -235,13 +235,13 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class ForwardedHeaderResponseWrapper extends HttpServletResponseWrapper {
|
||||
|
||||
private static final String FOLDER_SEPARATOR = "/";
|
||||
|
||||
private final HttpServletRequest request;
|
||||
|
||||
|
||||
public ForwardedHeaderResponseWrapper(HttpServletResponse response, HttpServletRequest request) {
|
||||
super(response);
|
||||
this.request = request;
|
||||
@@ -249,7 +249,6 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter {
|
||||
|
||||
@Override
|
||||
public void sendRedirect(String location) throws IOException {
|
||||
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(location);
|
||||
|
||||
// Absolute location
|
||||
@@ -259,20 +258,15 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter {
|
||||
}
|
||||
|
||||
// Network-path reference
|
||||
if(location.startsWith("//")) {
|
||||
if (location.startsWith("//")) {
|
||||
String scheme = this.request.getScheme();
|
||||
super.sendRedirect(builder.scheme(scheme).toUriString());
|
||||
return;
|
||||
}
|
||||
|
||||
// Relative to Servlet container root or to current request
|
||||
String path;
|
||||
if (location.startsWith(FOLDER_SEPARATOR)) {
|
||||
path = location;
|
||||
}
|
||||
else {
|
||||
path = StringUtils.applyRelativePath(this.request.getRequestURI(), location);
|
||||
}
|
||||
String path = (location.startsWith(FOLDER_SEPARATOR) ? location :
|
||||
StringUtils.applyRelativePath(this.request.getRequestURI(), location));
|
||||
|
||||
String result = UriComponentsBuilder
|
||||
.fromHttpRequest(new ServletServerHttpRequest(this.request))
|
||||
|
||||
Reference in New Issue
Block a user