Merge branch '3.2.x' into master
Conflicts: gradle.properties spring-beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheManagerFactoryBean.java spring-core/src/main/java/org/springframework/core/convert/support/StringToEnumConverterFactory.java spring-core/src/main/java/org/springframework/core/env/ReadOnlySystemAttributesMap.java spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/AbstractLobHandler.java spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpRequestWrapper.java spring-web/src/main/java/org/springframework/http/client/SimpleBufferingClientHttpRequest.java spring-web/src/main/java/org/springframework/http/converter/BufferedImageHttpMessageConverter.java spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -125,7 +125,9 @@ public enum HttpStatus {
|
||||
/**
|
||||
* {@code 302 Moved Temporarily}.
|
||||
* @see <a href="http://tools.ietf.org/html/rfc1945#section-9.3">HTTP/1.0</a>
|
||||
* @deprecated In favor of {@link #FOUND} which will be returned from {@code HttpStatus.valueOf(302)}
|
||||
*/
|
||||
@Deprecated
|
||||
MOVED_TEMPORARILY(302, "Moved Temporarily"),
|
||||
/**
|
||||
* {@code 303 See Other}.
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2002-2013 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
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.http;
|
||||
|
||||
/**
|
||||
* Exception thrown from {@link MediaType#parseMediaType(String)} in case of
|
||||
* encountering an invalid media type specification String.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.2.2
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class InvalidMediaTypeException extends IllegalArgumentException {
|
||||
|
||||
private String mediaType;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new InvalidMediaTypeException for the given media type.
|
||||
* @param mediaType the offending media type
|
||||
* @param msg a detail message indicating the invalid part
|
||||
*/
|
||||
public InvalidMediaTypeException(String mediaType, String msg) {
|
||||
super("Invalid media type \"" + mediaType + "\": " + msg);
|
||||
this.mediaType = mediaType;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the offending media type.
|
||||
*/
|
||||
public String getMediaType() {
|
||||
return this.mediaType;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.http;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.UnsupportedCharsetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.Collection;
|
||||
@@ -321,8 +322,8 @@ public class MediaType implements Comparable<MediaType> {
|
||||
* @throws IllegalArgumentException if any of the parameters contain illegal characters
|
||||
*/
|
||||
public MediaType(String type, String subtype, Map<String, String> parameters) {
|
||||
Assert.hasLength(type, "'type' must not be empty");
|
||||
Assert.hasLength(subtype, "'subtype' must not be empty");
|
||||
Assert.hasLength(type, "type must not be empty");
|
||||
Assert.hasLength(subtype, "subtype must not be empty");
|
||||
checkToken(type);
|
||||
checkToken(subtype);
|
||||
this.type = type.toLowerCase(Locale.ENGLISH);
|
||||
@@ -347,11 +348,11 @@ public class MediaType implements Comparable<MediaType> {
|
||||
* @throws IllegalArgumentException in case of illegal characters
|
||||
* @see <a href="http://tools.ietf.org/html/rfc2616#section-2.2">HTTP 1.1, section 2.2</a>
|
||||
*/
|
||||
private void checkToken(String s) {
|
||||
for (int i=0; i < s.length(); i++ ) {
|
||||
char ch = s.charAt(i);
|
||||
private void checkToken(String token) {
|
||||
for (int i=0; i < token.length(); i++ ) {
|
||||
char ch = token.charAt(i);
|
||||
if (!TOKEN.get(ch)) {
|
||||
throw new IllegalArgumentException("Invalid token character '" + ch + "' in token \"" + s + "\"");
|
||||
throw new IllegalArgumentException("Invalid token character '" + ch + "' in token \"" + token + "\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -681,7 +682,7 @@ public class MediaType implements Comparable<MediaType> {
|
||||
* Parse the given String into a single {@code MediaType}.
|
||||
* @param mediaType the string to parse
|
||||
* @return the media type
|
||||
* @throws IllegalArgumentException if the string cannot be parsed
|
||||
* @throws InvalidMediaTypeException if the string cannot be parsed
|
||||
*/
|
||||
public static MediaType parseMediaType(String mediaType) {
|
||||
Assert.hasLength(mediaType, "'mediaType' must not be empty");
|
||||
@@ -694,15 +695,15 @@ public class MediaType implements Comparable<MediaType> {
|
||||
}
|
||||
int subIndex = fullType.indexOf('/');
|
||||
if (subIndex == -1) {
|
||||
throw new IllegalArgumentException("\"" + mediaType + "\" does not contain '/'");
|
||||
throw new InvalidMediaTypeException(mediaType, "does not contain '/'");
|
||||
}
|
||||
if (subIndex == fullType.length() - 1) {
|
||||
throw new IllegalArgumentException("\"" + mediaType + "\" does not contain subtype after '/'");
|
||||
throw new InvalidMediaTypeException(mediaType, "does not contain subtype after '/'");
|
||||
}
|
||||
String type = fullType.substring(0, subIndex);
|
||||
String subtype = fullType.substring(subIndex + 1, fullType.length());
|
||||
if (WILDCARD_TYPE.equals(type) && !WILDCARD_TYPE.equals(subtype)) {
|
||||
throw new IllegalArgumentException("A wildcard type is legal only in '*/*' (all media types).");
|
||||
throw new InvalidMediaTypeException(mediaType, "wildcard type is legal only in '*/*' (all media types)");
|
||||
}
|
||||
|
||||
Map<String, String> parameters = null;
|
||||
@@ -719,7 +720,15 @@ public class MediaType implements Comparable<MediaType> {
|
||||
}
|
||||
}
|
||||
|
||||
return new MediaType(type, subtype, parameters);
|
||||
try {
|
||||
return new MediaType(type, subtype, parameters);
|
||||
}
|
||||
catch (UnsupportedCharsetException ex) {
|
||||
throw new InvalidMediaTypeException(mediaType, "unsupported charset '" + ex.getCharsetName() + "'");
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
throw new InvalidMediaTypeException(mediaType, ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -23,7 +23,7 @@ import java.net.URI;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
/**
|
||||
* Simple implementation of {@link ClientHttpRequest} that wraps another request.
|
||||
@@ -53,8 +53,7 @@ final class BufferingClientHttpRequestWrapper extends AbstractBufferingClientHtt
|
||||
@Override
|
||||
protected ClientHttpResponse executeInternal(HttpHeaders headers, byte[] bufferedOutput) throws IOException {
|
||||
this.request.getHeaders().putAll(headers);
|
||||
OutputStream body = this.request.getBody();
|
||||
FileCopyUtils.copy(bufferedOutput, body);
|
||||
StreamUtils.copy(bufferedOutput, this.request.getBody());
|
||||
ClientHttpResponse response = this.request.execute();
|
||||
return new BufferingClientHttpResponseWrapper(response);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -23,6 +23,7 @@ import java.io.InputStream;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
/**
|
||||
* Simple implementation of {@link ClientHttpResponse} that reads the request's body into memory,
|
||||
@@ -61,7 +62,7 @@ final class BufferingClientHttpResponseWrapper implements ClientHttpResponse {
|
||||
|
||||
public InputStream getBody() throws IOException {
|
||||
if (this.body == null) {
|
||||
this.body = FileCopyUtils.copyToByteArray(this.response.getBody());
|
||||
this.body = StreamUtils.copyToByteArray(this.response.getBody());
|
||||
}
|
||||
return new ByteArrayInputStream(this.body);
|
||||
}
|
||||
|
||||
@@ -74,4 +74,4 @@ final class CommonsClientHttpResponse extends AbstractClientHttpResponse {
|
||||
this.httpMethod.releaseConnection();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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,7 @@ import java.util.List;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpRequest;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
/**
|
||||
* Wrapper for a {@link ClientHttpRequest} that has support for {@link ClientHttpRequestInterceptor}s.
|
||||
@@ -86,7 +86,7 @@ class InterceptingClientHttpRequest extends AbstractBufferingClientHttpRequest {
|
||||
delegate.getHeaders().putAll(request.getHeaders());
|
||||
|
||||
if (body.length > 0) {
|
||||
FileCopyUtils.copy(body, delegate.getBody());
|
||||
StreamUtils.copy(body, delegate.getBody());
|
||||
}
|
||||
return delegate.execute();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -39,9 +39,12 @@ final class SimpleBufferingClientHttpRequest extends AbstractBufferingClientHttp
|
||||
|
||||
private final HttpURLConnection connection;
|
||||
|
||||
private final boolean outputStreaming;
|
||||
|
||||
SimpleBufferingClientHttpRequest(HttpURLConnection connection) {
|
||||
|
||||
SimpleBufferingClientHttpRequest(HttpURLConnection connection, boolean outputStreaming) {
|
||||
this.connection = connection;
|
||||
this.outputStreaming = outputStreaming;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +70,7 @@ final class SimpleBufferingClientHttpRequest extends AbstractBufferingClientHttp
|
||||
}
|
||||
}
|
||||
|
||||
if (this.connection.getDoOutput()) {
|
||||
if (this.connection.getDoOutput() && this.outputStreaming) {
|
||||
this.connection.setFixedLengthStreamingMode(bufferedOutput.length);
|
||||
}
|
||||
this.connection.connect();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -50,6 +50,8 @@ public class SimpleClientHttpRequestFactory implements ClientHttpRequestFactory
|
||||
|
||||
private int readTimeout = -1;
|
||||
|
||||
private boolean outputStreaming = true;
|
||||
|
||||
|
||||
/**
|
||||
* Set the {@link Proxy} to use for this request factory.
|
||||
@@ -104,15 +106,31 @@ public class SimpleClientHttpRequestFactory implements ClientHttpRequestFactory
|
||||
this.readTimeout = readTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the underlying URLConnection can be set to 'output streaming' mode. When
|
||||
* output streaming is enabled, authentication and redirection cannot be handled
|
||||
* automatically. If output streaming is disabled the
|
||||
* {@link HttpURLConnection#setFixedLengthStreamingMode(int)
|
||||
* setFixedLengthStreamingMode} and
|
||||
* {@link HttpURLConnection#setChunkedStreamingMode(int) setChunkedStreamingMode}
|
||||
* methods of the underlying connection will never be called.
|
||||
* <p>Default is {@code true}.
|
||||
* @param outputStreaming if output streaming is enabled
|
||||
*/
|
||||
public void setOutputStreaming(boolean outputStreaming) {
|
||||
this.outputStreaming = outputStreaming;
|
||||
}
|
||||
|
||||
|
||||
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
|
||||
HttpURLConnection connection = openConnection(uri.toURL(), this.proxy);
|
||||
prepareConnection(connection, httpMethod.name());
|
||||
if (this.bufferRequestBody) {
|
||||
return new SimpleBufferingClientHttpRequest(connection);
|
||||
return new SimpleBufferingClientHttpRequest(connection, this.outputStreaming);
|
||||
}
|
||||
else {
|
||||
return new SimpleStreamingClientHttpRequest(connection, this.chunkSize);
|
||||
return new SimpleStreamingClientHttpRequest(connection, this.chunkSize,
|
||||
this.outputStreaming);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.http.client;
|
||||
|
||||
import java.io.FilterOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
@@ -27,6 +26,7 @@ import java.util.Map;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
/**
|
||||
* {@link ClientHttpRequest} implementation that uses standard J2SE facilities to execute streaming requests.
|
||||
@@ -44,10 +44,14 @@ final class SimpleStreamingClientHttpRequest extends AbstractClientHttpRequest {
|
||||
|
||||
private OutputStream body;
|
||||
|
||||
private final boolean outputStreaming;
|
||||
|
||||
SimpleStreamingClientHttpRequest(HttpURLConnection connection, int chunkSize) {
|
||||
|
||||
SimpleStreamingClientHttpRequest(HttpURLConnection connection, int chunkSize,
|
||||
boolean outputStreaming) {
|
||||
this.connection = connection;
|
||||
this.chunkSize = chunkSize;
|
||||
this.outputStreaming = outputStreaming;
|
||||
}
|
||||
|
||||
public HttpMethod getMethod() {
|
||||
@@ -66,18 +70,20 @@ final class SimpleStreamingClientHttpRequest extends AbstractClientHttpRequest {
|
||||
@Override
|
||||
protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException {
|
||||
if (this.body == null) {
|
||||
int contentLength = (int) headers.getContentLength();
|
||||
if (contentLength >= 0) {
|
||||
this.connection.setFixedLengthStreamingMode(contentLength);
|
||||
}
|
||||
else {
|
||||
this.connection.setChunkedStreamingMode(this.chunkSize);
|
||||
if(this.outputStreaming) {
|
||||
int contentLength = (int) headers.getContentLength();
|
||||
if (contentLength >= 0) {
|
||||
this.connection.setFixedLengthStreamingMode(contentLength);
|
||||
}
|
||||
else {
|
||||
this.connection.setChunkedStreamingMode(this.chunkSize);
|
||||
}
|
||||
}
|
||||
writeHeaders(headers);
|
||||
this.connection.connect();
|
||||
this.body = this.connection.getOutputStream();
|
||||
}
|
||||
return new NonClosingOutputStream(this.body);
|
||||
return StreamUtils.nonClosing(this.body);
|
||||
}
|
||||
|
||||
private void writeHeaders(HttpHeaders headers) {
|
||||
@@ -106,26 +112,4 @@ final class SimpleStreamingClientHttpRequest extends AbstractClientHttpRequest {
|
||||
return new SimpleClientHttpResponse(this.connection);
|
||||
}
|
||||
|
||||
|
||||
private static class NonClosingOutputStream extends FilterOutputStream {
|
||||
|
||||
private NonClosingOutputStream(OutputStream out) {
|
||||
super(out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] b) throws IOException {
|
||||
super.write(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] b, int off, int let) throws IOException {
|
||||
out.write(b, off, let);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -132,7 +132,7 @@ public class BufferedImageHttpMessageConverter implements HttpMessageConverter<B
|
||||
}
|
||||
|
||||
private boolean isWritable(MediaType mediaType) {
|
||||
if (mediaType == null) {
|
||||
if (mediaType == null || MediaType.ALL.equals(mediaType)) {
|
||||
return true;
|
||||
}
|
||||
Iterator<ImageWriter> imageWriters = ImageIO.getImageWritersByMIMEType(mediaType.toString());
|
||||
@@ -191,7 +191,7 @@ public class BufferedImageHttpMessageConverter implements HttpMessageConverter<B
|
||||
public void write(BufferedImage image, MediaType contentType, HttpOutputMessage outputMessage)
|
||||
throws IOException, HttpMessageNotWritableException {
|
||||
|
||||
if (contentType == null) {
|
||||
if (contentType == null || contentType.isWildcardType() || contentType.isWildcardSubtype()) {
|
||||
contentType = getDefaultContentType();
|
||||
}
|
||||
Assert.notNull(contentType,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -22,7 +22,7 @@ import java.io.IOException;
|
||||
import org.springframework.http.HttpInputMessage;
|
||||
import org.springframework.http.HttpOutputMessage;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
/**
|
||||
* Implementation of {@link HttpMessageConverter} that can read and write byte arrays.
|
||||
@@ -49,14 +49,9 @@ public class ByteArrayHttpMessageConverter extends AbstractHttpMessageConverter<
|
||||
@Override
|
||||
public byte[] readInternal(Class clazz, HttpInputMessage inputMessage) throws IOException {
|
||||
long contentLength = inputMessage.getHeaders().getContentLength();
|
||||
if (contentLength >= 0) {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream((int) contentLength);
|
||||
FileCopyUtils.copy(inputMessage.getBody(), bos);
|
||||
return bos.toByteArray();
|
||||
}
|
||||
else {
|
||||
return FileCopyUtils.copyToByteArray(inputMessage.getBody());
|
||||
}
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(contentLength >= 0 ? (int) contentLength : StreamUtils.BUFFER_SIZE);
|
||||
StreamUtils.copy(inputMessage.getBody(), bos);
|
||||
return bos.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,7 +61,7 @@ public class ByteArrayHttpMessageConverter extends AbstractHttpMessageConverter<
|
||||
|
||||
@Override
|
||||
protected void writeInternal(byte[] bytes, HttpOutputMessage outputMessage) throws IOException {
|
||||
FileCopyUtils.copy(bytes, outputMessage.getBody());
|
||||
StreamUtils.copy(bytes, outputMessage.getBody());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.http.converter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
@@ -37,9 +36,9 @@ import org.springframework.http.HttpInputMessage;
|
||||
import org.springframework.http.HttpOutputMessage;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -170,7 +169,7 @@ public class FormHttpMessageConverter implements HttpMessageConverter<MultiValue
|
||||
|
||||
MediaType contentType = inputMessage.getHeaders().getContentType();
|
||||
Charset charset = contentType.getCharSet() != null ? contentType.getCharSet() : this.charset;
|
||||
String body = FileCopyUtils.copyToString(new InputStreamReader(inputMessage.getBody(), charset));
|
||||
String body = StreamUtils.copyToString(inputMessage.getBody(), charset);
|
||||
|
||||
String[] pairs = StringUtils.tokenizeToStringArray(body, "&");
|
||||
|
||||
@@ -246,7 +245,7 @@ public class FormHttpMessageConverter implements HttpMessageConverter<MultiValue
|
||||
}
|
||||
byte[] bytes = builder.toString().getBytes(charset.name());
|
||||
outputMessage.getHeaders().setContentLength(bytes.length);
|
||||
FileCopyUtils.copy(bytes, outputMessage.getBody());
|
||||
StreamUtils.copy(bytes, outputMessage.getBody());
|
||||
}
|
||||
|
||||
private void writeMultipart(MultiValueMap<String, Object> parts, HttpOutputMessage outputMessage)
|
||||
@@ -265,10 +264,12 @@ public class FormHttpMessageConverter implements HttpMessageConverter<MultiValue
|
||||
for (Map.Entry<String, List<Object>> entry : parts.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
for (Object part : entry.getValue()) {
|
||||
writeBoundary(boundary, os);
|
||||
HttpEntity entity = getEntity(part);
|
||||
writePart(name, entity, os);
|
||||
writeNewLine(os);
|
||||
if (part != null) {
|
||||
writeBoundary(boundary, os);
|
||||
HttpEntity entity = getEntity(part);
|
||||
writePart(name, entity, os);
|
||||
writeNewLine(os);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -18,6 +18,7 @@ package org.springframework.http.converter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.activation.FileTypeMap;
|
||||
import javax.activation.MimetypesFileTypeMap;
|
||||
|
||||
@@ -28,7 +29,7 @@ import org.springframework.http.HttpInputMessage;
|
||||
import org.springframework.http.HttpOutputMessage;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -61,7 +62,7 @@ public class ResourceHttpMessageConverter extends AbstractHttpMessageConverter<R
|
||||
protected Resource readInternal(Class<? extends Resource> clazz, HttpInputMessage inputMessage)
|
||||
throws IOException, HttpMessageNotReadableException {
|
||||
|
||||
byte[] body = FileCopyUtils.copyToByteArray(inputMessage.getBody());
|
||||
byte[] body = StreamUtils.copyToByteArray(inputMessage.getBody());
|
||||
return new ByteArrayResource(body);
|
||||
}
|
||||
|
||||
@@ -84,7 +85,7 @@ public class ResourceHttpMessageConverter extends AbstractHttpMessageConverter<R
|
||||
protected void writeInternal(Resource resource, HttpOutputMessage outputMessage)
|
||||
throws IOException, HttpMessageNotWritableException {
|
||||
|
||||
FileCopyUtils.copy(resource.getInputStream(), outputMessage.getBody());
|
||||
StreamUtils.copy(resource.getInputStream(), outputMessage.getBody());
|
||||
outputMessage.getBody().flush();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -17,8 +17,6 @@
|
||||
package org.springframework.http.converter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
@@ -27,7 +25,7 @@ import java.util.List;
|
||||
import org.springframework.http.HttpInputMessage;
|
||||
import org.springframework.http.HttpOutputMessage;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
/**
|
||||
* Implementation of {@link HttpMessageConverter} that can read and write strings.
|
||||
@@ -84,7 +82,7 @@ public class StringHttpMessageConverter extends AbstractHttpMessageConverter<Str
|
||||
@Override
|
||||
protected String readInternal(Class<? extends String> clazz, HttpInputMessage inputMessage) throws IOException {
|
||||
Charset charset = getContentTypeCharset(inputMessage.getHeaders().getContentType());
|
||||
return FileCopyUtils.copyToString(new InputStreamReader(inputMessage.getBody(), charset));
|
||||
return StreamUtils.copyToString(inputMessage.getBody(), charset);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -105,7 +103,7 @@ public class StringHttpMessageConverter extends AbstractHttpMessageConverter<Str
|
||||
outputMessage.getHeaders().setAcceptCharset(getAcceptedCharsets());
|
||||
}
|
||||
Charset charset = getContentTypeCharset(outputMessage.getHeaders().getContentType());
|
||||
FileCopyUtils.copy(s, new OutputStreamWriter(outputMessage.getBody(), charset));
|
||||
StreamUtils.copy(s, charset, outputMessage.getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,5 +43,4 @@ public class RssChannelHttpMessageConverter extends AbstractWireFeedHttpMessageC
|
||||
return Channel.class.isAssignableFrom(clazz);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -18,6 +18,7 @@ package org.springframework.web.accept;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
@@ -55,6 +56,7 @@ public class ContentNegotiationManager implements ContentNegotiationStrategy, Me
|
||||
private final Set<MediaTypeFileExtensionResolver> fileExtensionResolvers =
|
||||
new LinkedHashSet<MediaTypeFileExtensionResolver>();
|
||||
|
||||
|
||||
/**
|
||||
* Create an instance with the given ContentNegotiationStrategy instances.
|
||||
* <p>Each instance is checked to see if it is also an implementation of
|
||||
@@ -72,12 +74,29 @@ public class ContentNegotiationManager implements ContentNegotiationStrategy, Me
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance with a {@link HeaderContentNegotiationStrategy}.
|
||||
* Create an instance with the given ContentNegotiationStrategy instances.
|
||||
* <p>Each instance is checked to see if it is also an implementation of
|
||||
* MediaTypeFileExtensionResolver, and if so it is registered as such.
|
||||
* @param strategies one more more ContentNegotiationStrategy instances
|
||||
*/
|
||||
public ContentNegotiationManager(Collection<ContentNegotiationStrategy> strategies) {
|
||||
Assert.notEmpty(strategies, "At least one ContentNegotiationStrategy is expected");
|
||||
this.contentNegotiationStrategies.addAll(strategies);
|
||||
for (ContentNegotiationStrategy strategy : this.contentNegotiationStrategies) {
|
||||
if (strategy instanceof MediaTypeFileExtensionResolver) {
|
||||
this.fileExtensionResolvers.add((MediaTypeFileExtensionResolver) strategy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a default instance with a {@link HeaderContentNegotiationStrategy}.
|
||||
*/
|
||||
public ContentNegotiationManager() {
|
||||
this(new HeaderContentNegotiationStrategy());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add MediaTypeFileExtensionResolver instances.
|
||||
* <p>Note that some {@link ContentNegotiationStrategy} implementations also
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.accept;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -22,7 +23,6 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
@@ -39,13 +39,13 @@ import org.springframework.web.context.ServletContextAware;
|
||||
* <p>By default strategies for checking the extension of the request path and
|
||||
* the {@code Accept} header are registered. The path extension check will perform
|
||||
* lookups through the {@link ServletContext} and the Java Activation Framework
|
||||
* (if present) unless {@linkplain #setMediaTypes(Properties) media types} are configured.
|
||||
* (if present) unless {@linkplain #setMediaTypes media types} are configured.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 3.2
|
||||
*/
|
||||
public class ContentNegotiationManagerFactoryBean
|
||||
implements FactoryBean<ContentNegotiationManager>, InitializingBean, ServletContextAware {
|
||||
implements FactoryBean<ContentNegotiationManager>, ServletContextAware, InitializingBean {
|
||||
|
||||
private boolean favorPathExtension = true;
|
||||
|
||||
@@ -65,6 +65,7 @@ public class ContentNegotiationManagerFactoryBean
|
||||
|
||||
private ServletContext servletContext;
|
||||
|
||||
|
||||
/**
|
||||
* Indicate whether the extension of the request path should be used to determine
|
||||
* the requested media type with the <em>highest priority</em>.
|
||||
@@ -81,7 +82,6 @@ public class ContentNegotiationManagerFactoryBean
|
||||
* <p>When this mapping is not set or when an extension is not found, the Java
|
||||
* Action Framework, if available, may be used if enabled via
|
||||
* {@link #setFavorPathExtension(boolean)}.
|
||||
*
|
||||
* @see #addMediaType(String, MediaType)
|
||||
* @see #addMediaTypes(Map)
|
||||
*/
|
||||
@@ -121,9 +121,8 @@ public class ContentNegotiationManagerFactoryBean
|
||||
* to map from file extensions to media types. This is used only when
|
||||
* {@link #setFavorPathExtension(boolean)} is set to {@code true}.
|
||||
* <p>The default value is {@code true}.
|
||||
*
|
||||
* @see #parameterName
|
||||
* @see #setMediaTypes(Properties)
|
||||
* @see #setParameterName
|
||||
* @see #setMediaTypes
|
||||
*/
|
||||
public void setUseJaf(boolean useJaf) {
|
||||
this.useJaf = useJaf;
|
||||
@@ -138,8 +137,7 @@ public class ContentNegotiationManagerFactoryBean
|
||||
* {@code "application/pdf"} regardless of the {@code Accept} header.
|
||||
* <p>To use this option effectively you must also configure the MediaType
|
||||
* type mappings via {@link #setMediaTypes(Properties)}.
|
||||
*
|
||||
* @see #setParameterName(String)
|
||||
* @see #setParameterName
|
||||
*/
|
||||
public void setFavorParameter(boolean favorParameter) {
|
||||
this.favorParameter = favorParameter;
|
||||
@@ -180,7 +178,8 @@ public class ContentNegotiationManagerFactoryBean
|
||||
this.servletContext = servletContext;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
|
||||
public void afterPropertiesSet() {
|
||||
List<ContentNegotiationStrategy> strategies = new ArrayList<ContentNegotiationStrategy>();
|
||||
|
||||
if (this.favorPathExtension) {
|
||||
@@ -210,8 +209,12 @@ public class ContentNegotiationManagerFactoryBean
|
||||
strategies.add(new FixedContentNegotiationStrategy(this.defaultContentType));
|
||||
}
|
||||
|
||||
ContentNegotiationStrategy[] array = strategies.toArray(new ContentNegotiationStrategy[strategies.size()]);
|
||||
this.contentNegotiationManager = new ContentNegotiationManager(array);
|
||||
this.contentNegotiationManager = new ContentNegotiationManager(strategies);
|
||||
}
|
||||
|
||||
|
||||
public ContentNegotiationManager getObject() {
|
||||
return this.contentNegotiationManager;
|
||||
}
|
||||
|
||||
public Class<?> getObjectType() {
|
||||
@@ -222,8 +225,4 @@ public class ContentNegotiationManagerFactoryBean
|
||||
return true;
|
||||
}
|
||||
|
||||
public ContentNegotiationManager getObject() throws Exception {
|
||||
return this.contentNegotiationManager;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -55,14 +55,14 @@ public @interface CookieValue {
|
||||
* in case the header is missing in the request. Switch this to
|
||||
* {@code false} if you prefer a {@code null} in case of the
|
||||
* missing header.
|
||||
* <p>Alternatively, provide a {@link #defaultValue() defaultValue},
|
||||
* which implicitly sets this flag to {@code false}.
|
||||
* <p>Alternatively, provide a {@link #defaultValue}, which implicitly sets
|
||||
* this flag to {@code false}.
|
||||
*/
|
||||
boolean required() default true;
|
||||
|
||||
/**
|
||||
* The default value to use as a fallback. Supplying a default value implicitly
|
||||
* sets {@link #required()} to false.
|
||||
* sets {@link #required} to {@code false}.
|
||||
*/
|
||||
String defaultValue() default ValueConstants.DEFAULT_NONE;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -49,14 +49,14 @@ public @interface RequestHeader {
|
||||
* <p>Default is {@code true}, leading to an exception thrown in case
|
||||
* of the header missing in the request. Switch this to {@code false}
|
||||
* if you prefer a {@code null} in case of the header missing.
|
||||
* <p>Alternatively, provide a {@link #defaultValue() defaultValue},
|
||||
* which implicitely sets this flag to {@code false}.
|
||||
* <p>Alternatively, provide a {@link #defaultValue}, which implicitly sets
|
||||
* this flag to {@code false}.
|
||||
*/
|
||||
boolean required() default true;
|
||||
|
||||
/**
|
||||
* The default value to use as a fallback. Supplying a default value implicitely
|
||||
* sets {@link #required()} to false.
|
||||
* The default value to use as a fallback. Supplying a default value implicitly
|
||||
* sets {@link #required} to {@code false}.
|
||||
*/
|
||||
String defaultValue() default ValueConstants.DEFAULT_NONE;
|
||||
|
||||
|
||||
@@ -266,6 +266,7 @@ public @interface RequestMapping {
|
||||
* Ant-style path patterns are also supported (e.g. "/myPath/*.do").
|
||||
* At the method level, relative paths (e.g. "edit.do") are supported
|
||||
* within the primary mapping expressed at the type level.
|
||||
* Path mapping URIs may contain placeholders (e.g. "/${connect}")
|
||||
* <p>In a Portlet environment: the mapped portlet modes
|
||||
* (i.e. "EDIT", "VIEW", "HELP" or any custom modes).
|
||||
* <p><b>Supported at the type level as well as at the method level!</b>
|
||||
|
||||
@@ -68,8 +68,9 @@ public @interface RequestParam {
|
||||
boolean required() default true;
|
||||
|
||||
/**
|
||||
* The default value to use as a fallback. Supplying a default value implicitly
|
||||
* sets {@link #required()} to false.
|
||||
* The default value to use as a fallback when the request parameter value
|
||||
* is not provided or empty. Supplying a default value implicitly sets
|
||||
* {@link #required()} to false.
|
||||
*/
|
||||
String defaultValue() default ValueConstants.DEFAULT_NONE;
|
||||
|
||||
|
||||
@@ -36,4 +36,4 @@ import java.lang.annotation.Target;
|
||||
@Documented
|
||||
public @interface ResponseBody {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,4 +37,4 @@ public interface WebDataBinderFactory {
|
||||
*/
|
||||
WebDataBinder createBinder(NativeWebRequest webRequest, Object target, String objectName) throws Exception;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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,11 +71,6 @@ public interface ConfigurableWebApplicationContext extends WebApplicationContext
|
||||
*/
|
||||
ServletConfig getServletConfig();
|
||||
|
||||
/**
|
||||
* Return the {@link ConfigurableWebEnvironment} used by this web application context.
|
||||
*/
|
||||
ConfigurableWebEnvironment getEnvironment();
|
||||
|
||||
/**
|
||||
* Set the namespace for this web application context,
|
||||
* to be used for building a default context config location.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -23,11 +23,11 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.access.BeanFactoryLocator;
|
||||
import org.springframework.beans.factory.access.BeanFactoryReference;
|
||||
@@ -38,6 +38,7 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.access.ContextSingletonBeanFactoryLocator;
|
||||
import org.springframework.core.GenericTypeResolver;
|
||||
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.support.PropertiesLoaderUtils;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -280,7 +281,18 @@ public class ContextLoader {
|
||||
this.context = createWebApplicationContext(servletContext);
|
||||
}
|
||||
if (this.context instanceof ConfigurableWebApplicationContext) {
|
||||
configureAndRefreshWebApplicationContext((ConfigurableWebApplicationContext)this.context, servletContext);
|
||||
ConfigurableWebApplicationContext cwac = (ConfigurableWebApplicationContext) this.context;
|
||||
if (!cwac.isActive()) {
|
||||
// The context has not yet been refreshed -> provide services such as
|
||||
// setting the parent context, setting the application context id, etc
|
||||
if (cwac.getParent() == null) {
|
||||
// The context instance was injected without an explicit parent ->
|
||||
// determine parent for root web application context, if any.
|
||||
ApplicationContext parent = loadParentContext(servletContext);
|
||||
cwac.setParent(parent);
|
||||
}
|
||||
configureAndRefreshWebApplicationContext(cwac, servletContext);
|
||||
}
|
||||
}
|
||||
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context);
|
||||
|
||||
@@ -333,9 +345,7 @@ public class ContextLoader {
|
||||
throw new ApplicationContextException("Custom context class [" + contextClass.getName() +
|
||||
"] is not of type [" + ConfigurableWebApplicationContext.class.getName() + "]");
|
||||
}
|
||||
ConfigurableWebApplicationContext wac =
|
||||
(ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass);
|
||||
return wac;
|
||||
return (ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -370,10 +380,6 @@ public class ContextLoader {
|
||||
}
|
||||
}
|
||||
|
||||
// Determine parent for root web application context, if any.
|
||||
ApplicationContext parent = loadParentContext(sc);
|
||||
|
||||
wac.setParent(parent);
|
||||
wac.setServletContext(sc);
|
||||
String initParameter = sc.getInitParameter(CONFIG_LOCATION_PARAM);
|
||||
if (initParameter != null) {
|
||||
@@ -472,11 +478,11 @@ public class ContextLoader {
|
||||
|
||||
Class<?> contextClass = applicationContext.getClass();
|
||||
ArrayList<ApplicationContextInitializer<ConfigurableApplicationContext>> initializerInstances =
|
||||
new ArrayList<ApplicationContextInitializer<ConfigurableApplicationContext>>();
|
||||
new ArrayList<ApplicationContextInitializer<ConfigurableApplicationContext>>();
|
||||
|
||||
for (Class<ApplicationContextInitializer<ConfigurableApplicationContext>> initializerClass : initializerClasses) {
|
||||
Class<?> initializerContextClass =
|
||||
GenericTypeResolver.resolveTypeArgument(initializerClass, ApplicationContextInitializer.class);
|
||||
GenericTypeResolver.resolveTypeArgument(initializerClass, ApplicationContextInitializer.class);
|
||||
Assert.isAssignable(initializerContextClass, contextClass, String.format(
|
||||
"Could not add context initializer [%s] as its generic parameter [%s] " +
|
||||
"is not assignable from the type of application context used by this " +
|
||||
@@ -485,7 +491,10 @@ public class ContextLoader {
|
||||
initializerInstances.add(BeanUtils.instantiateClass(initializerClass));
|
||||
}
|
||||
|
||||
applicationContext.getEnvironment().initPropertySources(servletContext, null);
|
||||
ConfigurableEnvironment env = applicationContext.getEnvironment();
|
||||
if (env instanceof ConfigurableWebEnvironment) {
|
||||
((ConfigurableWebEnvironment)env).initPropertySources(servletContext, null);
|
||||
}
|
||||
|
||||
Collections.sort(initializerInstances, new AnnotationAwareOrderComparator());
|
||||
for (ApplicationContextInitializer<ConfigurableApplicationContext> initializer : initializerInstances) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -32,13 +32,13 @@ import org.springframework.web.context.request.NativeWebRequest;
|
||||
* <p>Subclasses can extend this class to easily associate additional data or
|
||||
* behavior with the {@link DeferredResult}. For example, one might want to
|
||||
* associate the user used to create the {@link DeferredResult} by extending the
|
||||
* class and adding an addition property for the user. In this way, the user
|
||||
* class and adding an additional property for the user. In this way, the user
|
||||
* could easily be accessed later without the need to use a data structure to do
|
||||
* the mapping.
|
||||
*
|
||||
* <p>An example of associating additional behavior to this class might be
|
||||
* realized by extending the class to implement an additional interface. For
|
||||
* example, one might want to implement a {@link Comparable} so that when the
|
||||
* example, one might want to implement {@link Comparable} so that when the
|
||||
* {@link DeferredResult} is added to a {@link PriorityQueue} it is handled in
|
||||
* the correct order.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -37,9 +37,9 @@ import org.springframework.web.util.UrlPathHelper;
|
||||
* as an SPI and not typically used directly by application classes.
|
||||
*
|
||||
* <p>An async scenario starts with request processing as usual in a thread (T1).
|
||||
* Concurrent request handling can be innitiated by calling
|
||||
* {@linkplain #startCallableProcessing(Callable, Object...) startCallableProcessing} or
|
||||
* {@linkplain #startDeferredResultProcessing(DeferredResult, Object...) startDeferredResultProcessing}
|
||||
* Concurrent request handling can be initiated by calling
|
||||
* {@link #startCallableProcessing(Callable, Object...) startCallableProcessing} or
|
||||
* {@link #startDeferredResultProcessing(DeferredResult, Object...) startDeferredResultProcessing},
|
||||
* both of which produce a result in a separate thread (T2). The result is saved
|
||||
* and the request dispatched to the container, to resume processing with the saved
|
||||
* result in a third thread (T3). Within the dispatched thread (T3), the saved
|
||||
@@ -263,7 +263,7 @@ public final class WebAsyncManager {
|
||||
* the timeout value of the {@code AsyncWebRequest} before delegating to
|
||||
* {@link #startCallableProcessing(Callable, Object...)}.
|
||||
*
|
||||
* @param webAsyncTask an WebAsyncTask containing the target {@code Callable}
|
||||
* @param webAsyncTask a WebAsyncTask containing the target {@code Callable}
|
||||
* @param processingContext additional context to save that can be accessed
|
||||
* via {@link #getConcurrentResultContext()}
|
||||
* @throws Exception If concurrent processing failed to start
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -46,7 +46,7 @@ public class WebAsyncTask<V> {
|
||||
|
||||
|
||||
/**
|
||||
* Create an {@code WebAsyncTask} wrapping the given {@link Callable}.
|
||||
* Create a {@code WebAsyncTask} wrapping the given {@link Callable}.
|
||||
* @param callable the callable for concurrent handling
|
||||
*/
|
||||
public WebAsyncTask(Callable<V> callable) {
|
||||
@@ -54,7 +54,7 @@ public class WebAsyncTask<V> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an {@code WebAsyncTask} with a timeout value and a {@link Callable}.
|
||||
* Create a {@code WebAsyncTask} with a timeout value and a {@link Callable}.
|
||||
* @param timeout timeout value in milliseconds
|
||||
* @param callable the callable for concurrent handling
|
||||
*/
|
||||
@@ -63,7 +63,7 @@ public class WebAsyncTask<V> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an {@code WebAsyncTask} with a timeout value, an executor name, and a {@link Callable}.
|
||||
* Create a {@code WebAsyncTask} with a timeout value, an executor name, and a {@link Callable}.
|
||||
* @param timeout timeout value in milliseconds; ignored if {@code null}
|
||||
* @param callable the callable for concurrent handling
|
||||
*/
|
||||
@@ -73,7 +73,7 @@ public class WebAsyncTask<V> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an {@code WebAsyncTask} with a timeout value, an executor instance, and a Callable.
|
||||
* Create a {@code WebAsyncTask} with a timeout value, an executor instance, and a Callable.
|
||||
* @param timeout timeout value in milliseconds; ignored if {@code null}
|
||||
* @param callable the callable for concurrent handling
|
||||
*/
|
||||
@@ -113,7 +113,7 @@ public class WebAsyncTask<V> {
|
||||
return this.executor;
|
||||
}
|
||||
else if (this.executorName != null) {
|
||||
Assert.state(this.beanFactory != null, "A BeanFactory is required to look up an task executor bean");
|
||||
Assert.state(this.beanFactory != null, "A BeanFactory is required to look up a task executor bean");
|
||||
return this.beanFactory.getBean(this.executorName, AsyncTaskExecutor.class);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -27,7 +27,6 @@ import org.springframework.core.io.support.ResourcePatternResolver;
|
||||
import org.springframework.ui.context.Theme;
|
||||
import org.springframework.ui.context.ThemeSource;
|
||||
import org.springframework.ui.context.support.UiApplicationContextUtils;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.context.ConfigurableWebApplicationContext;
|
||||
import org.springframework.web.context.ConfigurableWebEnvironment;
|
||||
import org.springframework.web.context.ServletConfigAware;
|
||||
@@ -157,15 +156,6 @@ public abstract class AbstractRefreshableWebApplicationContext extends AbstractR
|
||||
return new StandardServletEnvironment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigurableWebEnvironment getEnvironment() {
|
||||
ConfigurableEnvironment env = super.getEnvironment();
|
||||
Assert.isInstanceOf(ConfigurableWebEnvironment.class, env,
|
||||
"ConfigurableWebApplicationContext environment must be of type " +
|
||||
"ConfigurableWebEnvironment");
|
||||
return (ConfigurableWebEnvironment) env;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register request/session scopes, a {@link ServletContextAwareProcessor}, etc.
|
||||
*/
|
||||
@@ -212,7 +202,11 @@ public abstract class AbstractRefreshableWebApplicationContext extends AbstractR
|
||||
@Override
|
||||
protected void initPropertySources() {
|
||||
super.initPropertySources();
|
||||
this.getEnvironment().initPropertySources(this.servletContext, this.servletConfig);
|
||||
ConfigurableEnvironment env = this.getEnvironment();
|
||||
if (env instanceof ConfigurableWebEnvironment) {
|
||||
((ConfigurableWebEnvironment)env).initPropertySources(
|
||||
this.servletContext, this.servletConfig);
|
||||
}
|
||||
}
|
||||
|
||||
public Theme getTheme(String themeName) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -147,15 +147,6 @@ public class GenericWebApplicationContext extends GenericApplicationContext
|
||||
return new StandardServletEnvironment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigurableWebEnvironment getEnvironment() {
|
||||
ConfigurableEnvironment env = super.getEnvironment();
|
||||
Assert.isInstanceOf(ConfigurableWebEnvironment.class, env,
|
||||
"ConfigurableWebApplicationContext environment must be of type " +
|
||||
"ConfigurableWebEnvironment");
|
||||
return (ConfigurableWebEnvironment) env;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register ServletContextAwareProcessor.
|
||||
* @see ServletContextAwareProcessor
|
||||
@@ -202,7 +193,11 @@ public class GenericWebApplicationContext extends GenericApplicationContext
|
||||
@Override
|
||||
protected void initPropertySources() {
|
||||
super.initPropertySources();
|
||||
this.getEnvironment().initPropertySources(this.servletContext, null);
|
||||
ConfigurableEnvironment env = this.getEnvironment();
|
||||
if (env instanceof ConfigurableWebEnvironment) {
|
||||
((ConfigurableWebEnvironment)env).initPropertySources(
|
||||
this.servletContext, null);
|
||||
}
|
||||
}
|
||||
|
||||
public Theme getTheme(String themeName) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -27,9 +27,7 @@ import org.springframework.core.io.support.ResourcePatternResolver;
|
||||
import org.springframework.ui.context.Theme;
|
||||
import org.springframework.ui.context.ThemeSource;
|
||||
import org.springframework.ui.context.support.UiApplicationContextUtils;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.context.ConfigurableWebApplicationContext;
|
||||
import org.springframework.web.context.ConfigurableWebEnvironment;
|
||||
import org.springframework.web.context.ServletConfigAware;
|
||||
import org.springframework.web.context.ServletContextAware;
|
||||
|
||||
@@ -169,15 +167,6 @@ public class StaticWebApplicationContext extends StaticApplicationContext
|
||||
return new StandardServletEnvironment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigurableWebEnvironment getEnvironment() {
|
||||
ConfigurableEnvironment env = super.getEnvironment();
|
||||
Assert.isInstanceOf(ConfigurableWebEnvironment.class, env,
|
||||
"ConfigurableWebApplication environment must be of type " +
|
||||
"ConfigurableWebEnvironment");
|
||||
return (ConfigurableWebEnvironment) env;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the theme capability.
|
||||
*/
|
||||
|
||||
@@ -69,4 +69,4 @@ public abstract class HandlerMethodSelector {
|
||||
return handlerMethods;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,4 +71,4 @@ public abstract class AbstractCookieValueMethodArgumentResolver extends Abstract
|
||||
super(annotation.value(), annotation.required(), annotation.defaultValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,6 +92,9 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
|
||||
}
|
||||
arg = handleNullValue(namedValueInfo.name, arg, paramType);
|
||||
}
|
||||
else if ("".equals(arg) && (namedValueInfo.defaultValue != null)) {
|
||||
arg = resolveDefaultValue(namedValueInfo.defaultValue);
|
||||
}
|
||||
|
||||
if (binderFactory != null) {
|
||||
WebDataBinder binder = binderFactory.createBinder(webRequest, null, namedValueInfo.name);
|
||||
|
||||
@@ -76,4 +76,4 @@ public class ExpressionValueMethodArgumentResolver extends AbstractNamedValueMet
|
||||
super("@Value", false, annotation.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,4 +243,4 @@ public final class ModelFactory {
|
||||
!(value instanceof Map) && !BeanUtils.isSimpleValueType(value.getClass()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,4 +87,4 @@ public class RequestHeaderMethodArgumentResolver extends AbstractNamedValueMetho
|
||||
super(annotation.value(), annotation.required(), annotation.defaultValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,4 +212,4 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
|
||||
super(annotation.value(), annotation.required(), annotation.defaultValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,4 +62,4 @@ public interface HandlerMethodArgumentResolver {
|
||||
NativeWebRequest webRequest,
|
||||
WebDataBinderFactory binderFactory) throws Exception;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,4 +58,4 @@ public interface HandlerMethodReturnValueHandler {
|
||||
ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest) throws Exception;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.web.util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
@@ -38,9 +39,11 @@ import org.springframework.util.StringUtils;
|
||||
* Extension of {@link UriComponents} for hierarchical URIs.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Phillip Webb
|
||||
* @since 3.1.3
|
||||
* @see <a href="http://tools.ietf.org/html/rfc3986#section-1.2.3">Hierarchical URIs</a>
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
final class HierarchicalUriComponents extends UriComponents {
|
||||
|
||||
private static final char PATH_DELIMITER = '/';
|
||||
@@ -405,7 +408,10 @@ final class HierarchicalUriComponents extends UriComponents {
|
||||
else {
|
||||
String path = getPath();
|
||||
if (StringUtils.hasLength(path) && path.charAt(0) != PATH_DELIMITER) {
|
||||
path = PATH_DELIMITER + path;
|
||||
// Only prefix the path delimiter if something exists before it
|
||||
if(getScheme() != null || getUserInfo() != null || getHost() != null || getPort() != -1) {
|
||||
path = PATH_DELIMITER + path;
|
||||
}
|
||||
}
|
||||
return new URI(getScheme(), getUserInfo(), getHost(), getPort(), path, getQuery(),
|
||||
getFragment());
|
||||
@@ -425,28 +431,15 @@ final class HierarchicalUriComponents extends UriComponents {
|
||||
return false;
|
||||
}
|
||||
HierarchicalUriComponents other = (HierarchicalUriComponents) obj;
|
||||
if (ObjectUtils.nullSafeEquals(getScheme(), other.getScheme())) {
|
||||
return false;
|
||||
}
|
||||
if (ObjectUtils.nullSafeEquals(getUserInfo(), other.getUserInfo())) {
|
||||
return false;
|
||||
}
|
||||
if (ObjectUtils.nullSafeEquals(getHost(), other.getHost())) {
|
||||
return false;
|
||||
}
|
||||
if (this.port != other.port) {
|
||||
return false;
|
||||
}
|
||||
if (!this.path.equals(other.path)) {
|
||||
return false;
|
||||
}
|
||||
if (!this.queryParams.equals(other.queryParams)) {
|
||||
return false;
|
||||
}
|
||||
if (ObjectUtils.nullSafeEquals(getFragment(), other.getFragment())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
boolean rtn = true;
|
||||
rtn &= ObjectUtils.nullSafeEquals(getScheme(), other.getScheme());
|
||||
rtn &= ObjectUtils.nullSafeEquals(getUserInfo(), other.getUserInfo());
|
||||
rtn &= ObjectUtils.nullSafeEquals(getHost(), other.getHost());
|
||||
rtn &= getPort() == other.getPort();
|
||||
rtn &= this.path.equals(other.path);
|
||||
rtn &= this.queryParams.equals(other.queryParams);
|
||||
rtn &= ObjectUtils.nullSafeEquals(getFragment(), other.getFragment());
|
||||
return rtn;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -614,7 +607,7 @@ final class HierarchicalUriComponents extends UriComponents {
|
||||
/**
|
||||
* Defines the contract for path (segments).
|
||||
*/
|
||||
interface PathComponent {
|
||||
interface PathComponent extends Serializable {
|
||||
|
||||
String getPath();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -21,21 +21,21 @@ package org.springframework.web.util;
|
||||
* Escapes based on the JavaScript 1.5 recommendation.
|
||||
*
|
||||
* <p>Reference:
|
||||
* <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Literals#String_Literals">
|
||||
* Core JavaScript 1.5 Guide
|
||||
* </a>
|
||||
* <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Values,_variables,_and_literals#String_literals">
|
||||
* JavaScript Guide</a> on Mozilla Developer Network.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Rob Harrop
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 1.1.1
|
||||
*/
|
||||
public class JavaScriptUtils {
|
||||
|
||||
/**
|
||||
* Turn special characters into escaped characters conforming to JavaScript.
|
||||
* Handles complete character set defined in HTML 4.01 recommendation.
|
||||
* Turn JavaScript special characters into escaped characters.
|
||||
*
|
||||
* @param input the input string
|
||||
* @return the escaped string
|
||||
* @return the string with escaped characters
|
||||
*/
|
||||
public static String javaScriptEscape(String input) {
|
||||
if (input == null) {
|
||||
@@ -73,6 +73,27 @@ public class JavaScriptUtils {
|
||||
else if (c == '\f') {
|
||||
filtered.append("\\f");
|
||||
}
|
||||
else if (c == '\b') {
|
||||
filtered.append("\\b");
|
||||
}
|
||||
// No '\v' in Java, use octal value for VT ascii char
|
||||
else if (c == '\013') {
|
||||
filtered.append("\\v");
|
||||
}
|
||||
else if (c == '<') {
|
||||
filtered.append("\\u003C");
|
||||
}
|
||||
else if (c == '>') {
|
||||
filtered.append("\\u003E");
|
||||
}
|
||||
// Unicode for PS (line terminator in ECMA-262)
|
||||
else if (c == '\u2028') {
|
||||
filtered.append("\\u2028");
|
||||
}
|
||||
// Unicode for LS (line terminator in ECMA-262)
|
||||
else if (c == '\u2029') {
|
||||
filtered.append("\\u2029");
|
||||
}
|
||||
else {
|
||||
filtered.append(c);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -17,12 +17,10 @@
|
||||
package org.springframework.web.util;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.springframework.util.Log4jConfigurer;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.util.SystemPropertyUtils;
|
||||
|
||||
/**
|
||||
* Convenience class that performs custom log4j initialization for web environments,
|
||||
@@ -90,6 +88,7 @@ import org.springframework.util.SystemPropertyUtils;
|
||||
* context-param at all) without worrying.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Marten Deinum
|
||||
* @since 12.08.2003
|
||||
* @see org.springframework.util.Log4jConfigurer
|
||||
* @see Log4jConfigListener
|
||||
@@ -122,9 +121,8 @@ public abstract class Log4jWebConfigurer {
|
||||
if (location != null) {
|
||||
// Perform actual log4j initialization; else rely on log4j's default initialization.
|
||||
try {
|
||||
// Resolve system property placeholders before potentially
|
||||
// resolving a real path.
|
||||
location = SystemPropertyUtils.resolvePlaceholders(location);
|
||||
// Resolve property placeholders before potentially resolving a real path.
|
||||
location = ServletContextPropertyUtils.resolvePlaceholders(location, servletContext);
|
||||
|
||||
// Leave a URL (e.g. "classpath:" or "file:") as-is.
|
||||
if (!ResourceUtils.isUrl(location)) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -30,9 +30,11 @@ import org.springframework.util.ObjectUtils;
|
||||
* Extension of {@link UriComponents} for opaque URIs.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Phillip Webb
|
||||
* @since 3.2
|
||||
* @see <a href="http://tools.ietf.org/html/rfc3986#section-1.2.3">Hierarchical vs Opaque URIs</a>
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
final class OpaqueUriComponents extends UriComponents {
|
||||
|
||||
private static final MultiValueMap<String, String> QUERY_PARAMS_NONE = new LinkedMultiValueMap<String, String>(0);
|
||||
@@ -144,18 +146,11 @@ final class OpaqueUriComponents extends UriComponents {
|
||||
}
|
||||
|
||||
OpaqueUriComponents other = (OpaqueUriComponents) obj;
|
||||
|
||||
if (ObjectUtils.nullSafeEquals(getScheme(), other.getScheme())) {
|
||||
return false;
|
||||
}
|
||||
if (ObjectUtils.nullSafeEquals(this.ssp, other.ssp)) {
|
||||
return false;
|
||||
}
|
||||
if (ObjectUtils.nullSafeEquals(getFragment(), other.getFragment())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
boolean rtn = true;
|
||||
rtn &= ObjectUtils.nullSafeEquals(getScheme(), other.getScheme());
|
||||
rtn &= ObjectUtils.nullSafeEquals(this.ssp, other.ssp);
|
||||
rtn &= ObjectUtils.nullSafeEquals(getFragment(), other.getFragment());
|
||||
return rtn;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright 2002-2013 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
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.web.util;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.springframework.util.PropertyPlaceholderHelper;
|
||||
import org.springframework.util.SystemPropertyUtils;
|
||||
|
||||
/**
|
||||
* Helper class for resolving placeholders in texts. Usually applied to file paths.
|
||||
*
|
||||
* <p>A text may contain {@code ${...}} placeholders, to be resolved as servlet context
|
||||
* init parameters or system properties: e.g. {@code ${user.dir}}. Default values can
|
||||
* be supplied using the ":" separator between key and value.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Marten Deinum
|
||||
* @since 3.2.2
|
||||
* @see SystemPropertyUtils
|
||||
* @see ServletContext#getInitParameter(String)
|
||||
*/
|
||||
public abstract class ServletContextPropertyUtils {
|
||||
|
||||
private static final PropertyPlaceholderHelper strictHelper =
|
||||
new PropertyPlaceholderHelper(SystemPropertyUtils.PLACEHOLDER_PREFIX,
|
||||
SystemPropertyUtils.PLACEHOLDER_SUFFIX, SystemPropertyUtils.VALUE_SEPARATOR, false);
|
||||
|
||||
private static final PropertyPlaceholderHelper nonStrictHelper =
|
||||
new PropertyPlaceholderHelper(SystemPropertyUtils.PLACEHOLDER_PREFIX,
|
||||
SystemPropertyUtils.PLACEHOLDER_SUFFIX, SystemPropertyUtils.VALUE_SEPARATOR, true);
|
||||
|
||||
|
||||
/**
|
||||
* Resolve ${...} placeholders in the given text, replacing them with corresponding
|
||||
* servlet context init parameter or system property values.
|
||||
* @param text the String to resolve
|
||||
* @param servletContext the servletContext to use for lookups.
|
||||
* @return the resolved String
|
||||
* @see SystemPropertyUtils#PLACEHOLDER_PREFIX
|
||||
* @see SystemPropertyUtils#PLACEHOLDER_SUFFIX
|
||||
* @see SystemPropertyUtils#resolvePlaceholders(String, boolean)
|
||||
* @throws IllegalArgumentException if there is an unresolvable placeholder
|
||||
*/
|
||||
public static String resolvePlaceholders(String text, ServletContext servletContext) {
|
||||
return resolvePlaceholders(text, servletContext, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve ${...} placeholders in the given text, replacing them with corresponding
|
||||
* servlet context init parameter or system property values. Unresolvable placeholders
|
||||
* with no default value are ignored and passed through unchanged if the flag is set to true.
|
||||
* @param text the String to resolve
|
||||
* @param servletContext the servletContext to use for lookups.
|
||||
* @param ignoreUnresolvablePlaceholders flag to determine is unresolved placeholders are ignored
|
||||
* @return the resolved String
|
||||
* @see SystemPropertyUtils#PLACEHOLDER_PREFIX
|
||||
* @see SystemPropertyUtils#PLACEHOLDER_SUFFIX
|
||||
* @see SystemPropertyUtils#resolvePlaceholders(String, boolean)
|
||||
* @throws IllegalArgumentException if there is an unresolvable placeholder and the flag is false
|
||||
*/
|
||||
public static String resolvePlaceholders(String text, ServletContext servletContext, boolean ignoreUnresolvablePlaceholders) {
|
||||
PropertyPlaceholderHelper helper = (ignoreUnresolvablePlaceholders ? nonStrictHelper : strictHelper);
|
||||
return helper.replacePlaceholders(text, new ServletContextPlaceholderResolver(text, servletContext));
|
||||
}
|
||||
|
||||
|
||||
private static class ServletContextPlaceholderResolver implements PropertyPlaceholderHelper.PlaceholderResolver {
|
||||
|
||||
private final String text;
|
||||
|
||||
private final ServletContext servletContext;
|
||||
|
||||
public ServletContextPlaceholderResolver(String text, ServletContext servletContext) {
|
||||
this.text = text;
|
||||
this.servletContext = servletContext;
|
||||
}
|
||||
|
||||
public String resolvePlaceholder(String placeholderName) {
|
||||
try {
|
||||
String propVal = this.servletContext.getInitParameter(placeholderName);
|
||||
if (propVal == null) {
|
||||
// Fall back to system properties.
|
||||
propVal = System.getProperty(placeholderName);
|
||||
if (propVal == null) {
|
||||
// Fall back to searching the system environment.
|
||||
propVal = System.getenv(placeholderName);
|
||||
}
|
||||
}
|
||||
return propVal;
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
System.err.println("Could not resolve placeholder '" + placeholderName + "' in [" +
|
||||
this.text + "] as ServletContext init-parameter or system property: " + ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.web.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
@@ -38,7 +39,7 @@ import org.springframework.util.MultiValueMap;
|
||||
* @since 3.1
|
||||
* @see UriComponentsBuilder
|
||||
*/
|
||||
public abstract class UriComponents {
|
||||
public abstract class UriComponents implements Serializable {
|
||||
|
||||
private static final String DEFAULT_ENCODING = "UTF-8";
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -18,7 +18,7 @@ package org.springframework.web.util;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -29,6 +29,7 @@ import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.util.HierarchicalUriComponents.PathComponent;
|
||||
|
||||
/**
|
||||
* Builder for {@link UriComponents}.
|
||||
@@ -46,6 +47,7 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Phillip Webb
|
||||
* @since 3.1
|
||||
* @see #newInstance()
|
||||
* @see #fromPath(String)
|
||||
@@ -53,7 +55,7 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class UriComponentsBuilder {
|
||||
|
||||
private static final Pattern QUERY_PARAM_PATTERN = Pattern.compile("([^&=]+)=?([^&]+)?");
|
||||
private static final Pattern QUERY_PARAM_PATTERN = Pattern.compile("([^&=]+)(=?)([^&]+)?");
|
||||
|
||||
private static final String SCHEME_PATTERN = "([^:/?#]+):";
|
||||
|
||||
@@ -91,7 +93,7 @@ public class UriComponentsBuilder {
|
||||
|
||||
private int port = -1;
|
||||
|
||||
private PathComponentBuilder pathBuilder = NULL_PATH_COMPONENT_BUILDER;
|
||||
private CompositePathComponentBuilder pathBuilder = new CompositePathComponentBuilder();
|
||||
|
||||
private final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
|
||||
|
||||
@@ -334,7 +336,7 @@ public class UriComponentsBuilder {
|
||||
this.port = uri.getPort();
|
||||
}
|
||||
if (StringUtils.hasLength(uri.getRawPath())) {
|
||||
this.pathBuilder = new FullPathComponentBuilder(uri.getRawPath());
|
||||
this.pathBuilder = new CompositePathComponentBuilder(uri.getRawPath());
|
||||
}
|
||||
if (StringUtils.hasLength(uri.getRawQuery())) {
|
||||
this.queryParams.clear();
|
||||
@@ -352,7 +354,7 @@ public class UriComponentsBuilder {
|
||||
this.userInfo = null;
|
||||
this.host = null;
|
||||
this.port = -1;
|
||||
this.pathBuilder = NULL_PATH_COMPONENT_BUILDER;
|
||||
this.pathBuilder = new CompositePathComponentBuilder();
|
||||
this.queryParams.clear();
|
||||
}
|
||||
|
||||
@@ -436,12 +438,7 @@ public class UriComponentsBuilder {
|
||||
* @return this UriComponentsBuilder
|
||||
*/
|
||||
public UriComponentsBuilder path(String path) {
|
||||
if (path != null) {
|
||||
this.pathBuilder = this.pathBuilder.appendPath(path);
|
||||
}
|
||||
else {
|
||||
this.pathBuilder = NULL_PATH_COMPONENT_BUILDER;
|
||||
}
|
||||
this.pathBuilder.addPath(path);
|
||||
resetSchemeSpecificPart();
|
||||
return this;
|
||||
}
|
||||
@@ -453,22 +450,21 @@ public class UriComponentsBuilder {
|
||||
* @return this UriComponentsBuilder
|
||||
*/
|
||||
public UriComponentsBuilder replacePath(String path) {
|
||||
this.pathBuilder = NULL_PATH_COMPONENT_BUILDER;
|
||||
path(path);
|
||||
this.pathBuilder = new CompositePathComponentBuilder(path);
|
||||
resetSchemeSpecificPart();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the given path segments to the existing path of this builder. Each given path segments may contain URI
|
||||
* template variables.
|
||||
* Appends the given path segments to the existing path of this builder. Each given
|
||||
* path segments may contain URI template variables.
|
||||
*
|
||||
* @param pathSegments the URI path segments
|
||||
* @return this UriComponentsBuilder
|
||||
*/
|
||||
public UriComponentsBuilder pathSegment(String... pathSegments) throws IllegalArgumentException {
|
||||
Assert.notNull(pathSegments, "'segments' must not be null");
|
||||
this.pathBuilder = this.pathBuilder.appendPathSegments(pathSegments);
|
||||
this.pathBuilder.addPathSegments(pathSegments);
|
||||
resetSchemeSpecificPart();
|
||||
return this;
|
||||
}
|
||||
@@ -496,8 +492,10 @@ public class UriComponentsBuilder {
|
||||
Matcher m = QUERY_PARAM_PATTERN.matcher(query);
|
||||
while (m.find()) {
|
||||
String name = m.group(1);
|
||||
String value = m.group(2);
|
||||
queryParam(name, value);
|
||||
String eq = m.group(2);
|
||||
String value = m.group(3);
|
||||
queryParam(name, (value != null ? value :
|
||||
(StringUtils.hasLength(eq) ? "" : null)));
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -588,131 +586,122 @@ public class UriComponentsBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a builder for {@link HierarchicalUriComponents.PathComponent}
|
||||
*/
|
||||
|
||||
private interface PathComponentBuilder {
|
||||
|
||||
HierarchicalUriComponents.PathComponent build();
|
||||
|
||||
PathComponentBuilder appendPath(String path);
|
||||
|
||||
PathComponentBuilder appendPathSegments(String... pathSegments);
|
||||
PathComponent build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a builder for full string paths.
|
||||
*/
|
||||
private static class FullPathComponentBuilder implements PathComponentBuilder {
|
||||
private static class CompositePathComponentBuilder implements PathComponentBuilder {
|
||||
|
||||
private final StringBuilder path;
|
||||
private LinkedList<PathComponentBuilder> componentBuilders = new LinkedList<PathComponentBuilder>();
|
||||
|
||||
private FullPathComponentBuilder(String path) {
|
||||
this.path = new StringBuilder(path);
|
||||
public CompositePathComponentBuilder() {
|
||||
}
|
||||
|
||||
public HierarchicalUriComponents.PathComponent build() {
|
||||
return new HierarchicalUriComponents.FullPathComponent(path.toString());
|
||||
public CompositePathComponentBuilder(String path) {
|
||||
addPath(path);
|
||||
}
|
||||
|
||||
public PathComponentBuilder appendPath(String path) {
|
||||
this.path.append(path);
|
||||
return this;
|
||||
public void addPathSegments(String... pathSegments) {
|
||||
if (!ObjectUtils.isEmpty(pathSegments)) {
|
||||
PathSegmentComponentBuilder psBuilder = getLastBuilder(PathSegmentComponentBuilder.class);
|
||||
FullPathComponentBuilder fpBuilder = getLastBuilder(FullPathComponentBuilder.class);
|
||||
if (psBuilder == null) {
|
||||
psBuilder = new PathSegmentComponentBuilder();
|
||||
this.componentBuilders.add(psBuilder);
|
||||
if (fpBuilder != null) {
|
||||
fpBuilder.removeTrailingSlash();
|
||||
}
|
||||
}
|
||||
psBuilder.append(pathSegments);
|
||||
}
|
||||
}
|
||||
|
||||
public PathComponentBuilder appendPathSegments(String... pathSegments) {
|
||||
PathComponentCompositeBuilder builder = new PathComponentCompositeBuilder(this);
|
||||
builder.appendPathSegments(pathSegments);
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a builder for paths segment paths.
|
||||
*/
|
||||
private static class PathSegmentComponentBuilder implements PathComponentBuilder {
|
||||
|
||||
private final List<String> pathSegments = new ArrayList<String>();
|
||||
|
||||
private PathSegmentComponentBuilder(String... pathSegments) {
|
||||
this.pathSegments.addAll(removeEmptyPathSegments(pathSegments));
|
||||
public void addPath(String path) {
|
||||
if (StringUtils.hasText(path)) {
|
||||
PathSegmentComponentBuilder psBuilder = getLastBuilder(PathSegmentComponentBuilder.class);
|
||||
FullPathComponentBuilder fpBuilder = getLastBuilder(FullPathComponentBuilder.class);
|
||||
if (psBuilder != null) {
|
||||
path = path.startsWith("/") ? path : "/" + path;
|
||||
}
|
||||
if (fpBuilder == null) {
|
||||
fpBuilder = new FullPathComponentBuilder();
|
||||
this.componentBuilders.add(fpBuilder);
|
||||
}
|
||||
fpBuilder.append(path);
|
||||
}
|
||||
}
|
||||
|
||||
private Collection<String> removeEmptyPathSegments(String... pathSegments) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
for (String segment : pathSegments) {
|
||||
if (StringUtils.hasText(segment)) {
|
||||
result.add(segment);
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> T getLastBuilder(Class<T> builderClass) {
|
||||
if (!this.componentBuilders.isEmpty()) {
|
||||
PathComponentBuilder last = this.componentBuilders.getLast();
|
||||
if (builderClass.isInstance(last)) {
|
||||
return (T) last;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return null;
|
||||
}
|
||||
|
||||
public HierarchicalUriComponents.PathComponent build() {
|
||||
return new HierarchicalUriComponents.PathSegmentComponent(pathSegments);
|
||||
}
|
||||
|
||||
public PathComponentBuilder appendPath(String path) {
|
||||
PathComponentCompositeBuilder builder = new PathComponentCompositeBuilder(this);
|
||||
builder.appendPath(path);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public PathComponentBuilder appendPathSegments(String... pathSegments) {
|
||||
this.pathSegments.addAll(removeEmptyPathSegments(pathSegments));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a builder for a collection of PathComponents.
|
||||
*/
|
||||
private static class PathComponentCompositeBuilder implements PathComponentBuilder {
|
||||
|
||||
private final List<PathComponentBuilder> pathComponentBuilders = new ArrayList<PathComponentBuilder>();
|
||||
|
||||
private PathComponentCompositeBuilder(PathComponentBuilder builder) {
|
||||
pathComponentBuilders.add(builder);
|
||||
}
|
||||
|
||||
public HierarchicalUriComponents.PathComponent build() {
|
||||
List<HierarchicalUriComponents.PathComponent> pathComponents =
|
||||
new ArrayList<HierarchicalUriComponents.PathComponent>(pathComponentBuilders.size());
|
||||
|
||||
for (PathComponentBuilder pathComponentBuilder : pathComponentBuilders) {
|
||||
pathComponents.add(pathComponentBuilder.build());
|
||||
public PathComponent build() {
|
||||
int size = this.componentBuilders.size();
|
||||
List<PathComponent> components = new ArrayList<PathComponent>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
PathComponent pathComponent = this.componentBuilders.get(i).build();
|
||||
if (pathComponent != null) {
|
||||
components.add(pathComponent);
|
||||
}
|
||||
}
|
||||
return new HierarchicalUriComponents.PathComponentComposite(pathComponents);
|
||||
}
|
||||
|
||||
public PathComponentBuilder appendPath(String path) {
|
||||
this.pathComponentBuilders.add(new FullPathComponentBuilder(path));
|
||||
return this;
|
||||
}
|
||||
|
||||
public PathComponentBuilder appendPathSegments(String... pathSegments) {
|
||||
this.pathComponentBuilders.add(new PathSegmentComponentBuilder(pathSegments));
|
||||
return this;
|
||||
if (components.isEmpty()) {
|
||||
return HierarchicalUriComponents.NULL_PATH_COMPONENT;
|
||||
}
|
||||
if (components.size() == 1) {
|
||||
return components.get(0);
|
||||
}
|
||||
return new HierarchicalUriComponents.PathComponentComposite(components);
|
||||
}
|
||||
}
|
||||
|
||||
private static class FullPathComponentBuilder implements PathComponentBuilder {
|
||||
|
||||
/**
|
||||
* Represents a builder for an empty path.
|
||||
*/
|
||||
private static PathComponentBuilder NULL_PATH_COMPONENT_BUILDER = new PathComponentBuilder() {
|
||||
private StringBuilder path = new StringBuilder();
|
||||
|
||||
public HierarchicalUriComponents.PathComponent build() {
|
||||
return HierarchicalUriComponents.NULL_PATH_COMPONENT;
|
||||
public void append(String path) {
|
||||
this.path.append(path);
|
||||
}
|
||||
|
||||
public PathComponentBuilder appendPath(String path) {
|
||||
return new FullPathComponentBuilder(path);
|
||||
public PathComponent build() {
|
||||
if (this.path.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
String path = this.path.toString().replace("//", "/");
|
||||
return new HierarchicalUriComponents.FullPathComponent(path);
|
||||
}
|
||||
|
||||
public PathComponentBuilder appendPathSegments(String... pathSegments) {
|
||||
return new PathSegmentComponentBuilder(pathSegments);
|
||||
public void removeTrailingSlash() {
|
||||
int index = this.path.length() - 1;
|
||||
if (this.path.charAt(index) == '/') {
|
||||
this.path.deleteCharAt(index);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static class PathSegmentComponentBuilder implements PathComponentBuilder {
|
||||
|
||||
private List<String> pathSegments = new LinkedList<String>();
|
||||
|
||||
public void append(String... pathSegments) {
|
||||
for (String pathSegment : pathSegments) {
|
||||
if (StringUtils.hasText(pathSegment)) {
|
||||
this.pathSegments.add(pathSegment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PathComponent build() {
|
||||
return this.pathSegments.isEmpty() ?
|
||||
null : new HierarchicalUriComponents.PathSegmentComponent(this.pathSegments);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -32,7 +32,7 @@ import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Represents a URI template. A URI template is a URI-like String that contains variables enclosed
|
||||
* by braces ({@code {}, {@code }}), which can be expanded to produce an actual URI.
|
||||
* by braces ({@code {}}), which can be expanded to produce an actual URI.
|
||||
*
|
||||
* <p>See {@link #expand(Map)}, {@link #expand(Object[])}, and {@link #match(String)} for example usages.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -27,6 +27,8 @@ import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -439,10 +441,8 @@ public class UrlPathHelper {
|
||||
* @return the updated URI string
|
||||
*/
|
||||
public String removeSemicolonContent(String requestUri) {
|
||||
if (this.removeSemicolonContent) {
|
||||
return removeSemicolonContentInternal(requestUri);
|
||||
}
|
||||
return removeJsessionid(requestUri);
|
||||
return this.removeSemicolonContent ?
|
||||
removeSemicolonContentInternal(requestUri) : removeJsessionid(requestUri);
|
||||
}
|
||||
|
||||
private String removeSemicolonContentInternal(String requestUri) {
|
||||
@@ -491,6 +491,33 @@ public class UrlPathHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the given matrix variables via
|
||||
* {@link #decodeRequestString(HttpServletRequest, String)} unless
|
||||
* {@link #setUrlDecode(boolean)} is set to {@code true} in which case it is
|
||||
* assumed the URL path from which the variables were extracted is already
|
||||
* decoded through a call to
|
||||
* {@link #getLookupPathForRequest(HttpServletRequest)}.
|
||||
*
|
||||
* @param request current HTTP request
|
||||
* @param vars URI variables extracted from the URL path
|
||||
* @return the same Map or a new Map instance
|
||||
*/
|
||||
public MultiValueMap<String, String> decodeMatrixVariables(HttpServletRequest request, MultiValueMap<String, String> vars) {
|
||||
if (this.urlDecode) {
|
||||
return vars;
|
||||
}
|
||||
else {
|
||||
MultiValueMap<String, String> decodedVars = new LinkedMultiValueMap <String, String>(vars.size());
|
||||
for (String key : vars.keySet()) {
|
||||
for (String value : vars.get(key)) {
|
||||
decodedVars.add(key, decodeInternal(request, value));
|
||||
}
|
||||
}
|
||||
return decodedVars;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shouldRemoveTrailingServletPathSlash(HttpServletRequest request) {
|
||||
if (request.getAttribute(WEBSPHERE_URI_ATTRIBUTE) == null) {
|
||||
// Regular servlet container: behaves as expected in any case,
|
||||
|
||||
@@ -5,5 +5,6 @@
|
||||
version="3.0" metadata-complete="true">
|
||||
|
||||
<name>spring_web</name>
|
||||
<distributable/>
|
||||
|
||||
</web-fragment>
|
||||
</web-fragment>
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.beans;
|
||||
|
||||
import org.springframework.core.enums.ShortCodedLabeledEnum;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class Colour extends ShortCodedLabeledEnum {
|
||||
|
||||
public static final Colour RED = new Colour(0, "RED");
|
||||
public static final Colour BLUE = new Colour(1, "BLUE");
|
||||
public static final Colour GREEN = new Colour(2, "GREEN");
|
||||
public static final Colour PURPLE = new Colour(3, "PURPLE");
|
||||
|
||||
private Colour(int code, String label) {
|
||||
super(code, label);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.beans;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @since 21.08.2003
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class DerivedTestBean extends TestBean implements Serializable, BeanNameAware, DisposableBean {
|
||||
|
||||
private String beanName;
|
||||
|
||||
private boolean initialized;
|
||||
|
||||
private boolean destroyed;
|
||||
|
||||
|
||||
public DerivedTestBean() {
|
||||
}
|
||||
|
||||
public DerivedTestBean(String[] names) {
|
||||
if (names == null || names.length < 2) {
|
||||
throw new IllegalArgumentException("Invalid names array");
|
||||
}
|
||||
setName(names[0]);
|
||||
setBeanName(names[1]);
|
||||
}
|
||||
|
||||
public static DerivedTestBean create(String[] names) {
|
||||
return new DerivedTestBean(names);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setBeanName(String beanName) {
|
||||
if (this.beanName == null || beanName == null) {
|
||||
this.beanName = beanName;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBeanName() {
|
||||
return beanName;
|
||||
}
|
||||
|
||||
public void setSpouseRef(String name) {
|
||||
setSpouse(new TestBean(name));
|
||||
}
|
||||
|
||||
|
||||
public void initialize() {
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
public boolean wasInitialized() {
|
||||
return initialized;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
this.destroyed = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wasDestroyed() {
|
||||
return destroyed;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.beans;
|
||||
|
||||
public interface INestedTestBean {
|
||||
|
||||
public String getCompany();
|
||||
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
|
||||
/*
|
||||
* Copyright 2002-2012 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
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.beans;
|
||||
|
||||
public interface IOther {
|
||||
|
||||
void absquatulate();
|
||||
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2009 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
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.beans;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Interface used for {@link org.springframework.beans.TestBean}.
|
||||
*
|
||||
* <p>Two methods are the same as on Person, but if this
|
||||
* extends person it breaks quite a few tests..
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public interface ITestBean {
|
||||
|
||||
int getAge();
|
||||
|
||||
void setAge(int age);
|
||||
|
||||
String getName();
|
||||
|
||||
void setName(String name);
|
||||
|
||||
ITestBean getSpouse();
|
||||
|
||||
void setSpouse(ITestBean spouse);
|
||||
|
||||
ITestBean[] getSpouses();
|
||||
|
||||
String[] getStringArray();
|
||||
|
||||
void setStringArray(String[] stringArray);
|
||||
|
||||
Integer[][] getNestedIntegerArray();
|
||||
|
||||
Integer[] getSomeIntegerArray();
|
||||
|
||||
void setSomeIntegerArray(Integer[] someIntegerArray);
|
||||
|
||||
void setNestedIntegerArray(Integer[][] nestedIntegerArray);
|
||||
|
||||
int[] getSomeIntArray();
|
||||
|
||||
void setSomeIntArray(int[] someIntArray);
|
||||
|
||||
int[][] getNestedIntArray();
|
||||
|
||||
void setNestedIntArray(int[][] someNestedArray);
|
||||
|
||||
/**
|
||||
* Throws a given (non-null) exception.
|
||||
*/
|
||||
void exceptional(Throwable t) throws Throwable;
|
||||
|
||||
Object returnsThis();
|
||||
|
||||
INestedTestBean getDoctor();
|
||||
|
||||
INestedTestBean getLawyer();
|
||||
|
||||
IndexedTestBean getNestedIndexedBean();
|
||||
|
||||
/**
|
||||
* Increment the age by one.
|
||||
* @return the previous age
|
||||
*/
|
||||
int haveBirthday();
|
||||
|
||||
void unreliableFileOperation() throws IOException;
|
||||
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2006 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
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.beans;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @since 11.11.2003
|
||||
*/
|
||||
public class IndexedTestBean {
|
||||
|
||||
private TestBean[] array;
|
||||
|
||||
private Collection collection;
|
||||
|
||||
private List list;
|
||||
|
||||
private Set set;
|
||||
|
||||
private SortedSet sortedSet;
|
||||
|
||||
private Map map;
|
||||
|
||||
private SortedMap sortedMap;
|
||||
|
||||
|
||||
public IndexedTestBean() {
|
||||
this(true);
|
||||
}
|
||||
|
||||
public IndexedTestBean(boolean populate) {
|
||||
if (populate) {
|
||||
populate();
|
||||
}
|
||||
}
|
||||
|
||||
public void populate() {
|
||||
TestBean tb0 = new TestBean("name0", 0);
|
||||
TestBean tb1 = new TestBean("name1", 0);
|
||||
TestBean tb2 = new TestBean("name2", 0);
|
||||
TestBean tb3 = new TestBean("name3", 0);
|
||||
TestBean tb4 = new TestBean("name4", 0);
|
||||
TestBean tb5 = new TestBean("name5", 0);
|
||||
TestBean tb6 = new TestBean("name6", 0);
|
||||
TestBean tb7 = new TestBean("name7", 0);
|
||||
TestBean tbX = new TestBean("nameX", 0);
|
||||
TestBean tbY = new TestBean("nameY", 0);
|
||||
this.array = new TestBean[] {tb0, tb1};
|
||||
this.list = new ArrayList();
|
||||
this.list.add(tb2);
|
||||
this.list.add(tb3);
|
||||
this.set = new TreeSet();
|
||||
this.set.add(tb6);
|
||||
this.set.add(tb7);
|
||||
this.map = new HashMap();
|
||||
this.map.put("key1", tb4);
|
||||
this.map.put("key2", tb5);
|
||||
this.map.put("key.3", tb5);
|
||||
List list = new ArrayList();
|
||||
list.add(tbX);
|
||||
list.add(tbY);
|
||||
this.map.put("key4", list);
|
||||
}
|
||||
|
||||
|
||||
public TestBean[] getArray() {
|
||||
return array;
|
||||
}
|
||||
|
||||
public void setArray(TestBean[] array) {
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
public Collection getCollection() {
|
||||
return collection;
|
||||
}
|
||||
|
||||
public void setCollection(Collection collection) {
|
||||
this.collection = collection;
|
||||
}
|
||||
|
||||
public List getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
public Set getSet() {
|
||||
return set;
|
||||
}
|
||||
|
||||
public void setSet(Set set) {
|
||||
this.set = set;
|
||||
}
|
||||
|
||||
public SortedSet getSortedSet() {
|
||||
return sortedSet;
|
||||
}
|
||||
|
||||
public void setSortedSet(SortedSet sortedSet) {
|
||||
this.sortedSet = sortedSet;
|
||||
}
|
||||
|
||||
public Map getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
public void setMap(Map map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
public SortedMap getSortedMap() {
|
||||
return sortedMap;
|
||||
}
|
||||
|
||||
public void setSortedMap(SortedMap sortedMap) {
|
||||
this.sortedMap = sortedMap;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.beans;
|
||||
|
||||
/**
|
||||
* Simple nested test bean used for testing bean factories, AOP framework etc.
|
||||
*
|
||||
* @author Trevor D. Cook
|
||||
* @since 30.09.2003
|
||||
*/
|
||||
public class NestedTestBean implements INestedTestBean {
|
||||
|
||||
private String company = "";
|
||||
|
||||
public NestedTestBean() {
|
||||
}
|
||||
|
||||
public NestedTestBean(String company) {
|
||||
setCompany(company);
|
||||
}
|
||||
|
||||
public void setCompany(String company) {
|
||||
this.company = (company != null ? company : "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCompany() {
|
||||
return company;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof NestedTestBean)) {
|
||||
return false;
|
||||
}
|
||||
NestedTestBean ntb = (NestedTestBean) obj;
|
||||
return this.company.equals(ntb.company);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.company.hashCode();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "NestedTestBean: " + this.company;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.beans;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
public interface Person {
|
||||
|
||||
String getName();
|
||||
void setName(String name);
|
||||
int getAge();
|
||||
void setAge(int i);
|
||||
|
||||
/**
|
||||
* Test for non-property method matching.
|
||||
* If the parameter is a Throwable, it will be thrown rather than
|
||||
* returned.
|
||||
*/
|
||||
Object echo(Object o) throws Throwable;
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.beans;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Serializable implementation of the Person interface.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class SerializablePerson implements Person, Serializable {
|
||||
|
||||
private String name;
|
||||
private int age;
|
||||
|
||||
@Override
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object echo(Object o) throws Throwable {
|
||||
if (o instanceof Throwable) {
|
||||
throw (Throwable) o;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof SerializablePerson)) {
|
||||
return false;
|
||||
}
|
||||
SerializablePerson p = (SerializablePerson) other;
|
||||
return p.age == age && ObjectUtils.nullSafeEquals(name, p.name);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,495 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.beans;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Simple test bean used for testing bean factories, the AOP framework etc.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
* @since 15 April 2001
|
||||
*/
|
||||
public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOther, Comparable {
|
||||
|
||||
private String beanName;
|
||||
|
||||
private String country;
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
|
||||
private boolean postProcessed;
|
||||
|
||||
private String name;
|
||||
|
||||
private String sex;
|
||||
|
||||
private int age;
|
||||
|
||||
private boolean jedi;
|
||||
|
||||
private ITestBean[] spouses;
|
||||
|
||||
private String touchy;
|
||||
|
||||
private String[] stringArray;
|
||||
|
||||
private Integer[] someIntegerArray;
|
||||
|
||||
private Integer[][] nestedIntegerArray;
|
||||
|
||||
private int[] someIntArray;
|
||||
|
||||
private int[][] nestedIntArray;
|
||||
|
||||
private Date date = new Date();
|
||||
|
||||
private Float myFloat = new Float(0.0);
|
||||
|
||||
private Collection friends = new LinkedList();
|
||||
|
||||
private Set someSet = new HashSet();
|
||||
|
||||
private Map someMap = new HashMap();
|
||||
|
||||
private List someList = new ArrayList();
|
||||
|
||||
private Properties someProperties = new Properties();
|
||||
|
||||
private INestedTestBean doctor = new NestedTestBean();
|
||||
|
||||
private INestedTestBean lawyer = new NestedTestBean();
|
||||
|
||||
private IndexedTestBean nestedIndexedBean;
|
||||
|
||||
private boolean destroyed;
|
||||
|
||||
private Number someNumber;
|
||||
|
||||
private Colour favouriteColour;
|
||||
|
||||
private Boolean someBoolean;
|
||||
|
||||
private List otherColours;
|
||||
|
||||
private List pets;
|
||||
|
||||
|
||||
public TestBean() {
|
||||
}
|
||||
|
||||
public TestBean(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public TestBean(ITestBean spouse) {
|
||||
this.spouses = new ITestBean[] {spouse};
|
||||
}
|
||||
|
||||
public TestBean(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public TestBean(ITestBean spouse, Properties someProperties) {
|
||||
this.spouses = new ITestBean[] {spouse};
|
||||
this.someProperties = someProperties;
|
||||
}
|
||||
|
||||
public TestBean(List someList) {
|
||||
this.someList = someList;
|
||||
}
|
||||
|
||||
public TestBean(Set someSet) {
|
||||
this.someSet = someSet;
|
||||
}
|
||||
|
||||
public TestBean(Map someMap) {
|
||||
this.someMap = someMap;
|
||||
}
|
||||
|
||||
public TestBean(Properties someProperties) {
|
||||
this.someProperties = someProperties;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setBeanName(String beanName) {
|
||||
this.beanName = beanName;
|
||||
}
|
||||
|
||||
public String getBeanName() {
|
||||
return beanName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
this.beanFactory = beanFactory;
|
||||
}
|
||||
|
||||
public BeanFactory getBeanFactory() {
|
||||
return beanFactory;
|
||||
}
|
||||
|
||||
public void setPostProcessed(boolean postProcessed) {
|
||||
this.postProcessed = postProcessed;
|
||||
}
|
||||
|
||||
public boolean isPostProcessed() {
|
||||
return postProcessed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSex() {
|
||||
return sex;
|
||||
}
|
||||
|
||||
public void setSex(String sex) {
|
||||
this.sex = sex;
|
||||
if (this.name == null) {
|
||||
this.name = sex;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public boolean isJedi() {
|
||||
return jedi;
|
||||
}
|
||||
|
||||
public void setJedi(boolean jedi) {
|
||||
this.jedi = jedi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITestBean getSpouse() {
|
||||
return (spouses != null ? spouses[0] : null);
|
||||
}
|
||||
|
||||
public void setConcreteSpouse(TestBean spouse) {
|
||||
this.spouses = new ITestBean[] {spouse};
|
||||
}
|
||||
|
||||
public TestBean getConcreteSpouse() {
|
||||
return (spouses != null ? (TestBean) spouses[0] : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSpouse(ITestBean spouse) {
|
||||
this.spouses = new ITestBean[] {spouse};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITestBean[] getSpouses() {
|
||||
return spouses;
|
||||
}
|
||||
|
||||
public String getTouchy() {
|
||||
return touchy;
|
||||
}
|
||||
|
||||
public void setTouchy(String touchy) throws Exception {
|
||||
if (touchy.indexOf('.') != -1) {
|
||||
throw new Exception("Can't contain a .");
|
||||
}
|
||||
if (touchy.indexOf(',') != -1) {
|
||||
throw new NumberFormatException("Number format exception: contains a ,");
|
||||
}
|
||||
this.touchy = touchy;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getStringArray() {
|
||||
return stringArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStringArray(String[] stringArray) {
|
||||
this.stringArray = stringArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer[] getSomeIntegerArray() {
|
||||
return someIntegerArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSomeIntegerArray(Integer[] someIntegerArray) {
|
||||
this.someIntegerArray = someIntegerArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer[][] getNestedIntegerArray() {
|
||||
return nestedIntegerArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNestedIntegerArray(Integer[][] nestedIntegerArray) {
|
||||
this.nestedIntegerArray = nestedIntegerArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getSomeIntArray() {
|
||||
return someIntArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSomeIntArray(int[] someIntArray) {
|
||||
this.someIntArray = someIntArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[][] getNestedIntArray() {
|
||||
return nestedIntArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNestedIntArray(int[][] nestedIntArray) {
|
||||
this.nestedIntArray = nestedIntArray;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public Float getMyFloat() {
|
||||
return myFloat;
|
||||
}
|
||||
|
||||
public void setMyFloat(Float myFloat) {
|
||||
this.myFloat = myFloat;
|
||||
}
|
||||
|
||||
public Collection getFriends() {
|
||||
return friends;
|
||||
}
|
||||
|
||||
public void setFriends(Collection friends) {
|
||||
this.friends = friends;
|
||||
}
|
||||
|
||||
public Set getSomeSet() {
|
||||
return someSet;
|
||||
}
|
||||
|
||||
public void setSomeSet(Set someSet) {
|
||||
this.someSet = someSet;
|
||||
}
|
||||
|
||||
public Map getSomeMap() {
|
||||
return someMap;
|
||||
}
|
||||
|
||||
public void setSomeMap(Map someMap) {
|
||||
this.someMap = someMap;
|
||||
}
|
||||
|
||||
public List getSomeList() {
|
||||
return someList;
|
||||
}
|
||||
|
||||
public void setSomeList(List someList) {
|
||||
this.someList = someList;
|
||||
}
|
||||
|
||||
public Properties getSomeProperties() {
|
||||
return someProperties;
|
||||
}
|
||||
|
||||
public void setSomeProperties(Properties someProperties) {
|
||||
this.someProperties = someProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INestedTestBean getDoctor() {
|
||||
return doctor;
|
||||
}
|
||||
|
||||
public void setDoctor(INestedTestBean doctor) {
|
||||
this.doctor = doctor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INestedTestBean getLawyer() {
|
||||
return lawyer;
|
||||
}
|
||||
|
||||
public void setLawyer(INestedTestBean lawyer) {
|
||||
this.lawyer = lawyer;
|
||||
}
|
||||
|
||||
public Number getSomeNumber() {
|
||||
return someNumber;
|
||||
}
|
||||
|
||||
public void setSomeNumber(Number someNumber) {
|
||||
this.someNumber = someNumber;
|
||||
}
|
||||
|
||||
public Colour getFavouriteColour() {
|
||||
return favouriteColour;
|
||||
}
|
||||
|
||||
public void setFavouriteColour(Colour favouriteColour) {
|
||||
this.favouriteColour = favouriteColour;
|
||||
}
|
||||
|
||||
public Boolean getSomeBoolean() {
|
||||
return someBoolean;
|
||||
}
|
||||
|
||||
public void setSomeBoolean(Boolean someBoolean) {
|
||||
this.someBoolean = someBoolean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndexedTestBean getNestedIndexedBean() {
|
||||
return nestedIndexedBean;
|
||||
}
|
||||
|
||||
public void setNestedIndexedBean(IndexedTestBean nestedIndexedBean) {
|
||||
this.nestedIndexedBean = nestedIndexedBean;
|
||||
}
|
||||
|
||||
public List getOtherColours() {
|
||||
return otherColours;
|
||||
}
|
||||
|
||||
public void setOtherColours(List otherColours) {
|
||||
this.otherColours = otherColours;
|
||||
}
|
||||
|
||||
public List getPets() {
|
||||
return pets;
|
||||
}
|
||||
|
||||
public void setPets(List pets) {
|
||||
this.pets = pets;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void exceptional(Throwable t) throws Throwable {
|
||||
if (t != null) {
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unreliableFileOperation() throws IOException {
|
||||
throw new IOException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object returnsThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void absquatulate() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int haveBirthday() {
|
||||
return age++;
|
||||
}
|
||||
|
||||
|
||||
public void destroy() {
|
||||
this.destroyed = true;
|
||||
}
|
||||
|
||||
public boolean wasDestroyed() {
|
||||
return destroyed;
|
||||
}
|
||||
|
||||
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (other == null || !(other instanceof TestBean)) {
|
||||
return false;
|
||||
}
|
||||
TestBean tb2 = (TestBean) other;
|
||||
return (ObjectUtils.nullSafeEquals(this.name, tb2.name) && this.age == tb2.age);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.age;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object other) {
|
||||
if (this.name != null && other instanceof TestBean) {
|
||||
return this.name.compareTo(((TestBean) other).getName());
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,179 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.beans.factory;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
|
||||
/**
|
||||
* Simple factory to allow testing of FactoryBean support in AbstractBeanFactory.
|
||||
* Depending on whether its singleton property is set, it will return a singleton
|
||||
* or a prototype instance.
|
||||
*
|
||||
* <p>Implements InitializingBean interface, so we can check that
|
||||
* factories get this lifecycle callback if they want.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @since 10.03.2003
|
||||
*/
|
||||
public class DummyFactory
|
||||
implements FactoryBean, BeanNameAware, BeanFactoryAware, InitializingBean, DisposableBean {
|
||||
|
||||
public static final String SINGLETON_NAME = "Factory singleton";
|
||||
|
||||
private static boolean prototypeCreated;
|
||||
|
||||
/**
|
||||
* Clear static state.
|
||||
*/
|
||||
public static void reset() {
|
||||
prototypeCreated = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Default is for factories to return a singleton instance.
|
||||
*/
|
||||
private boolean singleton = true;
|
||||
|
||||
private String beanName;
|
||||
|
||||
private AutowireCapableBeanFactory beanFactory;
|
||||
|
||||
private boolean postProcessed;
|
||||
|
||||
private boolean initialized;
|
||||
|
||||
private TestBean testBean;
|
||||
|
||||
private TestBean otherTestBean;
|
||||
|
||||
|
||||
public DummyFactory() {
|
||||
this.testBean = new TestBean();
|
||||
this.testBean.setName(SINGLETON_NAME);
|
||||
this.testBean.setAge(25);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if the bean managed by this factory is a singleton.
|
||||
* @see FactoryBean#isSingleton()
|
||||
*/
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return this.singleton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the bean managed by this factory is a singleton.
|
||||
*/
|
||||
public void setSingleton(boolean singleton) {
|
||||
this.singleton = singleton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanName(String beanName) {
|
||||
this.beanName = beanName;
|
||||
}
|
||||
|
||||
public String getBeanName() {
|
||||
return beanName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
this.beanFactory = (AutowireCapableBeanFactory) beanFactory;
|
||||
this.beanFactory.applyBeanPostProcessorsBeforeInitialization(this.testBean, this.beanName);
|
||||
}
|
||||
|
||||
public BeanFactory getBeanFactory() {
|
||||
return beanFactory;
|
||||
}
|
||||
|
||||
public void setPostProcessed(boolean postProcessed) {
|
||||
this.postProcessed = postProcessed;
|
||||
}
|
||||
|
||||
public boolean isPostProcessed() {
|
||||
return postProcessed;
|
||||
}
|
||||
|
||||
public void setOtherTestBean(TestBean otherTestBean) {
|
||||
this.otherTestBean = otherTestBean;
|
||||
this.testBean.setSpouse(otherTestBean);
|
||||
}
|
||||
|
||||
public TestBean getOtherTestBean() {
|
||||
return otherTestBean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
if (initialized) {
|
||||
throw new RuntimeException("Cannot call afterPropertiesSet twice on the one bean");
|
||||
}
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Was this initialized by invocation of the
|
||||
* afterPropertiesSet() method from the InitializingBean interface?
|
||||
*/
|
||||
public boolean wasInitialized() {
|
||||
return initialized;
|
||||
}
|
||||
|
||||
public static boolean wasPrototypeCreated() {
|
||||
return prototypeCreated;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the managed object, supporting both singleton
|
||||
* and prototype mode.
|
||||
* @see FactoryBean#getObject()
|
||||
*/
|
||||
@Override
|
||||
public Object getObject() throws BeansException {
|
||||
if (isSingleton()) {
|
||||
return this.testBean;
|
||||
}
|
||||
else {
|
||||
TestBean prototype = new TestBean("prototype created at " + System.currentTimeMillis(), 11);
|
||||
if (this.beanFactory != null) {
|
||||
this.beanFactory.applyBeanPostProcessorsBeforeInitialization(prototype, this.beanName);
|
||||
}
|
||||
prototypeCreated = true;
|
||||
return prototype;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getObjectType() {
|
||||
return TestBean.class;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
if (this.testBean != null) {
|
||||
this.testBean.setName(null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -97,12 +97,12 @@ public class MediaTypeTests {
|
||||
assertEquals("Invalid toString() returned", "text/plain;q=0.7", result);
|
||||
}
|
||||
|
||||
@Test(expected= IllegalArgumentException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void slashInType() {
|
||||
new MediaType("text/plain");
|
||||
}
|
||||
|
||||
@Test(expected= IllegalArgumentException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void slashInSubtype() {
|
||||
new MediaType("text", "/");
|
||||
}
|
||||
@@ -122,57 +122,57 @@ public class MediaTypeTests {
|
||||
assertEquals("Invalid quality factor", 0.2D, mediaType.getQualityValue(), 0D);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test(expected = InvalidMediaTypeException.class)
|
||||
public void parseMediaTypeNoSubtype() {
|
||||
MediaType.parseMediaType("audio");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test(expected = InvalidMediaTypeException.class)
|
||||
public void parseMediaTypeNoSubtypeSlash() {
|
||||
MediaType.parseMediaType("audio/");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test(expected = InvalidMediaTypeException.class)
|
||||
public void parseMediaTypeTypeRange() {
|
||||
MediaType.parseMediaType("*/json");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test(expected = InvalidMediaTypeException.class)
|
||||
public void parseMediaTypeIllegalType() {
|
||||
MediaType.parseMediaType("audio(/basic");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test(expected = InvalidMediaTypeException.class)
|
||||
public void parseMediaTypeIllegalSubtype() {
|
||||
MediaType.parseMediaType("audio/basic)");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test(expected = InvalidMediaTypeException.class)
|
||||
public void parseMediaTypeEmptyParameterAttribute() {
|
||||
MediaType.parseMediaType("audio/*;=value");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test(expected = InvalidMediaTypeException.class)
|
||||
public void parseMediaTypeEmptyParameterValue() {
|
||||
MediaType.parseMediaType("audio/*;attr=");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test(expected = InvalidMediaTypeException.class)
|
||||
public void parseMediaTypeIllegalParameterAttribute() {
|
||||
MediaType.parseMediaType("audio/*;attr<=value");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test(expected = InvalidMediaTypeException.class)
|
||||
public void parseMediaTypeIllegalParameterValue() {
|
||||
MediaType.parseMediaType("audio/*;attr=v>alue");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test(expected = InvalidMediaTypeException.class)
|
||||
public void parseMediaTypeIllegalQualityFactor() {
|
||||
MediaType.parseMediaType("audio/basic;q=1.1");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test(expected = InvalidMediaTypeException.class)
|
||||
public void parseMediaTypeIllegalCharset() {
|
||||
MediaType.parseMediaType("text/html; charset=foo-bar");
|
||||
}
|
||||
@@ -193,7 +193,7 @@ public class MediaTypeTests {
|
||||
assertEquals("'v>alue'", mediaType.getParameter("attr"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test(expected = InvalidMediaTypeException.class)
|
||||
public void parseMediaTypeIllegalQuotedParameterValue() {
|
||||
MediaType.parseMediaType("audio/*;attr=\"");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.http;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
@@ -28,7 +30,7 @@ public class MockHttpOutputMessage implements HttpOutputMessage {
|
||||
|
||||
private final HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
private final ByteArrayOutputStream body = new ByteArrayOutputStream();
|
||||
private final ByteArrayOutputStream body = spy(new ByteArrayOutputStream());
|
||||
|
||||
@Override
|
||||
public HttpHeaders getHeaders() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -43,6 +43,7 @@ import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.tests.web.FreePortScanner;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
public abstract class AbstractHttpRequestFactoryTestCase {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -14,22 +14,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.beans;
|
||||
package org.springframework.http.client;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @since 17.08.2004
|
||||
*/
|
||||
public class BeanWithObjectProperty {
|
||||
|
||||
private Object object;
|
||||
public class NoOutputStreamingBufferedSimpleHttpRequestFactoryTests extends AbstractHttpRequestFactoryTestCase {
|
||||
|
||||
public Object getObject() {
|
||||
return object;
|
||||
@Override
|
||||
protected ClientHttpRequestFactory createRequestFactory() {
|
||||
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
|
||||
factory.setOutputStreaming(false);
|
||||
return factory;
|
||||
}
|
||||
|
||||
public void setObject(Object object) {
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -14,31 +14,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.beans;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @since 07.03.2006
|
||||
*/
|
||||
public class FieldAccessBean {
|
||||
|
||||
public String name;
|
||||
|
||||
protected int age;
|
||||
|
||||
private TestBean spouse;
|
||||
package org.springframework.http.client;
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
public class NoOutputStreamingStreamingSimpleHttpRequestFactoryTests extends AbstractHttpRequestFactoryTestCase {
|
||||
|
||||
@Override
|
||||
protected ClientHttpRequestFactory createRequestFactory() {
|
||||
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
|
||||
factory.setBufferRequestBody(false);
|
||||
factory.setOutputStreaming(false);
|
||||
return factory;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public TestBean getSpouse() {
|
||||
return spouse;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -81,7 +81,7 @@ public class StreamingSimpleHttpRequestFactoryTests extends AbstractHttpRequestF
|
||||
ClientHttpRequest request = factory.createRequest(new URI(baseUrl + "/methods/post"), HttpMethod.POST);
|
||||
final int BUF_SIZE = 4096;
|
||||
final int ITERATIONS = Integer.MAX_VALUE / BUF_SIZE;
|
||||
final int contentLength = ITERATIONS * BUF_SIZE;
|
||||
// final int contentLength = ITERATIONS * BUF_SIZE;
|
||||
// request.getHeaders().setContentLength(contentLength);
|
||||
OutputStream body = request.getBody();
|
||||
for (int i = 0; i < ITERATIONS; i++) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -51,6 +51,7 @@ public class BufferedImageHttpMessageConverterTests {
|
||||
public void canWrite() {
|
||||
assertTrue("Image not supported", converter.canWrite(BufferedImage.class, null));
|
||||
assertTrue("Image not supported", converter.canWrite(BufferedImage.class, new MediaType("image", "png")));
|
||||
assertTrue("Image not supported", converter.canWrite(BufferedImage.class, new MediaType("*", "*")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,7 +86,7 @@ public class BufferedImageHttpMessageConverterTests {
|
||||
converter.setDefaultContentType(contentType);
|
||||
BufferedImage body = ImageIO.read(logo.getFile());
|
||||
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
|
||||
converter.write(body, contentType, outputMessage);
|
||||
converter.write(body, new MediaType("*", "*"), outputMessage);
|
||||
assertEquals("Invalid content type", contentType, outputMessage.getHeaders().getContentType());
|
||||
assertTrue("Invalid size", outputMessage.getBodyAsBytes().length > 0);
|
||||
BufferedImage result = ImageIO.read(new ByteArrayInputStream(outputMessage.getBodyAsBytes()));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -45,6 +45,8 @@ import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
@@ -72,7 +74,6 @@ public class FormHttpMessageConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void readForm() throws Exception {
|
||||
String body = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3";
|
||||
Charset iso88591 = Charset.forName("ISO-8859-1");
|
||||
@@ -112,6 +113,7 @@ public class FormHttpMessageConverterTests {
|
||||
parts.add("name 1", "value 1");
|
||||
parts.add("name 2", "value 2+1");
|
||||
parts.add("name 2", "value 2+2");
|
||||
parts.add("name 3", null);
|
||||
|
||||
Resource logo = new ClassPathResource("/org/springframework/http/converter/logo.jpg");
|
||||
parts.add("logo", logo);
|
||||
@@ -157,6 +159,7 @@ public class FormHttpMessageConverterTests {
|
||||
item = (FileItem) items.get(4);
|
||||
assertEquals("xml", item.getFieldName());
|
||||
assertEquals("text/xml", item.getContentType());
|
||||
verify(outputMessage.getBody(), never()).close();
|
||||
}
|
||||
|
||||
private static class MockHttpOutputMessageRequestContext implements RequestContext {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -36,7 +36,6 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.AsyncContext;
|
||||
import javax.servlet.DispatcherType;
|
||||
import javax.servlet.RequestDispatcher;
|
||||
@@ -110,9 +109,9 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
private boolean active = true;
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
// ServletRequest properties
|
||||
//---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
private final Map<String, Object> attributes = new LinkedHashMap<String, Object>();
|
||||
|
||||
@@ -151,11 +150,12 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
|
||||
private int localPort = DEFAULT_SERVER_PORT;
|
||||
|
||||
private Map<String, Part> parts = new HashMap<String, Part>();
|
||||
private final Map<String, Part> parts = new HashMap<String, Part>();
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// HttpServletRequest properties
|
||||
//---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
private String authType;
|
||||
|
||||
@@ -200,9 +200,9 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
private DispatcherType dispatcherType = DispatcherType.REQUEST;
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
// Constructors
|
||||
//---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create a new {@code MockHttpServletRequest} with a default
|
||||
@@ -256,9 +256,10 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
this.locales.add(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Lifecycle methods
|
||||
//---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Return the ServletContext that this request is associated with. (Not
|
||||
@@ -302,9 +303,9 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
// ServletRequest interface
|
||||
//---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public Object getAttribute(String name) {
|
||||
@@ -414,8 +415,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter map value must be single value " + " or array of type [" + String.class.getName() +
|
||||
"]");
|
||||
"Parameter map value must be single value " + " or array of type [" + String.class.getName() + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -490,8 +490,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
|
||||
@Override
|
||||
public String getParameter(String name) {
|
||||
Assert.notNull(name, "Parameter name must not be null");
|
||||
String[] arr = this.parameters.get(name);
|
||||
String[] arr = (name != null ? this.parameters.get(name) : null);
|
||||
return (arr != null && arr.length > 0 ? arr[0] : null);
|
||||
}
|
||||
|
||||
@@ -502,8 +501,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
|
||||
@Override
|
||||
public String[] getParameterValues(String name) {
|
||||
Assert.notNull(name, "Parameter name must not be null");
|
||||
return this.parameters.get(name);
|
||||
return (name != null ? this.parameters.get(name) : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -620,7 +618,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
* @since 3.2
|
||||
*/
|
||||
public void setPreferredLocales(List<Locale> locales) {
|
||||
Assert.notEmpty(locales, "preferred locales list must not be empty");
|
||||
Assert.notEmpty(locales, "Locale list must not be empty");
|
||||
this.locales.clear();
|
||||
this.locales.addAll(locales);
|
||||
}
|
||||
@@ -779,7 +777,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
@Override
|
||||
public String getHeader(String name) {
|
||||
HeaderValueHolder header = HeaderValueHolder.getByName(this.headers, name);
|
||||
return (header != null ? header.getValue().toString() : null);
|
||||
return (header != null ? header.getStringValue() : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -867,8 +865,8 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
|
||||
@Override
|
||||
public boolean isUserInRole(String role) {
|
||||
return (this.userRoles.contains(role) || (this.servletContext instanceof MockServletContext && ((MockServletContext) this.servletContext).getDeclaredRoles().contains(
|
||||
role)));
|
||||
return (this.userRoles.contains(role) || (this.servletContext instanceof MockServletContext &&
|
||||
((MockServletContext) this.servletContext).getDeclaredRoles().contains(role)));
|
||||
}
|
||||
|
||||
public void setUserPrincipal(Principal userPrincipal) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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,11 +24,11 @@ import java.io.PrintWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -38,11 +38,9 @@ import org.springframework.util.LinkedCaseInsensitiveMap;
|
||||
import org.springframework.web.util.WebUtils;
|
||||
|
||||
/**
|
||||
* Mock implementation of the {@link javax.servlet.http.HttpServletResponse}
|
||||
* interface. Supports the Servlet 3.0 API level
|
||||
* Mock implementation of the {@link javax.servlet.http.HttpServletResponse} interface.
|
||||
*
|
||||
* <p>Used for testing the web framework; also useful for testing
|
||||
* application controllers.
|
||||
* <p>Compatible with Servlet 2.5 as well as Servlet 3.0.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Rod Johnson
|
||||
@@ -58,6 +56,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
|
||||
|
||||
private static final String LOCATION_HEADER = "Location";
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// ServletResponse properties
|
||||
//---------------------------------------------------------------------
|
||||
@@ -148,7 +147,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
|
||||
private void updateContentTypeHeader() {
|
||||
if (this.contentType != null) {
|
||||
StringBuilder sb = new StringBuilder(this.contentType);
|
||||
if (this.contentType.toLowerCase().indexOf(CHARSET_PREFIX) == -1 && this.charset) {
|
||||
if (!this.contentType.toLowerCase().contains(CHARSET_PREFIX) && this.charset) {
|
||||
sb.append(";").append(CHARSET_PREFIX).append(this.characterEncoding);
|
||||
}
|
||||
doAddHeaderValue(CONTENT_TYPE_HEADER, sb.toString(), true);
|
||||
@@ -319,7 +318,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
|
||||
* @return the {@code Set} of header name {@code Strings}, or an empty {@code Set} if none
|
||||
*/
|
||||
@Override
|
||||
public Set<String> getHeaderNames() {
|
||||
public Collection<String> getHeaderNames() {
|
||||
return this.headers.keySet();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -20,8 +20,8 @@ import com.caucho.burlap.client.BurlapProxyFactory;
|
||||
import com.caucho.hessian.client.HessianProxyFactory;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.tests.sample.beans.ITestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.remoting.RemoteAccessException;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import junit.framework.TestCase;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.tests.sample.beans.ITestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.test.MockHttpServletResponse;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.remoting.jaxws;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
@@ -28,7 +26,6 @@ import javax.xml.ws.WebServiceClient;
|
||||
import javax.xml.ws.WebServiceRef;
|
||||
import javax.xml.ws.soap.AddressingFeature;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.support.GenericBeanDefinition;
|
||||
@@ -36,12 +33,12 @@ import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.context.annotation.AnnotationConfigUtils;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @since 2.5
|
||||
*/
|
||||
// TODO [SPR-10074] see https://gist.github.com/1150858
|
||||
@Ignore("see https://gist.github.com/1150858")
|
||||
public class JaxWsSupportTests {
|
||||
|
||||
@Test
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.http.client;
|
||||
package org.springframework.tests.web;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* The Spring Framework is published under the terms
|
||||
* of the Apache Software License.
|
||||
*/
|
||||
|
||||
package org.springframework.util;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.NotSerializableException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.beans.TestBean;
|
||||
|
||||
/**
|
||||
* Utilities for testing serializability of objects.
|
||||
* Exposes static methods for use in other test cases.
|
||||
* Extends TestCase only to test itself.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
public class SerializationTestUtils extends TestCase {
|
||||
|
||||
public static void testSerialization(Object o) throws IOException {
|
||||
OutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeObject(o);
|
||||
}
|
||||
|
||||
public static boolean isSerializable(Object o) throws IOException {
|
||||
try {
|
||||
testSerialization(o);
|
||||
return true;
|
||||
}
|
||||
catch (NotSerializableException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static Object serializeAndDeserialize(Object o) throws IOException, ClassNotFoundException {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeObject(o);
|
||||
oos.flush();
|
||||
baos.flush();
|
||||
byte[] bytes = baos.toByteArray();
|
||||
|
||||
ByteArrayInputStream is = new ByteArrayInputStream(bytes);
|
||||
ObjectInputStream ois = new ObjectInputStream(is);
|
||||
Object o2 = ois.readObject();
|
||||
|
||||
return o2;
|
||||
}
|
||||
|
||||
public SerializationTestUtils(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
public void testWithNonSerializableObject() throws IOException {
|
||||
TestBean o = new TestBean();
|
||||
assertFalse(o instanceof Serializable);
|
||||
|
||||
assertFalse(isSerializable(o));
|
||||
|
||||
try {
|
||||
testSerialization(o);
|
||||
fail();
|
||||
}
|
||||
catch (NotSerializableException ex) {
|
||||
// Ok
|
||||
}
|
||||
}
|
||||
|
||||
public void testWithSerializableObject() throws Exception {
|
||||
int x = 5;
|
||||
int y = 10;
|
||||
Point p = new Point(x, y);
|
||||
assertTrue(p instanceof Serializable);
|
||||
|
||||
testSerialization(p);
|
||||
|
||||
assertTrue(isSerializable(p));
|
||||
|
||||
Point p2 = (Point) serializeAndDeserialize(p);
|
||||
assertNotSame(p, p2);
|
||||
assertEquals(x, (int) p2.getX());
|
||||
assertEquals(y, (int) p2.getY());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -18,7 +18,7 @@ package org.springframework.web.bind;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.FieldError;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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,10 +24,10 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.tests.sample.beans.ITestBean;
|
||||
import org.springframework.beans.PropertyValue;
|
||||
import org.springframework.beans.PropertyValues;
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -388,6 +388,7 @@ public class ServletRequestUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testGetIntParameterWithDefaultValueHandlingIsFastEnough() {
|
||||
Assume.group(TestGroup.PERFORMANCE);
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
StopWatch sw = new StopWatch();
|
||||
sw.start();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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,10 +24,10 @@ import java.util.Map;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.tests.sample.beans.ITestBean;
|
||||
import org.springframework.beans.PropertyValue;
|
||||
import org.springframework.beans.PropertyValues;
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.test.MockMultipartFile;
|
||||
import org.springframework.mock.web.test.MockMultipartHttpServletRequest;
|
||||
@@ -63,7 +63,7 @@ public class WebRequestDataBinderTests {
|
||||
|
||||
@Test
|
||||
public void testBindingWithNestedObjectCreationThroughAutoGrow() throws Exception {
|
||||
TestBean tb = new TestBean();
|
||||
TestBean tb = new TestBeanWithConcreteSpouse();
|
||||
|
||||
WebRequestDataBinder binder = new WebRequestDataBinder(tb, "person");
|
||||
binder.setIgnoreUnknownFields(false);
|
||||
@@ -305,21 +305,30 @@ public class WebRequestDataBinderTests {
|
||||
|
||||
public static class EnumHolder {
|
||||
|
||||
private MyEnum myEnum;
|
||||
private MyEnum myEnum;
|
||||
|
||||
public MyEnum getMyEnum() {
|
||||
return myEnum;
|
||||
}
|
||||
public MyEnum getMyEnum() {
|
||||
return myEnum;
|
||||
}
|
||||
|
||||
public void setMyEnum(MyEnum myEnum) {
|
||||
this.myEnum = myEnum;
|
||||
}
|
||||
}
|
||||
public void setMyEnum(MyEnum myEnum) {
|
||||
this.myEnum = myEnum;
|
||||
}
|
||||
}
|
||||
|
||||
public enum MyEnum {
|
||||
FOO, BAR
|
||||
}
|
||||
|
||||
public enum MyEnum {
|
||||
static class TestBeanWithConcreteSpouse extends TestBean {
|
||||
public void setConcreteSpouse(TestBean spouse) {
|
||||
this.spouses = new ITestBean[] {spouse};
|
||||
}
|
||||
|
||||
public TestBean getConcreteSpouse() {
|
||||
return (spouses != null ? (TestBean) spouses[0] : null);
|
||||
}
|
||||
}
|
||||
|
||||
FOO, BAR
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -62,8 +62,8 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.client.FreePortScanner;
|
||||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
||||
import org.springframework.tests.web.FreePortScanner;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -21,7 +21,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -18,8 +18,8 @@ package org.springframework.web.context.request;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.beans.DerivedTestBean;
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.tests.sample.beans.DerivedTestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.BeanCurrentlyInCreationException;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -21,10 +21,10 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.DerivedTestBean;
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.beans.factory.DummyFactory;
|
||||
import org.springframework.tests.sample.beans.DerivedTestBean;
|
||||
import org.springframework.tests.sample.beans.ITestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.tests.sample.beans.factory.DummyFactory;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -21,8 +21,8 @@ import java.io.Serializable;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.DerivedTestBean;
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.tests.sample.beans.DerivedTestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -21,7 +21,7 @@ import javax.servlet.ServletContextEvent;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DerivedTestBean;
|
||||
import org.springframework.tests.sample.beans.DerivedTestBean;
|
||||
import org.springframework.beans.factory.support.GenericBeanDefinition;
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.test.MockServletContext;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -18,9 +18,9 @@ package org.springframework.web.context.support;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.tests.sample.beans.ITestBean;
|
||||
import org.springframework.beans.MutablePropertyValues;
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.mock.web.test.MockServletContext;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -22,7 +22,7 @@ import javax.faces.el.VariableResolver;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.support.StaticWebApplicationContext;
|
||||
|
||||
|
||||
@@ -140,29 +140,25 @@ public class InitBinderDataBinderFactoryTests {
|
||||
|
||||
private static class InitBinderHandler {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@InitBinder
|
||||
public void initBinder(WebDataBinder dataBinder) {
|
||||
dataBinder.setDisallowedFields("id");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@InitBinder(value="foo")
|
||||
public void initBinderWithAttributeName(WebDataBinder dataBinder) {
|
||||
dataBinder.setDisallowedFields("id");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@InitBinder
|
||||
public String initBinderReturnValue(WebDataBinder dataBinder) {
|
||||
return "invalid";
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@InitBinder
|
||||
public void initBinderTypeConversion(WebDataBinder dataBinder, @RequestParam int requestParam) {
|
||||
dataBinder.setDisallowedFields("requestParam-" + requestParam);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -23,7 +23,7 @@ import java.lang.reflect.Method;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.validation.BindException;
|
||||
@@ -299,7 +299,6 @@ public class ModelAttributeMethodProcessorTests {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@ModelAttribute("modelAttrName")
|
||||
private String annotatedReturnValue() {
|
||||
return null;
|
||||
@@ -310,4 +309,4 @@ public class ModelAttributeMethodProcessorTests {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ public class RequestParamMethodArgumentResolverTests {
|
||||
private MethodParameter paramMultipartFileList;
|
||||
private MethodParameter paramServlet30Part;
|
||||
private MethodParameter paramRequestPartAnnot;
|
||||
private MethodParameter paramRequired;
|
||||
|
||||
private NativeWebRequest webRequest;
|
||||
|
||||
@@ -80,7 +81,7 @@ public class RequestParamMethodArgumentResolverTests {
|
||||
ParameterNameDiscoverer paramNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
|
||||
|
||||
Method method = getClass().getMethod("params", String.class, String[].class, Map.class, MultipartFile.class,
|
||||
Map.class, String.class, MultipartFile.class, List.class, Part.class, MultipartFile.class);
|
||||
Map.class, String.class, MultipartFile.class, List.class, Part.class, MultipartFile.class, String.class);
|
||||
|
||||
paramNamedDefaultValueString = new MethodParameter(method, 0);
|
||||
paramNamedStringArray = new MethodParameter(method, 1);
|
||||
@@ -96,6 +97,7 @@ public class RequestParamMethodArgumentResolverTests {
|
||||
paramServlet30Part = new MethodParameter(method, 8);
|
||||
paramServlet30Part.initParameterNameDiscovery(paramNameDiscoverer);
|
||||
paramRequestPartAnnot = new MethodParameter(method, 9);
|
||||
paramRequired = new MethodParameter(method, 10);
|
||||
|
||||
request = new MockHttpServletRequest();
|
||||
webRequest = new ServletWebRequest(request, new MockHttpServletResponse());
|
||||
@@ -257,16 +259,41 @@ public class RequestParamMethodArgumentResolverTests {
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
// SPR-10180
|
||||
|
||||
@Test
|
||||
public void resolveEmptyValueToDefault() throws Exception {
|
||||
this.request.addParameter("name", "");
|
||||
Object result = resolver.resolveArgument(paramNamedDefaultValueString, null, webRequest, null);
|
||||
assertEquals("bar", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveEmptyValueWithoutDefault() throws Exception {
|
||||
this.request.addParameter("stringNotAnnot", "");
|
||||
Object result = resolver.resolveArgument(paramStringNotAnnot, null, webRequest, null);
|
||||
assertEquals("", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveEmptyValueRequiredWithoutDefault() throws Exception {
|
||||
this.request.addParameter("name", "");
|
||||
Object result = resolver.resolveArgument(paramRequired, null, webRequest, null);
|
||||
assertEquals("", result);
|
||||
}
|
||||
|
||||
|
||||
public void params(@RequestParam(value = "name", defaultValue = "bar") String param1,
|
||||
@RequestParam("name") String[] param2,
|
||||
@RequestParam("name") Map<?, ?> param3,
|
||||
@RequestParam(value = "file") MultipartFile param4,
|
||||
@RequestParam Map<?, ?> param5,
|
||||
String stringNotAnnot,
|
||||
MultipartFile multipartFileNotAnnot,
|
||||
List<MultipartFile> multipartFileList,
|
||||
Part servlet30Part,
|
||||
@RequestPart MultipartFile requestPartAnnot) {
|
||||
@RequestParam("name") String[] param2,
|
||||
@RequestParam("name") Map<?, ?> param3,
|
||||
@RequestParam(value = "file") MultipartFile param4,
|
||||
@RequestParam Map<?, ?> param5,
|
||||
String stringNotAnnot,
|
||||
MultipartFile multipartFileNotAnnot,
|
||||
List<MultipartFile> multipartFileList,
|
||||
Part servlet30Part,
|
||||
@RequestPart MultipartFile requestPartAnnot,
|
||||
@RequestParam(value = "name") String paramRequired) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -27,7 +27,7 @@ import java.util.HashSet;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.SessionAttributes;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -465,19 +465,11 @@ public class CommonsMultipartResolverTests {
|
||||
this.writtenFile = file;
|
||||
}
|
||||
|
||||
public File getWrittenFile() {
|
||||
return writtenFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() {
|
||||
this.deleted = true;
|
||||
}
|
||||
|
||||
public boolean isDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFieldName() {
|
||||
return fieldName;
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2004-2013 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
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.util;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link JavaScriptUtils}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class JavaScriptUtilsTests {
|
||||
|
||||
@Test
|
||||
public void escape() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append('"');
|
||||
sb.append("'");
|
||||
sb.append("\\");
|
||||
sb.append("/");
|
||||
sb.append("\t");
|
||||
sb.append("\n");
|
||||
sb.append("\r");
|
||||
sb.append("\f");
|
||||
sb.append("\b");
|
||||
sb.append("\013");
|
||||
assertEquals("\\\"\\'\\\\\\/\\t\\n\\n\\f\\b\\v", JavaScriptUtils.javaScriptEscape(sb.toString()));
|
||||
}
|
||||
|
||||
// SPR-9983
|
||||
|
||||
@Test
|
||||
public void escapePsLsLineTerminators() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append('\u2028');
|
||||
sb.append('\u2029');
|
||||
String result = JavaScriptUtils.javaScriptEscape(sb.toString());
|
||||
|
||||
assertEquals("\\u2028\\u2029", result);
|
||||
}
|
||||
|
||||
// SPR-9983
|
||||
|
||||
@Test
|
||||
public void escapeLessThanGreaterThanSigns() throws UnsupportedEncodingException {
|
||||
assertEquals("\\u003C\\u003E", JavaScriptUtils.javaScriptEscape("<>"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2002-2013 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
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/package org.springframework.web.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.mock.web.test.MockServletContext;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Marten Deinum
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public class ServletContextPropertyUtilsTests {
|
||||
|
||||
@Test
|
||||
public void resolveAsServletContextInitParameter() {
|
||||
MockServletContext servletContext = new MockServletContext();
|
||||
servletContext.setInitParameter("test.prop", "bar");
|
||||
String resolved = ServletContextPropertyUtils.resolvePlaceholders("${test.prop:foo}", servletContext);
|
||||
assertEquals(resolved, "bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fallbackToSystemProperties() {
|
||||
MockServletContext servletContext = new MockServletContext();
|
||||
System.setProperty("test.prop", "bar");
|
||||
try {
|
||||
String resolved = ServletContextPropertyUtils.resolvePlaceholders("${test.prop:foo}", servletContext);
|
||||
assertEquals(resolved, "bar");
|
||||
}
|
||||
finally {
|
||||
System.clearProperty("test.prop");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -27,10 +27,12 @@ import org.junit.Test;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class UriComponentsBuilderTests {
|
||||
|
||||
@@ -55,7 +57,9 @@ public class UriComponentsBuilderTests {
|
||||
assertEquals("bar", result.getQuery());
|
||||
assertEquals("baz", result.getFragment());
|
||||
|
||||
URI expected = new URI("/foo?bar#baz");
|
||||
assertEquals("Invalid result URI String", "foo?bar#baz", result.toUriString());
|
||||
|
||||
URI expected = new URI("foo?bar#baz");
|
||||
assertEquals("Invalid result URI", expected, result.toUri());
|
||||
|
||||
result = UriComponentsBuilder.fromPath("/foo").build();
|
||||
@@ -312,4 +316,42 @@ public class UriComponentsBuilderTests {
|
||||
assertEquals("mailto:foo@example.com", result.toUriString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryParamWithValueWithEquals() throws Exception {
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromUriString("http://example.com/foo?bar=baz").build();
|
||||
assertThat(uriComponents.toUriString(), equalTo("http://example.com/foo?bar=baz"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryParamWithoutValueWithEquals() throws Exception {
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromUriString("http://example.com/foo?bar=").build();
|
||||
assertThat(uriComponents.toUriString(), equalTo("http://example.com/foo?bar="));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryParamWithoutValueWithoutEquals() throws Exception {
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromUriString("http://example.com/foo?bar").build();
|
||||
assertThat(uriComponents.toUriString(), equalTo("http://example.com/foo?bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void relativeUrls() throws Exception {
|
||||
assertThat(UriComponentsBuilder.fromUriString("http://example.com/foo/../bar").build().toString(), equalTo("http://example.com/foo/../bar"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("http://example.com/foo/../bar").build().toUriString(), equalTo("http://example.com/foo/../bar"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("http://example.com/foo/../bar").build().toUri().getPath(), equalTo("/foo/../bar"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("../../").build().toString(), equalTo("../../"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("../../").build().toUriString(), equalTo("../../"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("../../").build().toUri().getPath(), equalTo("../../"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("http://example.com").path("foo/../bar").build().toString(), equalTo("http://example.com/foo/../bar"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("http://example.com").path("foo/../bar").build().toUriString(), equalTo("http://example.com/foo/../bar"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("http://example.com").path("foo/../bar").build().toUri().getPath(), equalTo("/foo/../bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptySegments() throws Exception {
|
||||
assertThat(UriComponentsBuilder.fromUriString("http://example.com/abc/").path("/x/y/z").build().toString(), equalTo("http://example.com/abc/x/y/z"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("http://example.com/abc/").pathSegment("x", "y", "z").build().toString(), equalTo("http://example.com/abc/x/y/z"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("http://example.com/abc/").path("/x/").path("/y/z").build().toString(), equalTo("http://example.com/abc/x/y/z"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("http://example.com/abc/").pathSegment("x").path("y").build().toString(), equalTo("http://example.com/abc/x/y"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -16,14 +16,24 @@
|
||||
|
||||
package org.springframework.web.util;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/** @author Arjen Poutsma */
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class UriComponentsTests {
|
||||
|
||||
@Test
|
||||
@@ -75,4 +85,38 @@ public class UriComponentsTests {
|
||||
assertEquals("http://example.com/bar", uriComponents.normalize().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serializable() throws Exception {
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromUriString(
|
||||
"http://example.com").path("/{foo}").query("bar={baz}").build();
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(bos);
|
||||
oos.writeObject(uriComponents);
|
||||
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
|
||||
UriComponents readObject = (UriComponents) ois.readObject();
|
||||
assertThat(uriComponents.toString(), equalTo(readObject.toString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsHierarchicalUriComponents() throws Exception {
|
||||
UriComponents uriComponents1 = UriComponentsBuilder.fromUriString("http://example.com").path("/{foo}").query("bar={baz}").build();
|
||||
UriComponents uriComponents2 = UriComponentsBuilder.fromUriString("http://example.com").path("/{foo}").query("bar={baz}").build();
|
||||
UriComponents uriComponents3 = UriComponentsBuilder.fromUriString("http://example.com").path("/{foo}").query("bin={baz}").build();
|
||||
assertThat(uriComponents1, instanceOf(HierarchicalUriComponents.class));
|
||||
assertThat(uriComponents1, equalTo(uriComponents1));
|
||||
assertThat(uriComponents1, equalTo(uriComponents2));
|
||||
assertThat(uriComponents1, not(equalTo(uriComponents3)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsOpaqueUriComponents() throws Exception {
|
||||
UriComponents uriComponents1 = UriComponentsBuilder.fromUriString("http:example.com/foo/bar").build();
|
||||
UriComponents uriComponents2 = UriComponentsBuilder.fromUriString("http:example.com/foo/bar").build();
|
||||
UriComponents uriComponents3 = UriComponentsBuilder.fromUriString("http:example.com/foo/bin").build();
|
||||
assertThat(uriComponents1, instanceOf(OpaqueUriComponents.class));
|
||||
assertThat(uriComponents1, equalTo(uriComponents1));
|
||||
assertThat(uriComponents1, equalTo(uriComponents2));
|
||||
assertThat(uriComponents1, not(equalTo(uriComponents3)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,35 +4,35 @@
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
|
||||
<bean id="requestScopedObject" class="org.springframework.beans.TestBean" scope="request">
|
||||
<bean id="requestScopedObject" class="org.springframework.tests.sample.beans.TestBean" scope="request">
|
||||
<property name="name" value="#{request.contextPath}"/>
|
||||
</bean>
|
||||
|
||||
<bean id="requestScopedDisposableObject" class="org.springframework.beans.DerivedTestBean" scope="request"/>
|
||||
<bean id="requestScopedDisposableObject" class="org.springframework.tests.sample.beans.DerivedTestBean" scope="request"/>
|
||||
|
||||
<bean id="requestScopedFactoryBean" class="org.springframework.beans.factory.DummyFactory" scope="request"/>
|
||||
<bean id="requestScopedFactoryBean" class="org.springframework.tests.sample.beans.factory.DummyFactory" scope="request"/>
|
||||
|
||||
<bean id="requestScopedObjectCircle1" class="org.springframework.beans.TestBean" scope="request">
|
||||
<bean id="requestScopedObjectCircle1" class="org.springframework.tests.sample.beans.TestBean" scope="request">
|
||||
<property name="spouse" ref="requestScopedObjectCircle2"/>
|
||||
</bean>
|
||||
|
||||
<bean id="requestScopedObjectCircle2" class="org.springframework.beans.TestBean" scope="request">
|
||||
<bean id="requestScopedObjectCircle2" class="org.springframework.tests.sample.beans.TestBean" scope="request">
|
||||
<property name="spouse" ref="requestScopedObjectCircle1"/>
|
||||
</bean>
|
||||
|
||||
<bean id="requestScopedOuterBean" class="org.springframework.beans.DerivedTestBean" scope="request">
|
||||
<bean id="requestScopedOuterBean" class="org.springframework.tests.sample.beans.DerivedTestBean" scope="request">
|
||||
<property name="name" value="outer"/>
|
||||
<property name="spouse">
|
||||
<bean class="org.springframework.beans.DerivedTestBean">
|
||||
<bean class="org.springframework.tests.sample.beans.DerivedTestBean">
|
||||
<property name="name" value="inner"/>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="singletonOuterBean" class="org.springframework.beans.DerivedTestBean" lazy-init="true">
|
||||
<bean id="singletonOuterBean" class="org.springframework.tests.sample.beans.DerivedTestBean" lazy-init="true">
|
||||
<property name="name" value="outer"/>
|
||||
<property name="spouse">
|
||||
<bean class="org.springframework.beans.DerivedTestBean" scope="request">
|
||||
<bean class="org.springframework.tests.sample.beans.DerivedTestBean" scope="request">
|
||||
<property name="name" value="inner"/>
|
||||
</bean>
|
||||
</property>
|
||||
|
||||
@@ -5,47 +5,47 @@
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
|
||||
|
||||
<bean id="requestScopedObject" class="org.springframework.beans.TestBean" scope="request">
|
||||
<bean id="requestScopedObject" class="org.springframework.tests.sample.beans.TestBean" scope="request">
|
||||
<aop:scoped-proxy/>
|
||||
<property name="name" value="scoped"/>
|
||||
</bean>
|
||||
|
||||
<bean id="requestScopedProxy" class="org.springframework.beans.TestBean" scope="request">
|
||||
<bean id="requestScopedProxy" class="org.springframework.tests.sample.beans.TestBean" scope="request">
|
||||
<aop:scoped-proxy proxy-target-class="false"/>
|
||||
<property name="name" value="scoped"/>
|
||||
</bean>
|
||||
|
||||
<bean id="requestScopedDisposableObject" class="org.springframework.beans.DerivedTestBean" scope="request">
|
||||
<bean id="requestScopedDisposableObject" class="org.springframework.tests.sample.beans.DerivedTestBean" scope="request">
|
||||
<aop:scoped-proxy/>
|
||||
<property name="name" value="scoped"/>
|
||||
</bean>
|
||||
|
||||
<bean id="requestScopedFactoryBean" class="org.springframework.beans.factory.DummyFactory" scope="request">
|
||||
<bean id="requestScopedFactoryBean" class="org.springframework.tests.sample.beans.factory.DummyFactory" scope="request">
|
||||
<aop:scoped-proxy/>
|
||||
</bean>
|
||||
|
||||
<bean id="requestScopedObjectCircle1" class="org.springframework.beans.TestBean" scope="request">
|
||||
<bean id="requestScopedObjectCircle1" class="org.springframework.tests.sample.beans.TestBean" scope="request">
|
||||
<aop:scoped-proxy/>
|
||||
<property name="spouse" ref="requestScopedObjectCircle2"/>
|
||||
</bean>
|
||||
|
||||
<bean id="requestScopedObjectCircle2" class="org.springframework.beans.TestBean" scope="request">
|
||||
<bean id="requestScopedObjectCircle2" class="org.springframework.tests.sample.beans.TestBean" scope="request">
|
||||
<aop:scoped-proxy/>
|
||||
<property name="spouse" ref="requestScopedObjectCircle1"/>
|
||||
</bean>
|
||||
|
||||
<bean id="outerBean" class="org.springframework.beans.TestBean">
|
||||
<bean id="outerBean" class="org.springframework.tests.sample.beans.TestBean">
|
||||
<property name="spouse">
|
||||
<bean id="scopedInnerBean" class="org.springframework.beans.TestBean" scope="request">
|
||||
<bean id="scopedInnerBean" class="org.springframework.tests.sample.beans.TestBean" scope="request">
|
||||
<aop:scoped-proxy/>
|
||||
<property name="name" value="scoped"/>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="outerBeanWithAnonymousInner" class="org.springframework.beans.TestBean">
|
||||
<bean id="outerBeanWithAnonymousInner" class="org.springframework.tests.sample.beans.TestBean">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.beans.TestBean" scope="request">
|
||||
<bean class="org.springframework.tests.sample.beans.TestBean" scope="request">
|
||||
<aop:scoped-proxy/>
|
||||
<property name="name" value="scoped"/>
|
||||
</bean>
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user