This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/master by this push:
new 7cc0ae6 [SCB-2191]download file in servlet context is not deleted
(#2241)
7cc0ae6 is described below
commit 7cc0ae6124288ebf9c1bde4bfda4722b4f1c4ac7
Author: bao liu <[email protected]>
AuthorDate: Sat Feb 20 12:00:14 2021 +0800
[SCB-2191]download file in servlet context is not deleted (#2241)
* [SCB-2191]download file in servlet context is not deleted
* [SCB-2191]add more tests
---
demo/demo-spring-boot-provider/pom.xml | 2 -
.../demo-spring-boot-springmvc-client/pom.xml | 2 +-
.../springmvc/client/SpringmvcClient.java | 2 +-
.../src/main/resources/application.yml | 4 +
.../src/main/resources/certificates/server.p12 | Bin
.../src/main/resources/certificates/trust.jks | Bin
.../springmvc/client/SpringmvcClientIT.java | 0
.../demo-spring-boot-springmvc-server/pom.xml | 2 +-
.../springmvc/server/SpringmvcServer.java | 2 +-
.../src/main/resources/application.yml | 2 +-
.../src/main/resources/certificates/server.p12 | Bin
.../src/main/resources/certificates/trust.jks | Bin
.../src/main/resources/microservice.yaml | 0
demo/demo-spring-boot-transport/pom.xml | 2 +
.../demo/springmvc/client/TestDownloadSchema.java | 58 ++++++++++++++
.../springmvc/client/TestMaxHttpUrlLength.java | 5 +-
.../demo/springmvc/server/DownloadSchema.java | 83 +++++++++++++++++++++
.../springmvc/server/ProducerTestsAfterBootup.java | 2 +-
.../foundation/vertx/stream/PumpFromPart.java | 1 +
19 files changed, 158 insertions(+), 9 deletions(-)
diff --git a/demo/demo-spring-boot-provider/pom.xml
b/demo/demo-spring-boot-provider/pom.xml
index 8ef6f8d..8909c88 100644
--- a/demo/demo-spring-boot-provider/pom.xml
+++ b/demo/demo-spring-boot-provider/pom.xml
@@ -30,8 +30,6 @@
<modules>
<module>demo-spring-boot-jaxrs-server</module>
<module>demo-spring-boot-jaxrs-client</module>
- <module>demo-spring-boot-springmvc-server</module>
- <module>demo-spring-boot-springmvc-client</module>
</modules>
<dependencies>
diff --git
a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-client/pom.xml
b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/pom.xml
similarity index 97%
rename from
demo/demo-spring-boot-provider/demo-spring-boot-springmvc-client/pom.xml
rename to
demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/pom.xml
index 1a43593..9d59e81 100644
--- a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-client/pom.xml
+++ b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/pom.xml
@@ -25,7 +25,7 @@
<name>Java Chassis::Demo::Spring Boot::Spring MVC Client</name>
<parent>
<groupId>org.apache.servicecomb.demo</groupId>
- <artifactId>demo-spring-boot</artifactId>
+ <artifactId>demo-spring-boot-transport</artifactId>
<version>2.2.0-SNAPSHOT</version>
</parent>
<dependencies>
diff --git
a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-client/src/main/java/org/apache/servicecomb/springboot/springmvc/client/SpringmvcClient.java
b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/java/org/apache/servicecomb/springboot/springmvc/client/SpringmvcClient.java
similarity index 96%
rename from
demo/demo-spring-boot-provider/demo-spring-boot-springmvc-client/src/main/java/org/apache/servicecomb/springboot/springmvc/client/SpringmvcClient.java
rename to
demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/java/org/apache/servicecomb/springboot/springmvc/client/SpringmvcClient.java
index aa0358f..5e092d8 100644
---
a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-client/src/main/java/org/apache/servicecomb/springboot/springmvc/client/SpringmvcClient.java
+++
b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/java/org/apache/servicecomb/springboot/springmvc/client/SpringmvcClient.java
@@ -34,7 +34,7 @@ public class SpringmvcClient {
public static void main(final String[] args) throws Exception {
- new
SpringApplicationBuilder().sources(SpringmvcClient.class).web(WebApplicationType.NONE).build().run(args);
+ new
SpringApplicationBuilder().sources(SpringmvcClient.class).web(WebApplicationType.SERVLET).build().run(args);
org.apache.servicecomb.demo.springmvc.client.SpringmvcClient.run();
diff --git
a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-client/src/main/resources/application.yml
b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/resources/application.yml
similarity index 94%
rename from
demo/demo-spring-boot-provider/demo-spring-boot-springmvc-client/src/main/resources/application.yml
rename to
demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/resources/application.yml
index d13e64c..ffd57a8 100644
---
a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-client/src/main/resources/application.yml
+++
b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/resources/application.yml
@@ -17,3 +17,7 @@
server:
port: 8999
+servicecomb:
+ test:
+ vert:
+ transport: false
\ No newline at end of file
diff --git
a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/resources/certificates/server.p12
b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/resources/certificates/server.p12
similarity index 100%
rename from
demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/resources/certificates/server.p12
rename to
demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/resources/certificates/server.p12
diff --git
a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/resources/certificates/trust.jks
b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/resources/certificates/trust.jks
similarity index 100%
rename from
demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/resources/certificates/trust.jks
rename to
demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/resources/certificates/trust.jks
diff --git
a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-client/src/test/java/org/apache/servicecomb/springboot/springmvc/client/SpringmvcClientIT.java
b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/test/java/org/apache/servicecomb/springboot/springmvc/client/SpringmvcClientIT.java
similarity index 100%
rename from
demo/demo-spring-boot-provider/demo-spring-boot-springmvc-client/src/test/java/org/apache/servicecomb/springboot/springmvc/client/SpringmvcClientIT.java
rename to
demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/test/java/org/apache/servicecomb/springboot/springmvc/client/SpringmvcClientIT.java
diff --git
a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/pom.xml
b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/pom.xml
similarity index 98%
rename from
demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/pom.xml
rename to
demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/pom.xml
index b0fb39a..d09227f 100644
--- a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/pom.xml
+++ b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/pom.xml
@@ -25,7 +25,7 @@
<name>Java Chassis::Demo::Spring Boot::Spring MVC Server</name>
<parent>
<groupId>org.apache.servicecomb.demo</groupId>
- <artifactId>demo-spring-boot</artifactId>
+ <artifactId>demo-spring-boot-transport</artifactId>
<version>2.2.0-SNAPSHOT</version>
</parent>
<dependencies>
diff --git
a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/SpringmvcServer.java
b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/SpringmvcServer.java
similarity index 97%
rename from
demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/SpringmvcServer.java
rename to
demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/SpringmvcServer.java
index b369ef8..311bd53 100644
---
a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/SpringmvcServer.java
+++
b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/SpringmvcServer.java
@@ -33,7 +33,7 @@ public class SpringmvcServer {
private static final Logger LOGGER =
LoggerFactory.getLogger(SpringmvcServer.class);
public static void main(final String[] args) throws Exception {
- new
SpringApplicationBuilder().sources(SpringmvcServer.class).web(WebApplicationType.NONE).build().run(args);
+ new
SpringApplicationBuilder().sources(SpringmvcServer.class).web(WebApplicationType.SERVLET).build().run(args);
assertPropertyCorrect();
}
diff --git
a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/resources/application.yml
b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/resources/application.yml
similarity index 92%
rename from
demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/resources/application.yml
rename to
demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/resources/application.yml
index d45f5bc..869e1f5 100644
---
a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/resources/application.yml
+++
b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/resources/application.yml
@@ -16,6 +16,6 @@
## ---------------------------------------------------------------------------
server:
- port: 7999
+ port: 8080
test.unresolved.placeholder: jdbc:postgresql://${ip}:${port}/pt
\ No newline at end of file
diff --git
a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-client/src/main/resources/certificates/server.p12
b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/resources/certificates/server.p12
similarity index 100%
rename from
demo/demo-spring-boot-provider/demo-spring-boot-springmvc-client/src/main/resources/certificates/server.p12
rename to
demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/resources/certificates/server.p12
diff --git
a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-client/src/main/resources/certificates/trust.jks
b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/resources/certificates/trust.jks
similarity index 100%
rename from
demo/demo-spring-boot-provider/demo-spring-boot-springmvc-client/src/main/resources/certificates/trust.jks
rename to
demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/resources/certificates/trust.jks
diff --git
a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/resources/microservice.yaml
b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/resources/microservice.yaml
similarity index 100%
rename from
demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/resources/microservice.yaml
rename to
demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/resources/microservice.yaml
diff --git a/demo/demo-spring-boot-transport/pom.xml
b/demo/demo-spring-boot-transport/pom.xml
index a2cb9e8..2928b9e 100644
--- a/demo/demo-spring-boot-transport/pom.xml
+++ b/demo/demo-spring-boot-transport/pom.xml
@@ -28,6 +28,8 @@
<name>Java Chassis::Demo::Spring Boot::Transport</name>
<packaging>pom</packaging>
<modules>
+ <module>demo-spring-boot-springmvc-server</module>
+ <module>demo-spring-boot-springmvc-client</module>
<module>demo-spring-boot-pojo-server</module>
<module>demo-spring-boot-pojo-client</module>
</modules>
diff --git
a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestDownloadSchema.java
b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestDownloadSchema.java
new file mode 100644
index 0000000..c010278
--- /dev/null
+++
b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestDownloadSchema.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicecomb.demo.springmvc.client;
+
+import org.apache.servicecomb.demo.CategorizedTestCase;
+import org.apache.servicecomb.demo.TestMgr;
+import org.apache.servicecomb.foundation.vertx.http.ReadStreamPart;
+import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
+
+@Component
+public class TestDownloadSchema implements CategorizedTestCase {
+ @Override
+ public void testRestTransport() throws Exception {
+ testDownloadFileAndDeleted();
+ testDownloadFileNotDeleted();
+ }
+
+ private void testDownloadFileAndDeleted() throws Exception {
+ RestTemplate restTemplate = RestTemplateBuilder.create();
+ ReadStreamPart readStreamPart = restTemplate
+
.getForObject("servicecomb://springmvc/download/deleteAfterFinished?content=hello",
ReadStreamPart.class);
+ String hello = readStreamPart.saveAsString().get();
+ TestMgr.check(hello, "hello");
+
+ boolean exists = restTemplate
+
.getForObject("servicecomb://springmvc/download/assertLastFileDeleted",
boolean.class);
+ TestMgr.check(exists, false);
+ }
+
+ private void testDownloadFileNotDeleted() throws Exception {
+ RestTemplate restTemplate = RestTemplateBuilder.create();
+ ReadStreamPart readStreamPart = restTemplate
+
.getForObject("servicecomb://springmvc/download/notDeleteAfterFinished?content=hello",
ReadStreamPart.class);
+ String hello = readStreamPart.saveAsString().get();
+ TestMgr.check(hello, "hello");
+
+ boolean exists = restTemplate
+
.getForObject("servicecomb://springmvc/download/assertLastFileDeleted",
boolean.class);
+ TestMgr.check(exists, true);
+ }
+}
diff --git
a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestMaxHttpUrlLength.java
b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestMaxHttpUrlLength.java
index df3caa7..d696b40 100644
---
a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestMaxHttpUrlLength.java
+++
b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestMaxHttpUrlLength.java
@@ -25,12 +25,15 @@ import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import com.google.common.base.Strings;
+import com.netflix.config.DynamicPropertyFactory;
@Component
public class TestMaxHttpUrlLength implements CategorizedTestCase {
@Override
public void testRestTransport() throws Exception {
- testUrlNotLongerThan4096();
+ if
(DynamicPropertyFactory.getInstance().getBooleanProperty("servicecomb.test.vert.transport",
true).get()) {
+ testUrlNotLongerThan4096();
+ }
}
private void testUrlNotLongerThan4096() {
diff --git
a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/DownloadSchema.java
b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/DownloadSchema.java
new file mode 100644
index 0000000..8f6db6b
--- /dev/null
+++
b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/DownloadSchema.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicecomb.demo.springmvc.server;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.UUID;
+
+import javax.servlet.http.Part;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.servicecomb.foundation.common.part.FilePart;
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+@RestSchema(schemaId = "DownloadSchema")
+@RequestMapping(path = "/download", produces =
MediaType.APPLICATION_JSON_VALUE)
+public class DownloadSchema {
+ private File tempDir = new File("target/downloadTemp");
+
+ private File lastFile;
+
+ private File createTempFile(String content) throws IOException {
+ return createTempFile(null, content);
+ }
+
+ private File createTempFile(String name, String content) throws IOException {
+ if (name == null) {
+ name = "download-" + UUID.randomUUID().toString() + ".txt";
+ }
+ File file = new File(tempDir, name);
+ FileUtils.write(file, content, StandardCharsets.UTF_8, false);
+ lastFile = file;
+ return file;
+ }
+
+ @GetMapping(path = "/deleteAfterFinished")
+ public ResponseEntity<Part> deleteAfterFinished(@RequestParam("content")
String content) throws IOException {
+ File file = createTempFile(content);
+
+ return ResponseEntity
+ .ok()
+ .header(HttpHeaders.CONTENT_DISPOSITION,
"attachment;filename=tempFileEntity.txt")
+ .body(new FilePart(null, file)
+ .setDeleteAfterFinished(true));
+ }
+
+ @GetMapping(path = "/notDeleteAfterFinished")
+ public ResponseEntity<Part> notDeleteAfterFinished(@RequestParam("content")
String content) throws IOException {
+ File file = createTempFile(content);
+
+ return ResponseEntity
+ .ok()
+ .header(HttpHeaders.CONTENT_DISPOSITION,
"attachment;filename=tempFileEntity.txt")
+ .body(new FilePart(null, file));
+ }
+
+ @GetMapping(path = "/assertLastFileDeleted")
+ public boolean assertLastFileDeleted() {
+ return lastFile.exists();
+ }
+}
diff --git
a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerTestsAfterBootup.java
b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerTestsAfterBootup.java
index 9ca48e7..acde805 100644
---
a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerTestsAfterBootup.java
+++
b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerTestsAfterBootup.java
@@ -89,7 +89,7 @@ public class ProducerTestsAfterBootup implements BootListener
{
}
public void testRegisteredBasePath() {
- TestMgr.check(16,
RegistrationManager.INSTANCE.getMicroservice().getPaths().size());
+ TestMgr.check(17,
RegistrationManager.INSTANCE.getMicroservice().getPaths().size());
}
private String getSwaggerContent(Swagger swagger) {
diff --git
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/stream/PumpFromPart.java
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/stream/PumpFromPart.java
index cc147c1..7bcd1d4 100644
---
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/stream/PumpFromPart.java
+++
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/stream/PumpFromPart.java
@@ -93,6 +93,7 @@ public class PumpFromPart {
// otherwise when pump big stream, will cause stack overflow
private CompletableFuture<Void> toOutputStreamSync(OutputStream
outputStream, boolean autoCloseOutputStream) {
CompletableFuture<Void> future = new CompletableFuture<>();
+ future.whenComplete((v, e) -> DownloadUtils.clearPartResource(part));
try (InputStream inputStream = part.getInputStream()) {
IOUtils.copyLarge(inputStream, outputStream);