You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ni...@apache.org on 2017/12/22 03:16:02 UTC
[incubator-servicecomb-java-chassis] 06/11: JAV-548 pojo consumer
support file upload
This is an automated email from the ASF dual-hosted git repository.
ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git
commit cde845059e3b65788cc8b504d059956ddb45c86f
Author: wujimin <wu...@huawei.com>
AuthorDate: Wed Dec 13 15:53:05 2017 +0800
JAV-548 pojo consumer support file upload
---
.../converter/impl/part/FileToPartConverter.java | 48 ++++++++++++++++++++++
.../impl/part/InputStreamToPartConverter.java | 48 ++++++++++++++++++++++
.../impl/part/ResourceToPartConverter.java | 48 ++++++++++++++++++++++
.../impl/part/TestFileToPartConverter.java | 47 +++++++++++++++++++++
.../impl/part/TestInputStreamToPartConverter.java | 47 +++++++++++++++++++++
.../impl/part/TestResourceToPartConverter.java | 48 ++++++++++++++++++++++
6 files changed, 286 insertions(+)
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/converter/impl/part/FileToPartConverter.java b/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/converter/impl/part/FileToPartConverter.java
new file mode 100644
index 0000000..d6a7c4a
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/converter/impl/part/FileToPartConverter.java
@@ -0,0 +1,48 @@
+/*
+ * 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 io.servicecomb.swagger.invocation.converter.impl.part;
+
+import java.io.File;
+import java.lang.reflect.Type;
+
+import javax.servlet.http.Part;
+
+import org.springframework.stereotype.Component;
+
+import io.servicecomb.foundation.common.part.FilePart;
+import io.servicecomb.swagger.invocation.converter.CustomizedConverter;
+
+@Component
+public class FileToPartConverter implements CustomizedConverter {
+ @Override
+ public Type getSrcType() {
+ return File.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
+ // io.servicecomb.common.rest.codec.param.RestClientRequestImpl not depend on the name
+ return new FilePart(null, (File) value);
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/converter/impl/part/InputStreamToPartConverter.java b/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/converter/impl/part/InputStreamToPartConverter.java
new file mode 100644
index 0000000..90aeded
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/converter/impl/part/InputStreamToPartConverter.java
@@ -0,0 +1,48 @@
+/*
+ * 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 io.servicecomb.swagger.invocation.converter.impl.part;
+
+import java.io.InputStream;
+import java.lang.reflect.Type;
+
+import javax.servlet.http.Part;
+
+import org.springframework.stereotype.Component;
+
+import io.servicecomb.foundation.common.part.InputStreamPart;
+import io.servicecomb.swagger.invocation.converter.CustomizedConverter;
+
+@Component
+public class InputStreamToPartConverter implements CustomizedConverter {
+ @Override
+ public Type getSrcType() {
+ return InputStream.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
+ // io.servicecomb.common.rest.codec.param.RestClientRequestImpl not depend on the name
+ return new InputStreamPart(null, (InputStream) value);
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/converter/impl/part/ResourceToPartConverter.java b/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/converter/impl/part/ResourceToPartConverter.java
new file mode 100644
index 0000000..273e1a5
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/converter/impl/part/ResourceToPartConverter.java
@@ -0,0 +1,48 @@
+/*
+ * 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 io.servicecomb.swagger.invocation.converter.impl.part;
+
+import java.lang.reflect.Type;
+
+import javax.servlet.http.Part;
+
+import org.springframework.core.io.Resource;
+import org.springframework.stereotype.Component;
+
+import io.servicecomb.foundation.common.part.ResourcePart;
+import io.servicecomb.swagger.invocation.converter.CustomizedConverter;
+
+@Component
+public class ResourceToPartConverter implements CustomizedConverter {
+ @Override
+ public Type getSrcType() {
+ return Resource.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
+ // io.servicecomb.common.rest.codec.param.RestClientRequestImpl not depend on the name
+ return new ResourcePart(null, (Resource) value);
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/io/servicecomb/swagger/invocation/converter/impl/part/TestFileToPartConverter.java b/swagger/swagger-invocation/invocation-core/src/test/java/io/servicecomb/swagger/invocation/converter/impl/part/TestFileToPartConverter.java
new file mode 100644
index 0000000..934d240
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/io/servicecomb/swagger/invocation/converter/impl/part/TestFileToPartConverter.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 io.servicecomb.swagger.invocation.converter.impl.part;
+
+import java.io.File;
+
+import javax.servlet.http.Part;
+
+import org.hamcrest.Matchers;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestFileToPartConverter {
+ FileToPartConverter converter = new FileToPartConverter();
+
+ @Test
+ public void getSrcType() {
+ Assert.assertEquals(File.class.getName(), converter.getSrcType().getTypeName());
+ }
+
+ @Test
+ public void getTargetType() {
+ Assert.assertEquals(Part.class.getName(), converter.getTargetType().getTypeName());
+ }
+
+ @Test
+ public void convert() {
+ File file = new File("abc");
+ Object part = converter.convert(file);
+ Assert.assertThat(part, Matchers.instanceOf(Part.class));
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/io/servicecomb/swagger/invocation/converter/impl/part/TestInputStreamToPartConverter.java b/swagger/swagger-invocation/invocation-core/src/test/java/io/servicecomb/swagger/invocation/converter/impl/part/TestInputStreamToPartConverter.java
new file mode 100644
index 0000000..b288c12
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/io/servicecomb/swagger/invocation/converter/impl/part/TestInputStreamToPartConverter.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 io.servicecomb.swagger.invocation.converter.impl.part;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import javax.servlet.http.Part;
+
+import org.hamcrest.Matchers;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestInputStreamToPartConverter {
+ InputStreamToPartConverter converter = new InputStreamToPartConverter();
+
+ @Test
+ public void getSrcType() {
+ Assert.assertEquals(InputStream.class.getName(), converter.getSrcType().getTypeName());
+ }
+
+ @Test
+ public void getTargetType() {
+ Assert.assertEquals(Part.class.getName(), converter.getTargetType().getTypeName());
+ }
+
+ @Test
+ public void convert() {
+ Object part = converter.convert(new ByteArrayInputStream(new byte[] {}));
+ Assert.assertThat(part, Matchers.instanceOf(Part.class));
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/io/servicecomb/swagger/invocation/converter/impl/part/TestResourceToPartConverter.java b/swagger/swagger-invocation/invocation-core/src/test/java/io/servicecomb/swagger/invocation/converter/impl/part/TestResourceToPartConverter.java
new file mode 100644
index 0000000..8aa9c8b
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/io/servicecomb/swagger/invocation/converter/impl/part/TestResourceToPartConverter.java
@@ -0,0 +1,48 @@
+/*
+ * 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 io.servicecomb.swagger.invocation.converter.impl.part;
+
+import java.io.ByteArrayInputStream;
+
+import javax.servlet.http.Part;
+
+import org.hamcrest.Matchers;
+import org.junit.Assert;
+import org.junit.Test;
+import org.springframework.core.io.InputStreamResource;
+import org.springframework.core.io.Resource;
+
+public class TestResourceToPartConverter {
+ ResourceToPartConverter converter = new ResourceToPartConverter();
+
+ @Test
+ public void getSrcType() {
+ Assert.assertEquals(Resource.class.getName(), converter.getSrcType().getTypeName());
+ }
+
+ @Test
+ public void getTargetType() {
+ Assert.assertEquals(Part.class.getName(), converter.getTargetType().getTypeName());
+ }
+
+ @Test
+ public void convert() {
+ Object part = converter.convert(new InputStreamResource(new ByteArrayInputStream(new byte[] {})));
+ Assert.assertThat(part, Matchers.instanceOf(Part.class));
+ }
+}
--
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.