Merge branch '5.2.x'
This commit is contained in:
@@ -109,7 +109,7 @@ configure(allprojects) { project ->
|
||||
entry 'activemq-stomp'
|
||||
}
|
||||
dependency "org.apache.bcel:bcel:6.0"
|
||||
dependency "org.apache.commons:commons-pool2:2.8.0"
|
||||
dependency "org.apache.commons:commons-pool2:2.8.1"
|
||||
dependencySet(group: 'org.apache.derby', version: '10.14.2.0') {
|
||||
entry 'derby'
|
||||
entry 'derbyclient'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -101,8 +101,7 @@ public class OrderComparator implements Comparator<Object> {
|
||||
Object orderSource = sourceProvider.getOrderSource(obj);
|
||||
if (orderSource != null) {
|
||||
if (orderSource.getClass().isArray()) {
|
||||
Object[] sources = ObjectUtils.toObjectArray(orderSource);
|
||||
for (Object source : sources) {
|
||||
for (Object source : ObjectUtils.toObjectArray(orderSource)) {
|
||||
order = findOrder(source);
|
||||
if (order != null) {
|
||||
break;
|
||||
|
||||
@@ -256,7 +256,7 @@ public class DefaultStompSession implements ConnectionHandlingStompSession {
|
||||
private Message<byte[]> createMessage(StompHeaderAccessor accessor, @Nullable Object payload) {
|
||||
accessor.updateSimpMessageHeadersFromStompHeaders();
|
||||
Message<byte[]> message;
|
||||
if (isEmpty(payload)) {
|
||||
if (StringUtils.isEmpty(payload) || (payload instanceof byte[] && ((byte[]) payload).length == 0)) {
|
||||
message = MessageBuilder.createMessage(EMPTY_PAYLOAD, accessor.getMessageHeaders());
|
||||
}
|
||||
else {
|
||||
@@ -271,10 +271,6 @@ public class DefaultStompSession implements ConnectionHandlingStompSession {
|
||||
return message;
|
||||
}
|
||||
|
||||
private boolean isEmpty(@Nullable Object payload) {
|
||||
return (StringUtils.isEmpty(payload) || (payload instanceof byte[] && ((byte[]) payload).length == 0));
|
||||
}
|
||||
|
||||
private void execute(Message<byte[]> message) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -26,7 +26,7 @@ import org.springframework.web.multipart.MultipartResolver;
|
||||
*
|
||||
* <p>This may be because the request is not a multipart/form-data request,
|
||||
* because the part is not present in the request, or because the web
|
||||
* application is not configured correctly for processing multipart requests,
|
||||
* application is not configured correctly for processing multipart requests,
|
||||
* e.g. no {@link MultipartResolver}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
@@ -35,17 +35,24 @@ import org.springframework.web.multipart.MultipartResolver;
|
||||
@SuppressWarnings("serial")
|
||||
public class MissingServletRequestPartException extends ServletException {
|
||||
|
||||
private final String partName;
|
||||
private final String requestPartName;
|
||||
|
||||
|
||||
public MissingServletRequestPartException(String partName) {
|
||||
super("Required request part '" + partName + "' is not present");
|
||||
this.partName = partName;
|
||||
/**
|
||||
* Constructor for MissingServletRequestPartException.
|
||||
* @param requestPartName the name of the missing part of the multipart request
|
||||
*/
|
||||
public MissingServletRequestPartException(String requestPartName) {
|
||||
super("Required request part '" + requestPartName + "' is not present");
|
||||
this.requestPartName = requestPartName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the name of the offending part of the multipart request.
|
||||
*/
|
||||
public String getRequestPartName() {
|
||||
return this.partName;
|
||||
return this.requestPartName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2020 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,11 +22,13 @@ import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.Part;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServletServerHttpRequest;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.web.multipart.MultipartException;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
@@ -46,58 +48,75 @@ public class RequestPartServletServerHttpRequest extends ServletServerHttpReques
|
||||
|
||||
private final MultipartHttpServletRequest multipartRequest;
|
||||
|
||||
private final String partName;
|
||||
private final String requestPartName;
|
||||
|
||||
private final HttpHeaders headers;
|
||||
private final HttpHeaders multipartHeaders;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new {@code RequestPartServletServerHttpRequest} instance.
|
||||
* @param request the current servlet request
|
||||
* @param partName the name of the part to adapt to the {@link ServerHttpRequest} contract
|
||||
* @param requestPartName the name of the part to adapt to the {@link ServerHttpRequest} contract
|
||||
* @throws MissingServletRequestPartException if the request part cannot be found
|
||||
* @throws MultipartException if MultipartHttpServletRequest cannot be initialized
|
||||
*/
|
||||
public RequestPartServletServerHttpRequest(HttpServletRequest request, String partName)
|
||||
public RequestPartServletServerHttpRequest(HttpServletRequest request, String requestPartName)
|
||||
throws MissingServletRequestPartException {
|
||||
|
||||
super(request);
|
||||
|
||||
this.multipartRequest = MultipartResolutionDelegate.asMultipartHttpServletRequest(request);
|
||||
this.partName = partName;
|
||||
this.requestPartName = requestPartName;
|
||||
|
||||
HttpHeaders headers = this.multipartRequest.getMultipartHeaders(this.partName);
|
||||
if (headers == null) {
|
||||
throw new MissingServletRequestPartException(partName);
|
||||
HttpHeaders multipartHeaders = this.multipartRequest.getMultipartHeaders(this.requestPartName);
|
||||
if (multipartHeaders == null) {
|
||||
throw new MissingServletRequestPartException(requestPartName);
|
||||
}
|
||||
this.headers = headers;
|
||||
this.multipartHeaders = multipartHeaders;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public HttpHeaders getHeaders() {
|
||||
return this.headers;
|
||||
return this.multipartHeaders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getBody() throws IOException {
|
||||
// Prefer Servlet Part resolution to cover file as well as parameter streams
|
||||
if (this.multipartRequest instanceof StandardMultipartHttpServletRequest) {
|
||||
try {
|
||||
return this.multipartRequest.getPart(this.partName).getInputStream();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new MultipartException("Could not parse multipart servlet request", ex);
|
||||
Part part = retrieveServletPart();
|
||||
if (part != null) {
|
||||
return part.getInputStream();
|
||||
}
|
||||
}
|
||||
else {
|
||||
MultipartFile file = this.multipartRequest.getFile(this.partName);
|
||||
if (file != null) {
|
||||
return file.getInputStream();
|
||||
}
|
||||
else {
|
||||
String paramValue = this.multipartRequest.getParameter(this.partName);
|
||||
return new ByteArrayInputStream(paramValue.getBytes(determineCharset()));
|
||||
}
|
||||
|
||||
// Spring-style distinction between MultipartFile and String parameters
|
||||
MultipartFile file = this.multipartRequest.getFile(this.requestPartName);
|
||||
if (file != null) {
|
||||
return file.getInputStream();
|
||||
}
|
||||
String paramValue = this.multipartRequest.getParameter(this.requestPartName);
|
||||
if (paramValue != null) {
|
||||
return new ByteArrayInputStream(paramValue.getBytes(determineCharset()));
|
||||
}
|
||||
|
||||
// Fallback: Servlet Part resolution even if not indicated
|
||||
Part part = retrieveServletPart();
|
||||
if (part != null) {
|
||||
return part.getInputStream();
|
||||
}
|
||||
|
||||
throw new IllegalStateException("No body available for request part '" + this.requestPartName + "'");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Part retrieveServletPart() {
|
||||
try {
|
||||
return this.multipartRequest.getPart(this.requestPartName);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new MultipartException("Failed to retrieve request part '" + this.requestPartName + "'", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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,11 +32,13 @@ import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.testfixture.servlet.MockMultipartFile;
|
||||
import org.springframework.web.testfixture.servlet.MockMultipartHttpServletRequest;
|
||||
import org.springframework.web.testfixture.servlet.MockPart;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class RequestPartServletServerHttpRequestTests {
|
||||
|
||||
@@ -137,4 +139,17 @@ public class RequestPartServletServerHttpRequestTests {
|
||||
assertThat(result).isEqualTo(bytes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBodyViaRequestPart() throws Exception {
|
||||
byte[] bytes = "content".getBytes("UTF-8");
|
||||
MockPart mockPart = new MockPart("part", bytes);
|
||||
mockPart.getHeaders().setContentType(MediaType.APPLICATION_JSON);
|
||||
mockRequest.addPart(mockPart);
|
||||
this.mockRequest.addPart(mockPart);
|
||||
ServerHttpRequest request = new RequestPartServletServerHttpRequest(this.mockRequest, "part");
|
||||
|
||||
byte[] result = FileCopyUtils.copyToByteArray(request.getBody());
|
||||
assertThat(result).isEqualTo(bytes);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user