[
https://issues.apache.org/jira/browse/SCB-529?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16467141#comment-16467141
]
ASF GitHub Bot commented on SCB-529:
------------------------------------
liubao68 closed pull request #690: [SCB-529] producer download file from byte[]
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/690
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/DownloadSchemaIntf.java
b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/DownloadSchemaIntf.java
index 48b9a0f49..93e67ee7e 100644
---
a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/DownloadSchemaIntf.java
+++
b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/DownloadSchemaIntf.java
@@ -33,5 +33,7 @@
ReadStreamPart entityInputStream(String content);
+ ReadStreamPart bytes(String content);
+
ReadStreamPart netInputStream(String content);
}
diff --git
a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestDownload.java
b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestDownload.java
index 6472171ed..c782b6814 100644
---
a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestDownload.java
+++
b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestDownload.java
@@ -117,6 +117,9 @@ public void runRest() {
futures.add(checkFile(intf.entityInputStream(content)));
futures.add(checkFuture(templateGet("entityInputStream").saveAsString()));
+ futures.add(checkFile(intf.bytes(content)));
+ futures.add(checkFuture(templateGet("bytes").saveAsString()));
+
futures.add(checkFile(intf.netInputStream(content)));
futures.add(checkFuture(templateGet("netInputStream").saveAsString()));
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
index c6124d204..563166327 100644
---
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
@@ -157,6 +157,18 @@ public String getFilename() {
.body(new
ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)));
}
+ @GetMapping(path = "/bytes")
+ @ApiResponses({
+ @ApiResponse(code = 200, response = File.class, message = ""),
+ })
+ public ResponseEntity<byte[]> bytes(String content) throws IOException {
+ return ResponseEntity
+ .ok()
+ .header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN_VALUE)
+ .header(HttpHeaders.CONTENT_DISPOSITION,
"attachment;filename=bytes.txt")
+ .body(content.getBytes(StandardCharsets.UTF_8));
+ }
+
@GetMapping(path = "/netInputStream")
@ApiResponses({
@ApiResponse(code = 200, response = File.class, message = ""),
diff --git
a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/converter/impl/part/BytesToPartConverter.java
b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/converter/impl/part/BytesToPartConverter.java
new file mode 100644
index 000000000..44265040e
--- /dev/null
+++
b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/converter/impl/part/BytesToPartConverter.java
@@ -0,0 +1,47 @@
+/*
+ * 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.swagger.invocation.converter.impl.part;
+
+import java.io.ByteArrayInputStream;
+import java.lang.reflect.Type;
+
+import javax.servlet.http.Part;
+
+import org.apache.servicecomb.foundation.common.part.InputStreamPart;
+import org.apache.servicecomb.swagger.invocation.converter.CustomizedConverter;
+import org.springframework.stereotype.Component;
+
+@Component
+public class BytesToPartConverter implements CustomizedConverter {
+ @Override
+ public Type getSrcType() {
+ return byte[].class;
+ }
+
+ @Override
+ public Type getTargetType() {
+ return Part.class;
+ }
+
+ @Override
+ public Object convert(Object value) {
+ // not set name, because not easy to get parameter name in this place
+ // org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl
not depend on the name
+ return new InputStreamPart(null, new ByteArrayInputStream((byte[]) value));
+ }
+}
diff --git
a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/converter/impl/part/TestBytesToPartConverter.java
b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/converter/impl/part/TestBytesToPartConverter.java
new file mode 100644
index 000000000..19fcfa256
--- /dev/null
+++
b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/converter/impl/part/TestBytesToPartConverter.java
@@ -0,0 +1,43 @@
+/*
+ * 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.swagger.invocation.converter.impl.part;
+
+import javax.servlet.http.Part;
+
+import org.hamcrest.Matchers;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestBytesToPartConverter {
+ BytesToPartConverter converter = new BytesToPartConverter();
+
+ @Test
+ public void getSrcType() {
+ Assert.assertSame(byte[].class, converter.getSrcType());
+ }
+
+ @Test
+ public void getTargetType() {
+ Assert.assertEquals(Part.class.getName(),
converter.getTargetType().getTypeName());
+ }
+
+ @Test
+ public void convert() {
+ Object part = converter.convert(new byte[] {});
+ Assert.assertThat(part, Matchers.instanceOf(Part.class));
+ }
+}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> producer download file from byte[]
> ----------------------------------
>
> Key: SCB-529
> URL: https://issues.apache.org/jira/browse/SCB-529
> Project: Apache ServiceComb
> Issue Type: Sub-task
> Components: Java-Chassis
> Reporter: wujimin
> Assignee: wujimin
> Priority: Major
> Fix For: java-chassis-1.0.0-m2
>
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)