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:15:56 UTC

[incubator-servicecomb-java-chassis] branch master updated (704214d -> 11d1b17)

This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git.


    from 704214d  [JAV-584]fallback logic optimize
     new 887ab2a  JAV-548 fix springmvc upload bug, avoid getBytes not closed inputStream
     new 1c9e31d  JAV-548 fix springmvc upload bug, avoid sample not close inputstream
     new 5bb158f  JAV-548 do not use part.getName() to get parameter name, because pojo consumer not easy to set name to part
     new 70afebd  JAV-548 change upload directory from "." to "target"
     new fdcede6  JAV-548 move part implementations to foundation-common, and add UT
     new cde8450  JAV-548 pojo consumer support file upload
     new 50ecefd  JAV-548 add demo for pojo consumer invoke file upload
     new 28f0743  JAV-548 producer support Part to be input parameter
     new e738251  JAV-548 change demo springmvc-server, one input parameter changed from MultipartFile to Part
     new 7ffe244  update license in code-templates.xml
     new 11d1b17  modify license problems

The 11 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../rest/codec/param/RestClientRequestImpl.java    |  13 +-
 ...servicecomb.common.rest.filter.HttpServerFilter |  17 --
 .../client/CodeFirstRestTemplateSpringmvc.java     |  34 +++-
 .../demo/springmvc/server/CodeFirstSpringmvc.java  |   5 +-
 .../src/main/resources/microservice.yaml           |   2 +-
 ...ecomb.serviceregistry.discovery.DiscoveryFilter |  17 --
 etc/code-templates.xml                             |  13 +-
 foundations/foundation-common/pom.xml              |   4 +
 .../foundation/common}/part/AbstractPart.java      |   2 +-
 .../foundation/common}/part/FilePart.java          |   2 +-
 .../foundation/common}/part/InputStreamPart.java   |   2 +-
 .../foundation/common}/part/ResourcePart.java      |   2 +-
 .../foundation/common/part/TestAbstractPart.java   | 116 +++++++++++++
 .../foundation/common/part/TestFilePart.java       |  76 +++++++++
 .../common/part/TestInputStreamPart.java           |  33 ++--
 .../foundation/common/part/TestResourcePart.java}  |  32 ++--
 ...rvicecomb.foundation.common.utils.SPIServiceDef |  34 +---
 ...comb.config.spi.ConfigCenterConfigurationSource |  35 +---
 ...comb.config.spi.ConfigCenterConfigurationSource |  34 +---
 foundations/foundation-vertx/pom.xml               |   4 -
 .../VertxServerRequestToHttpServletRequest.java    |   3 +-
 integration-tests/springmvc-tests/pom.xml          |   4 -
 .../tests/endpoints/CodeFirstSpringmvcBase.java    |   5 +-
 .../reference/CommonToHttpServletRequest.java      |   6 +-
 .../swagger/extend/ModelResolverExt.java           |   2 +
 ...opertyCreator.java => PartPropertyCreator.java} |  11 +-
 .../property/creator/TestPartPropertyCreator.java  |  24 +--
 .../converter/impl/part/FileToPartConverter.java   |  30 ++--
 .../impl/part/InputStreamToPartConverter.java      |  29 ++--
 .../impl/part/ResourceToPartConverter.java         |  29 ++--
 .../impl/part/TestFileToPartConverter.java         |  26 ++-
 .../impl/part/TestInputStreamToPartConverter.java  |  26 ++-
 .../impl/part/TestResourceToPartConverter.java     |  37 ++--
 .../invocation/converter/PartToMultipartFile.java  |  62 +++----
 .../converter/SpringMultipartConverter.java        |  47 +-----
 .../converter/TestPartToMultipartFile.java         | 186 +++++++++++++++++++++
 36 files changed, 642 insertions(+), 362 deletions(-)
 copy foundations/{foundation-vertx/src/main/java/io/servicecomb/foundation/vertx => foundation-common/src/main/java/io/servicecomb/foundation/common}/part/AbstractPart.java (97%)
 rename foundations/{foundation-vertx/src/main/java/io/servicecomb/foundation/vertx => foundation-common/src/main/java/io/servicecomb/foundation/common}/part/FilePart.java (97%)
 rename foundations/{foundation-vertx/src/main/java/io/servicecomb/foundation/vertx => foundation-common/src/main/java/io/servicecomb/foundation/common}/part/InputStreamPart.java (95%)
 copy foundations/{foundation-vertx/src/main/java/io/servicecomb/foundation/vertx => foundation-common/src/main/java/io/servicecomb/foundation/common}/part/ResourcePart.java (96%)
 create mode 100644 foundations/foundation-common/src/test/java/io/servicecomb/foundation/common/part/TestAbstractPart.java
 create mode 100644 foundations/foundation-common/src/test/java/io/servicecomb/foundation/common/part/TestFilePart.java
 copy providers/provider-springmvc/src/test/java/io/servicecomb/provider/springmvc/reference/TestCseClientHttpRequestFactory.java => foundations/foundation-common/src/test/java/io/servicecomb/foundation/common/part/TestInputStreamPart.java (58%)
 rename foundations/{foundation-vertx/src/main/java/io/servicecomb/foundation/vertx/part/ResourcePart.java => foundation-common/src/test/java/io/servicecomb/foundation/common/part/TestResourcePart.java} (57%)
 copy swagger/swagger-generator/generator-core/src/main/java/io/servicecomb/swagger/extend/property/creator/{ShortPropertyCreator.java => PartPropertyCreator.java} (82%)
 copy service-registry/src/test/java/io/servicecomb/serviceregistry/version/TestVersionRuleFixedParser.java => swagger/swagger-generator/generator-core/src/test/java/io/servicecomb/swagger/extend/property/creator/TestPartPropertyCreator.java (62%)
 copy handlers/handler-bizkeeper/src/main/java/io/servicecomb/bizkeeper/ReturnNullFallbackPolicy.java => swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/converter/impl/part/FileToPartConverter.java (55%)
 copy providers/provider-rest-common/src/main/java/io/servicecomb/provider/rest/common/ProducerHttpRequestArgMapperFactory.java => swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/converter/impl/part/InputStreamToPartConverter.java (54%)
 copy providers/provider-rest-common/src/main/java/io/servicecomb/provider/rest/common/ProducerHttpRequestArgMapperFactory.java => swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/converter/impl/part/ResourceToPartConverter.java (54%)
 copy transports/transport-highway/src/test/java/io/servicecomb/transport/highway/TestHighwayConfig.java => swagger/swagger-invocation/invocation-core/src/test/java/io/servicecomb/swagger/invocation/converter/impl/part/TestFileToPartConverter.java (57%)
 copy transports/transport-highway/src/test/java/io/servicecomb/transport/highway/TestHighwayConfig.java => swagger/swagger-invocation/invocation-core/src/test/java/io/servicecomb/swagger/invocation/converter/impl/part/TestInputStreamToPartConverter.java (55%)
 copy foundations/foundation-common/src/test/java/io/servicecomb/foundation/common/http/TestHttpStatusUtils.java => swagger/swagger-invocation/invocation-core/src/test/java/io/servicecomb/swagger/invocation/converter/impl/part/TestResourceToPartConverter.java (52%)
 rename foundations/foundation-vertx/src/main/java/io/servicecomb/foundation/vertx/part/AbstractPart.java => swagger/swagger-invocation/invocation-springmvc/src/main/java/io/servicecomb/swagger/invocation/converter/PartToMultipartFile.java (51%)
 create mode 100644 swagger/swagger-invocation/invocation-springmvc/src/test/java/io/servicecomb/swagger/invocation/converter/TestPartToMultipartFile.java

-- 
To stop receiving notification emails like this one, please contact
['"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>'].

[incubator-servicecomb-java-chassis] 03/11: JAV-548 do not use part.getName() to get parameter name, because pojo consumer not easy to set name to part

Posted by ni...@apache.org.
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 5bb158f649f2c2640c878e2cdec81066b7ece2f7
Author: wujimin <wu...@huawei.com>
AuthorDate: Wed Dec 13 10:50:26 2017 +0800

    JAV-548 do not use part.getName() to get parameter name, because pojo consumer not easy to set name to part
---
 .../common/rest/codec/param/RestClientRequestImpl.java      | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/common/common-rest/src/main/java/io/servicecomb/common/rest/codec/param/RestClientRequestImpl.java b/common/common-rest/src/main/java/io/servicecomb/common/rest/codec/param/RestClientRequestImpl.java
index 19d6f4f..2eda363 100644
--- a/common/common-rest/src/main/java/io/servicecomb/common/rest/codec/param/RestClientRequestImpl.java
+++ b/common/common-rest/src/main/java/io/servicecomb/common/rest/codec/param/RestClientRequestImpl.java
@@ -153,21 +153,22 @@ public class RestClientRequestImpl implements RestClientRequest {
   }
 
   private void attachFiles(String boundary) {
-    Iterator<Part> uploadsIterator = uploads.values().iterator();
+    Iterator<Entry<String, Part>> uploadsIterator = uploads.entrySet().iterator();
     attachFile(boundary, uploadsIterator);
   }
 
-  private void attachFile(String boundary, Iterator<Part> uploadsIterator) {
+  private void attachFile(String boundary, Iterator<Entry<String, Part>> uploadsIterator) {
     if (!uploadsIterator.hasNext()) {
       request.write(boundaryEndInfo(boundary));
       request.end();
       return;
     }
 
-    // maybe it's a memory file, now we do not support this
-    // not easy to wrapping inputstream to readStream
-    Part part = uploadsIterator.next();
-    String name = part.getName();
+    Entry<String, Part> entry = uploadsIterator.next();
+    // do not use part.getName() to get parameter name
+    // because pojo consumer not easy to set name to part
+    String name = entry.getKey();
+    Part part = entry.getValue();
     String filename = part.getSubmittedFileName();
 
     InputStreamToReadStream fileStream = null;

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.

[incubator-servicecomb-java-chassis] 11/11: modify license problems

Posted by ni...@apache.org.
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 11d1b170b5afbaba9cfc4d395d1f0f4fbdcede6a
Author: wujimin <wu...@huawei.com>
AuthorDate: Wed Dec 20 22:13:17 2017 +0800

    modify license problems
---
 ...servicecomb.common.rest.filter.HttpServerFilter | 17 -----------
 ...ecomb.serviceregistry.discovery.DiscoveryFilter | 17 -----------
 ...rvicecomb.foundation.common.utils.SPIServiceDef | 34 +--------------------
 ...comb.config.spi.ConfigCenterConfigurationSource | 35 +---------------------
 ...comb.config.spi.ConfigCenterConfigurationSource | 34 +--------------------
 5 files changed, 3 insertions(+), 134 deletions(-)

diff --git a/demo/demo-signature/src/main/resources/META-INF/services/io.servicecomb.common.rest.filter.HttpServerFilter b/demo/demo-signature/src/main/resources/META-INF/services/io.servicecomb.common.rest.filter.HttpServerFilter
index ff16ac0..4012604 100644
--- a/demo/demo-signature/src/main/resources/META-INF/services/io.servicecomb.common.rest.filter.HttpServerFilter
+++ b/demo/demo-signature/src/main/resources/META-INF/services/io.servicecomb.common.rest.filter.HttpServerFilter
@@ -15,21 +15,4 @@
 # limitations under the License.
 #
 
-#
-# 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.
-#
-
 io.servicecomb.demo.signature.ServerSignature
diff --git a/edge/edge-core/src/main/resources/META-INF/services/io.servicecomb.serviceregistry.discovery.DiscoveryFilter b/edge/edge-core/src/main/resources/META-INF/services/io.servicecomb.serviceregistry.discovery.DiscoveryFilter
index 75bbb9f..aa61b93 100644
--- a/edge/edge-core/src/main/resources/META-INF/services/io.servicecomb.serviceregistry.discovery.DiscoveryFilter
+++ b/edge/edge-core/src/main/resources/META-INF/services/io.servicecomb.serviceregistry.discovery.DiscoveryFilter
@@ -15,21 +15,4 @@
 # limitations under the License.
 #
 
-#
-# 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.
-#
-
 io.servicecomb.edge.core.OperationInstancesDiscoveryFilter
diff --git a/foundations/foundation-common/src/test/resources/META-INF/services/io.servicecomb.foundation.common.utils.SPIServiceDef b/foundations/foundation-common/src/test/resources/META-INF/services/io.servicecomb.foundation.common.utils.SPIServiceDef
index 777ab26..59b7cd5 100644
--- a/foundations/foundation-common/src/test/resources/META-INF/services/io.servicecomb.foundation.common.utils.SPIServiceDef
+++ b/foundations/foundation-common/src/test/resources/META-INF/services/io.servicecomb.foundation.common.utils.SPIServiceDef
@@ -15,37 +15,5 @@
 # limitations under the License.
 #
 
-#
-# 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.
-#
-
-#
-# Copyright 2017 Huawei Technologies Co., Ltd
-#
-# 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.
-#
 
-io.servicecomb.foundation.common.utils.SPIServiceDefImpl
+io.servicecomb.foundation.common.utils.SPIServiceDefImpl
\ No newline at end of file
diff --git a/foundations/foundation-config-cc/src/main/resources/META-INF/services/io.servicecomb.config.spi.ConfigCenterConfigurationSource b/foundations/foundation-config-cc/src/main/resources/META-INF/services/io.servicecomb.config.spi.ConfigCenterConfigurationSource
index e1355f5..55043eb 100644
--- a/foundations/foundation-config-cc/src/main/resources/META-INF/services/io.servicecomb.config.spi.ConfigCenterConfigurationSource
+++ b/foundations/foundation-config-cc/src/main/resources/META-INF/services/io.servicecomb.config.spi.ConfigCenterConfigurationSource
@@ -15,37 +15,4 @@
 # limitations under the License.
 #
 
-#
-# 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.
-#
-
-#
-# Copyright 2017 Huawei Technologies Co., Ltd
-#
-# 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.
-#
-
-io.servicecomb.config.archaius.sources.ConfigCenterConfigurationSourceImpl
+io.servicecomb.config.archaius.sources.ConfigCenterConfigurationSourceImpl
\ No newline at end of file
diff --git a/foundations/foundation-config/src/test/resources/META-INF/services/io.servicecomb.config.spi.ConfigCenterConfigurationSource b/foundations/foundation-config/src/test/resources/META-INF/services/io.servicecomb.config.spi.ConfigCenterConfigurationSource
index af0fbec..dc9585f 100644
--- a/foundations/foundation-config/src/test/resources/META-INF/services/io.servicecomb.config.spi.ConfigCenterConfigurationSource
+++ b/foundations/foundation-config/src/test/resources/META-INF/services/io.servicecomb.config.spi.ConfigCenterConfigurationSource
@@ -15,37 +15,5 @@
 # limitations under the License.
 #
 
-#
-# 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.
-#
-
-#
-# Copyright 2017 Huawei Technologies Co., Ltd
-#
-# 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.
-#
 
-io.servicecomb.config.MapBasedConfigurationSource
+io.servicecomb.config.MapBasedConfigurationSource
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.

[incubator-servicecomb-java-chassis] 08/11: JAV-548 producer support Part to be input parameter

Posted by ni...@apache.org.
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 28f074310751a4363b05e60a17dfcb71c7cf7241
Author: wujimin <wu...@huawei.com>
AuthorDate: Thu Dec 14 08:41:53 2017 +0800

    JAV-548 producer support Part to be input parameter
---
 .../swagger/extend/ModelResolverExt.java           |  2 ++
 .../property/creator/PartPropertyCreator.java      | 37 +++++++++++++++++++
 .../property/creator/TestPartPropertyCreator.java  | 42 ++++++++++++++++++++++
 3 files changed, 81 insertions(+)

diff --git a/swagger/swagger-generator/generator-core/src/main/java/io/servicecomb/swagger/extend/ModelResolverExt.java b/swagger/swagger-generator/generator-core/src/main/java/io/servicecomb/swagger/extend/ModelResolverExt.java
index 3dfb227..0044a8d 100644
--- a/swagger/swagger-generator/generator-core/src/main/java/io/servicecomb/swagger/extend/ModelResolverExt.java
+++ b/swagger/swagger-generator/generator-core/src/main/java/io/servicecomb/swagger/extend/ModelResolverExt.java
@@ -35,6 +35,7 @@ import io.servicecomb.swagger.converter.property.StringPropertyConverter;
 import io.servicecomb.swagger.extend.property.creator.ByteArrayPropertyCreator;
 import io.servicecomb.swagger.extend.property.creator.BytePropertyCreator;
 import io.servicecomb.swagger.extend.property.creator.InputStreamPropertyCreator;
+import io.servicecomb.swagger.extend.property.creator.PartPropertyCreator;
 import io.servicecomb.swagger.extend.property.creator.PropertyCreator;
 import io.servicecomb.swagger.extend.property.creator.ShortPropertyCreator;
 import io.swagger.converter.ModelConverter;
@@ -58,6 +59,7 @@ public class ModelResolverExt extends ModelResolver {
     addPropertyCreator(new ShortPropertyCreator());
     addPropertyCreator(new ByteArrayPropertyCreator());
     addPropertyCreator(new InputStreamPropertyCreator());
+    addPropertyCreator(new PartPropertyCreator());
     loadPropertyCreators();
   }
 
diff --git a/swagger/swagger-generator/generator-core/src/main/java/io/servicecomb/swagger/extend/property/creator/PartPropertyCreator.java b/swagger/swagger-generator/generator-core/src/main/java/io/servicecomb/swagger/extend/property/creator/PartPropertyCreator.java
new file mode 100644
index 0000000..7d8fb20
--- /dev/null
+++ b/swagger/swagger-generator/generator-core/src/main/java/io/servicecomb/swagger/extend/property/creator/PartPropertyCreator.java
@@ -0,0 +1,37 @@
+/*
+ * 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.extend.property.creator;
+
+import javax.servlet.http.Part;
+
+import io.swagger.models.properties.FileProperty;
+import io.swagger.models.properties.Property;
+
+public class PartPropertyCreator implements PropertyCreator {
+  private final Class<?>[] classes = {Part.class};
+
+  @Override
+  public Property createProperty() {
+    return new FileProperty();
+  }
+
+  @Override
+  public Class<?>[] classes() {
+    return classes;
+  }
+}
diff --git a/swagger/swagger-generator/generator-core/src/test/java/io/servicecomb/swagger/extend/property/creator/TestPartPropertyCreator.java b/swagger/swagger-generator/generator-core/src/test/java/io/servicecomb/swagger/extend/property/creator/TestPartPropertyCreator.java
new file mode 100644
index 0000000..4e8c8e5
--- /dev/null
+++ b/swagger/swagger-generator/generator-core/src/test/java/io/servicecomb/swagger/extend/property/creator/TestPartPropertyCreator.java
@@ -0,0 +1,42 @@
+/*
+ * 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.extend.property.creator;
+
+import javax.servlet.http.Part;
+
+import org.hamcrest.Matchers;
+import org.junit.Assert;
+import org.junit.Test;
+
+import io.swagger.models.properties.FileProperty;
+
+
+public class TestPartPropertyCreator {
+  PartPropertyCreator creator = new PartPropertyCreator();
+
+  @SuppressWarnings("unchecked")
+  @Test
+  public void classes() {
+    Assert.assertThat(creator.classes(), Matchers.arrayContaining(Part.class));
+  }
+
+  @Test
+  public void createProperty() {
+    Assert.assertThat(creator.createProperty(), Matchers.instanceOf(FileProperty.class));
+  }
+}

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.

[incubator-servicecomb-java-chassis] 02/11: JAV-548 fix springmvc upload bug, avoid sample not close inputstream

Posted by ni...@apache.org.
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 1c9e31dd7440bf9a05c929f84bd81775def7c17f
Author: wujimin <wu...@huawei.com>
AuthorDate: Wed Dec 13 10:47:31 2017 +0800

    JAV-548 fix springmvc upload bug, avoid sample not close inputstream
---
 integration-tests/springmvc-tests/pom.xml                            | 4 ----
 .../demo/springmvc/tests/endpoints/CodeFirstSpringmvcBase.java       | 5 ++++-
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/integration-tests/springmvc-tests/pom.xml b/integration-tests/springmvc-tests/pom.xml
index 692554f..f376446 100644
--- a/integration-tests/springmvc-tests/pom.xml
+++ b/integration-tests/springmvc-tests/pom.xml
@@ -40,10 +40,6 @@
     </dependency>
     <dependency>
       <groupId>io.servicecomb</groupId>
-      <artifactId>provider-rest-common</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>io.servicecomb</groupId>
       <artifactId>provider-springmvc</artifactId>
     </dependency>
   </dependencies>
diff --git a/integration-tests/springmvc-tests/src/test/java/io/servicecomb/demo/springmvc/tests/endpoints/CodeFirstSpringmvcBase.java b/integration-tests/springmvc-tests/src/test/java/io/servicecomb/demo/springmvc/tests/endpoints/CodeFirstSpringmvcBase.java
index 6f73b33..35d6266 100644
--- a/integration-tests/springmvc-tests/src/test/java/io/servicecomb/demo/springmvc/tests/endpoints/CodeFirstSpringmvcBase.java
+++ b/integration-tests/springmvc-tests/src/test/java/io/servicecomb/demo/springmvc/tests/endpoints/CodeFirstSpringmvcBase.java
@@ -18,6 +18,7 @@
 package io.servicecomb.demo.springmvc.tests.endpoints;
 
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -76,7 +77,9 @@ public class CodeFirstSpringmvcBase {
 
   public String fileUpload(MultipartFile file1, MultipartFile file2, String name) {
     try {
-      return IOUtils.toString(file1.getInputStream()) + IOUtils.toString(file2.getInputStream()) + name;
+      return IOUtils.toString(file1.getBytes(), StandardCharsets.UTF_8.name())
+          + IOUtils.toString(file2.getBytes(), StandardCharsets.UTF_8.name())
+          + name;
     } catch (IOException e) {
       throw new IllegalArgumentException(e);
     }

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.

[incubator-servicecomb-java-chassis] 06/11: JAV-548 pojo consumer support file upload

Posted by ni...@apache.org.
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>.

[incubator-servicecomb-java-chassis] 09/11: JAV-548 change demo springmvc-server, one input parameter changed from MultipartFile to Part

Posted by ni...@apache.org.
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 e7382511801230d1facaa8068f5aa98f49bd85d5
Author: wujimin <wu...@huawei.com>
AuthorDate: Thu Dec 14 08:42:49 2017 +0800

    JAV-548 change demo springmvc-server, one input parameter changed from MultipartFile to Part
---
 .../io/servicecomb/demo/springmvc/server/CodeFirstSpringmvc.java     | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/demo/demo-springmvc/springmvc-server/src/main/java/io/servicecomb/demo/springmvc/server/CodeFirstSpringmvc.java b/demo/demo-springmvc/springmvc-server/src/main/java/io/servicecomb/demo/springmvc/server/CodeFirstSpringmvc.java
index 3fc76aa..ff17d29 100644
--- a/demo/demo-springmvc/springmvc-server/src/main/java/io/servicecomb/demo/springmvc/server/CodeFirstSpringmvc.java
+++ b/demo/demo-springmvc/springmvc-server/src/main/java/io/servicecomb/demo/springmvc/server/CodeFirstSpringmvc.java
@@ -24,6 +24,7 @@ import java.util.List;
 import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.Part;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.Response.Status;
 
@@ -73,7 +74,7 @@ import io.vertx.core.json.JsonObject;
 @RestSchema(schemaId = "codeFirst")
 @RequestMapping(path = "/codeFirstSpringmvc", produces = MediaType.APPLICATION_JSON_VALUE)
 public class CodeFirstSpringmvc {
-  private String _fileUpload(MultipartFile file1, MultipartFile file2) {
+  private String _fileUpload(MultipartFile file1, Part file2) {
     try (InputStream is1 = file1.getInputStream(); InputStream is2 = file2.getInputStream()) {
       String content1 = IOUtils.toString(is1);
       String content2 = IOUtils.toString(is2);
@@ -85,7 +86,7 @@ public class CodeFirstSpringmvc {
 
   @PostMapping(path = "/upload", produces = MediaType.TEXT_PLAIN_VALUE)
   public String fileUpload(@RequestPart(name = "file1") MultipartFile file1,
-      @RequestPart(name = "someFile") MultipartFile file2) {
+      @RequestPart(name = "someFile") Part file2) {
     return _fileUpload(file1, file2);
   }
 

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.

[incubator-servicecomb-java-chassis] 10/11: update license in code-templates.xml

Posted by ni...@apache.org.
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 7ffe244d23f83db0918c61e77a9366054a83cbde
Author: wujimin <wu...@huawei.com>
AuthorDate: Wed Dec 20 15:46:19 2017 +0800

    update license in code-templates.xml
---
 etc/code-templates.xml | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/etc/code-templates.xml b/etc/code-templates.xml
index 66943fe..dcb9150 100644
--- a/etc/code-templates.xml
+++ b/etc/code-templates.xml
@@ -20,13 +20,14 @@
   <template autoinsert="false" context="filecomment_context" deleted="false"
     description="Comment for created Java files" enabled="true"
     id="org.eclipse.jdt.ui.text.codetemplates.filecomment" name="filecomment">/*&#13;
- * Copyright 2017 Huawei Technologies Co., Ltd&#13;
+ * Licensed to the Apache Software Foundation (ASF) under one or more&#13;
+ * contributor license agreements.  See the NOTICE file distributed with&#13;
+ * this work for additional information regarding copyright ownership.&#13;
+ * The ASF licenses this file to You under the Apache License, Version 2.0&#13;
+ * (the "License"); you may not use this file except in compliance with&#13;
+ * the License.  You may obtain a copy of the License at&#13;
  *&#13;
- * Licensed under the Apache License, Version 2.0 (the "License");&#13;
- * you may not use this file except in compliance with the License.&#13;
- * You may obtain a copy of the License at&#13;
- *&#13;
- * http://www.apache.org/licenses/LICENSE-2.0&#13;
+ *     http://www.apache.org/licenses/LICENSE-2.0&#13;
  *&#13;
  * Unless required by applicable law or agreed to in writing, software&#13;
  * distributed under the License is distributed on an "AS IS" BASIS,&#13;

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.

[incubator-servicecomb-java-chassis] 07/11: JAV-548 add demo for pojo consumer invoke file upload

Posted by ni...@apache.org.
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 50ecefd9d3d921aa1fce7c2606501abb3f3e89ee
Author: wujimin <wu...@huawei.com>
AuthorDate: Wed Dec 13 15:54:07 2017 +0800

    JAV-548 add demo for pojo consumer invoke file upload
---
 .../client/CodeFirstRestTemplateSpringmvc.java     | 34 ++++++++++++++++++++--
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/demo/demo-springmvc/springmvc-client/src/main/java/io/servicecomb/demo/springmvc/client/CodeFirstRestTemplateSpringmvc.java b/demo/demo-springmvc/springmvc-client/src/main/java/io/servicecomb/demo/springmvc/client/CodeFirstRestTemplateSpringmvc.java
index 63ecca6..b2e5924 100644
--- a/demo/demo-springmvc/springmvc-client/src/main/java/io/servicecomb/demo/springmvc/client/CodeFirstRestTemplateSpringmvc.java
+++ b/demo/demo-springmvc/springmvc-client/src/main/java/io/servicecomb/demo/springmvc/client/CodeFirstRestTemplateSpringmvc.java
@@ -17,14 +17,21 @@
 
 package io.servicecomb.demo.springmvc.client;
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.servlet.http.Part;
+
 import org.apache.commons.io.FileUtils;
 import org.springframework.core.io.FileSystemResource;
+import org.springframework.core.io.PathResource;
+import org.springframework.core.io.Resource;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpMethod;
@@ -39,6 +46,8 @@ import io.servicecomb.bizkeeper.BizkeeperExceptionUtils;
 import io.servicecomb.core.exception.CseException;
 import io.servicecomb.demo.CodeFirstRestTemplate;
 import io.servicecomb.demo.TestMgr;
+import io.servicecomb.foundation.common.part.FilePart;
+import io.servicecomb.provider.pojo.Invoker;
 import io.servicecomb.provider.pojo.RpcReference;
 import io.servicecomb.provider.springmvc.reference.CseHttpEntity;
 import io.servicecomb.serviceregistry.RegistryUtils;
@@ -46,6 +55,17 @@ import io.servicecomb.swagger.invocation.Response;
 
 @Component
 public class CodeFirstRestTemplateSpringmvc extends CodeFirstRestTemplate {
+  interface UploadPartAndFile {
+    String fileUpload(Part file1, File file2);
+  }
+  interface UploadStreamAndResource {
+    String fileUpload(InputStream file1, Resource file2);
+  }
+
+  private UploadPartAndFile uploadPartAndFile = Invoker.createProxy("springmvc", "codeFirst", UploadPartAndFile.class);
+
+  private UploadStreamAndResource uploadStreamAndResource =
+      Invoker.createProxy("springmvc", "codeFirst", UploadStreamAndResource.class);
 
   @RpcReference(microserviceName = "springmvc", schemaId = "codeFirst")
   private CodeFirstSprigmvcIntf intf;
@@ -55,7 +75,7 @@ public class CodeFirstRestTemplateSpringmvc extends CodeFirstRestTemplate {
     try {
       testUpload(template, cseUrlPrefix);
     } catch (IOException e) {
-      e.printStackTrace();
+      throw new IllegalStateException(e);
     }
 
     super.testOnlyRest(template, cseUrlPrefix);
@@ -80,8 +100,16 @@ public class CodeFirstRestTemplateSpringmvc extends CodeFirstRestTemplate {
     File someFile = File.createTempFile("upload2", ".txt");
     FileUtils.writeStringToFile(someFile, file2Content);
 
-    String templateResult = testRestTemplateUpload(template, cseUrlPrefix, file1, someFile);
-    TestMgr.check(file1Content + file2Content, templateResult);
+    String result = testRestTemplateUpload(template, cseUrlPrefix, file1, someFile);
+    TestMgr.check(file1Content + file2Content, result);
+
+    result = uploadPartAndFile.fileUpload(new FilePart(null, file1), someFile);
+    TestMgr.check(file1Content + file2Content, result);
+
+    result = uploadStreamAndResource
+        .fileUpload(new ByteArrayInputStream(file1Content.getBytes(StandardCharsets.UTF_8)),
+            new PathResource(someFile.getAbsolutePath()));
+    TestMgr.check(file1Content + file2Content, result);
   }
 
   private String testRestTemplateUpload(RestTemplate template, String cseUrlPrefix, File file1, File someFile) {

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.

[incubator-servicecomb-java-chassis] 05/11: JAV-548 move part implementations to foundation-common, and add UT

Posted by ni...@apache.org.
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 fdcede6c6d064524758888ae1b843a16404ab160
Author: wujimin <wu...@huawei.com>
AuthorDate: Wed Dec 13 14:19:39 2017 +0800

    JAV-548 move part implementations to foundation-common, and add UT
---
 foundations/foundation-common/pom.xml              |   4 +
 .../foundation/common}/part/AbstractPart.java      |   2 +-
 .../foundation/common}/part/FilePart.java          |   2 +-
 .../foundation/common}/part/InputStreamPart.java   |   2 +-
 .../foundation/common}/part/ResourcePart.java      |   2 +-
 .../foundation/common/part/TestAbstractPart.java   | 116 +++++++++++++++++++++
 .../foundation/common/part/TestFilePart.java       |  76 ++++++++++++++
 .../common/part/TestInputStreamPart.java}          |  33 ++++--
 .../foundation/common/part/TestResourcePart.java}  |  32 ++++--
 foundations/foundation-vertx/pom.xml               |   4 -
 .../VertxServerRequestToHttpServletRequest.java    |   3 +-
 .../reference/CommonToHttpServletRequest.java      |   6 +-
 12 files changed, 249 insertions(+), 33 deletions(-)

diff --git a/foundations/foundation-common/pom.xml b/foundations/foundation-common/pom.xml
index d5a360a..298d7e2 100644
--- a/foundations/foundation-common/pom.xml
+++ b/foundations/foundation-common/pom.xml
@@ -71,5 +71,9 @@
 			<groupId>com.google.guava</groupId>
 			<artifactId>guava</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>javax.servlet</groupId>
+			<artifactId>javax.servlet-api</artifactId>
+		</dependency>
 	</dependencies>
 </project>
diff --git a/foundations/foundation-vertx/src/main/java/io/servicecomb/foundation/vertx/part/AbstractPart.java b/foundations/foundation-common/src/main/java/io/servicecomb/foundation/common/part/AbstractPart.java
similarity index 97%
rename from foundations/foundation-vertx/src/main/java/io/servicecomb/foundation/vertx/part/AbstractPart.java
rename to foundations/foundation-common/src/main/java/io/servicecomb/foundation/common/part/AbstractPart.java
index f36fa04..9a152f8 100644
--- a/foundations/foundation-vertx/src/main/java/io/servicecomb/foundation/vertx/part/AbstractPart.java
+++ b/foundations/foundation-common/src/main/java/io/servicecomb/foundation/common/part/AbstractPart.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package io.servicecomb.foundation.vertx.part;
+package io.servicecomb.foundation.common.part;
 
 import java.io.IOException;
 import java.io.InputStream;
diff --git a/foundations/foundation-vertx/src/main/java/io/servicecomb/foundation/vertx/part/FilePart.java b/foundations/foundation-common/src/main/java/io/servicecomb/foundation/common/part/FilePart.java
similarity index 97%
rename from foundations/foundation-vertx/src/main/java/io/servicecomb/foundation/vertx/part/FilePart.java
rename to foundations/foundation-common/src/main/java/io/servicecomb/foundation/common/part/FilePart.java
index d71e970..aed6c6d 100644
--- a/foundations/foundation-vertx/src/main/java/io/servicecomb/foundation/vertx/part/FilePart.java
+++ b/foundations/foundation-common/src/main/java/io/servicecomb/foundation/common/part/FilePart.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package io.servicecomb.foundation.vertx.part;
+package io.servicecomb.foundation.common.part;
 
 import java.io.File;
 import java.io.FileInputStream;
diff --git a/foundations/foundation-vertx/src/main/java/io/servicecomb/foundation/vertx/part/InputStreamPart.java b/foundations/foundation-common/src/main/java/io/servicecomb/foundation/common/part/InputStreamPart.java
similarity index 95%
rename from foundations/foundation-vertx/src/main/java/io/servicecomb/foundation/vertx/part/InputStreamPart.java
rename to foundations/foundation-common/src/main/java/io/servicecomb/foundation/common/part/InputStreamPart.java
index e7a3c17..7efbfbc 100644
--- a/foundations/foundation-vertx/src/main/java/io/servicecomb/foundation/vertx/part/InputStreamPart.java
+++ b/foundations/foundation-common/src/main/java/io/servicecomb/foundation/common/part/InputStreamPart.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package io.servicecomb.foundation.vertx.part;
+package io.servicecomb.foundation.common.part;
 
 import java.io.InputStream;
 
diff --git a/foundations/foundation-vertx/src/main/java/io/servicecomb/foundation/vertx/part/ResourcePart.java b/foundations/foundation-common/src/main/java/io/servicecomb/foundation/common/part/ResourcePart.java
similarity index 96%
copy from foundations/foundation-vertx/src/main/java/io/servicecomb/foundation/vertx/part/ResourcePart.java
copy to foundations/foundation-common/src/main/java/io/servicecomb/foundation/common/part/ResourcePart.java
index 5ba1599..22c53e4 100644
--- a/foundations/foundation-vertx/src/main/java/io/servicecomb/foundation/vertx/part/ResourcePart.java
+++ b/foundations/foundation-common/src/main/java/io/servicecomb/foundation/common/part/ResourcePart.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package io.servicecomb.foundation.vertx.part;
+package io.servicecomb.foundation.common.part;
 
 import java.io.IOException;
 import java.io.InputStream;
diff --git a/foundations/foundation-common/src/test/java/io/servicecomb/foundation/common/part/TestAbstractPart.java b/foundations/foundation-common/src/test/java/io/servicecomb/foundation/common/part/TestAbstractPart.java
new file mode 100644
index 0000000..dcd5177
--- /dev/null
+++ b/foundations/foundation-common/src/test/java/io/servicecomb/foundation/common/part/TestAbstractPart.java
@@ -0,0 +1,116 @@
+/*
+ * 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.foundation.common.part;
+
+import java.io.IOException;
+
+import javax.ws.rs.core.MediaType;
+
+import org.hamcrest.Matchers;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class TestAbstractPart {
+  AbstractPart part = new AbstractPart();
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private void initExpectedException() {
+    expectedException.expect(Error.class);
+    expectedException.expectMessage(Matchers.is("not supported method"));
+  }
+
+  @Test
+  public void getInputStream() throws IOException {
+    initExpectedException();
+
+    part.getInputStream();
+  }
+
+  @Test
+  public void getContentType() throws IOException {
+    Assert.assertEquals(MediaType.MULTIPART_FORM_DATA, part.getContentType());
+
+    String contentType = "abc";
+    part.contentType(contentType);
+    Assert.assertEquals(contentType, part.getContentType());
+  }
+
+  @Test
+  public void getName() throws IOException {
+    Assert.assertNull(part.getName());
+
+    String name = "abc";
+    part.name = name;
+    Assert.assertEquals(name, part.getName());
+  }
+
+  @Test
+  public void getSubmittedFileName() throws IOException {
+    Assert.assertNull(part.getSubmittedFileName());
+
+    String submittedFileName = "abc";
+    part.submittedFileName = submittedFileName;
+    Assert.assertEquals(submittedFileName, part.getSubmittedFileName());
+  }
+
+  @Test
+  public void getSize() {
+    initExpectedException();
+
+    part.getSize();
+  }
+
+  @Test
+  public void write() throws IOException {
+    initExpectedException();
+
+    part.write("file");
+  }
+
+  @Test
+  public void delete() throws IOException {
+    initExpectedException();
+
+    part.delete();
+  }
+
+  @Test
+  public void getHeader() {
+    initExpectedException();
+
+    part.getHeader("header");
+  }
+
+  @Test
+  public void getHeaders() {
+    initExpectedException();
+
+    part.getHeaders("header");
+  }
+
+  @Test
+  public void getHeaderNames() {
+    initExpectedException();
+
+    part.getHeaderNames();
+  }
+}
diff --git a/foundations/foundation-common/src/test/java/io/servicecomb/foundation/common/part/TestFilePart.java b/foundations/foundation-common/src/test/java/io/servicecomb/foundation/common/part/TestFilePart.java
new file mode 100644
index 0000000..5a50eb2
--- /dev/null
+++ b/foundations/foundation-common/src/test/java/io/servicecomb/foundation/common/part/TestFilePart.java
@@ -0,0 +1,76 @@
+/*
+ * 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.foundation.common.part;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestFilePart {
+  static File file = new File("testFilePart.txt");
+
+  static String content = "testFilePart content";
+
+  String name = "paramName";
+
+  FilePart part = new FilePart(name, file.getAbsolutePath());
+
+  @BeforeClass
+  public static void setup() throws IOException {
+    file.delete();
+    FileUtils.write(file, content);
+  }
+
+  @AfterClass
+  public static void teardown() {
+    file.delete();
+  }
+
+  @Test
+  public void getName() {
+    Assert.assertEquals(name, part.getName());
+  }
+
+  @Test
+  public void getInputStream() throws IOException {
+    try (InputStream is = part.getInputStream()) {
+      Assert.assertEquals(content, IOUtils.toString(is));
+    }
+  }
+
+  @Test
+  public void getSize() {
+    Assert.assertEquals(content.length(), part.getSize());
+  }
+
+  @Test
+  public void write() throws IOException {
+    File destFile = new File("testFilePartCopy.txt");
+
+    part.write(destFile.getPath());
+    Assert.assertEquals(content, FileUtils.readFileToString(destFile));
+    destFile.delete();
+  }
+}
diff --git a/foundations/foundation-vertx/src/main/java/io/servicecomb/foundation/vertx/part/ResourcePart.java b/foundations/foundation-common/src/test/java/io/servicecomb/foundation/common/part/TestInputStreamPart.java
similarity index 56%
copy from foundations/foundation-vertx/src/main/java/io/servicecomb/foundation/vertx/part/ResourcePart.java
copy to foundations/foundation-common/src/test/java/io/servicecomb/foundation/common/part/TestInputStreamPart.java
index 5ba1599..569acda 100644
--- a/foundations/foundation-vertx/src/main/java/io/servicecomb/foundation/vertx/part/ResourcePart.java
+++ b/foundations/foundation-common/src/test/java/io/servicecomb/foundation/common/part/TestInputStreamPart.java
@@ -15,24 +15,35 @@
  * limitations under the License.
  */
 
-package io.servicecomb.foundation.vertx.part;
+package io.servicecomb.foundation.common.part;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 
-import org.springframework.core.io.Resource;
+import org.apache.commons.io.IOUtils;
+import org.junit.Assert;
+import org.junit.Test;
 
-public class ResourcePart extends AbstractPart {
-  private Resource resource;
+public class TestInputStreamPart {
+  String name = "paramName";
 
-  public ResourcePart(String name, Resource resource) {
-    this.name = name;
-    this.resource = resource;
-    this.submittedFileName = resource.getFilename();
+  byte[] bytes = new byte[] {1, 2, 3};
+
+  InputStream is = new ByteArrayInputStream(bytes);
+
+  InputStreamPart part = new InputStreamPart(name, is);
+
+  @Test
+  public void getName() {
+    Assert.assertEquals(name, part.getName());
   }
 
-  @Override
-  public InputStream getInputStream() throws IOException {
-    return resource.getInputStream();
+  @Test
+  public void test() throws IOException {
+    try (InputStream is = part.getInputStream()) {
+      byte[] content = IOUtils.toByteArray(is);
+      Assert.assertArrayEquals(bytes, content);
+    }
   }
 }
diff --git a/foundations/foundation-vertx/src/main/java/io/servicecomb/foundation/vertx/part/ResourcePart.java b/foundations/foundation-common/src/test/java/io/servicecomb/foundation/common/part/TestResourcePart.java
similarity index 57%
rename from foundations/foundation-vertx/src/main/java/io/servicecomb/foundation/vertx/part/ResourcePart.java
rename to foundations/foundation-common/src/test/java/io/servicecomb/foundation/common/part/TestResourcePart.java
index 5ba1599..ba2d003 100644
--- a/foundations/foundation-vertx/src/main/java/io/servicecomb/foundation/vertx/part/ResourcePart.java
+++ b/foundations/foundation-common/src/test/java/io/servicecomb/foundation/common/part/TestResourcePart.java
@@ -15,24 +15,36 @@
  * limitations under the License.
  */
 
-package io.servicecomb.foundation.vertx.part;
+package io.servicecomb.foundation.common.part;
 
 import java.io.IOException;
 import java.io.InputStream;
 
+import org.apache.commons.io.IOUtils;
+import org.junit.Assert;
+import org.junit.Test;
+import org.springframework.core.io.ByteArrayResource;
 import org.springframework.core.io.Resource;
 
-public class ResourcePart extends AbstractPart {
-  private Resource resource;
+public class TestResourcePart {
+  String name = "paramName";
 
-  public ResourcePart(String name, Resource resource) {
-    this.name = name;
-    this.resource = resource;
-    this.submittedFileName = resource.getFilename();
+  byte[] bytes = new byte[] {1, 2, 3};
+
+  Resource resource = new ByteArrayResource(bytes);
+
+  ResourcePart part = new ResourcePart(name, resource);
+
+  @Test
+  public void getName() {
+    Assert.assertEquals(name, part.getName());
   }
 
-  @Override
-  public InputStream getInputStream() throws IOException {
-    return resource.getInputStream();
+  @Test
+  public void getInputStream() throws IOException {
+    try (InputStream is = part.getInputStream()) {
+      byte[] content = IOUtils.toByteArray(is);
+      Assert.assertArrayEquals(bytes, content);
+    }
   }
 }
diff --git a/foundations/foundation-vertx/pom.xml b/foundations/foundation-vertx/pom.xml
index 0728d9d..cc9b6cc 100644
--- a/foundations/foundation-vertx/pom.xml
+++ b/foundations/foundation-vertx/pom.xml
@@ -43,10 +43,6 @@
       <artifactId>foundation-common</artifactId>
     </dependency>
     <dependency>
-      <groupId>javax.servlet</groupId>
-      <artifactId>javax.servlet-api</artifactId>
-    </dependency>
-    <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-log4j12</artifactId>
       <scope>test</scope>
diff --git a/foundations/foundation-vertx/src/main/java/io/servicecomb/foundation/vertx/http/VertxServerRequestToHttpServletRequest.java b/foundations/foundation-vertx/src/main/java/io/servicecomb/foundation/vertx/http/VertxServerRequestToHttpServletRequest.java
index 57a79c7..7bba5bd 100644
--- a/foundations/foundation-vertx/src/main/java/io/servicecomb/foundation/vertx/http/VertxServerRequestToHttpServletRequest.java
+++ b/foundations/foundation-vertx/src/main/java/io/servicecomb/foundation/vertx/http/VertxServerRequestToHttpServletRequest.java
@@ -36,7 +36,7 @@ import javax.ws.rs.core.HttpHeaders;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import io.servicecomb.foundation.vertx.part.FilePart;
+import io.servicecomb.foundation.common.part.FilePart;
 import io.servicecomb.foundation.vertx.stream.BufferInputStream;
 import io.vertx.core.MultiMap;
 import io.vertx.core.buffer.Buffer;
@@ -47,6 +47,7 @@ import io.vertx.ext.web.RoutingContext;
 // wrap vertx http request to Servlet http request
 public class VertxServerRequestToHttpServletRequest extends AbstractHttpServletRequest {
   private static final Logger LOGGER = LoggerFactory.getLogger(VertxServerRequestToHttpServletRequest.class);
+
   private static final EmptyAsyncContext EMPTY_ASYNC_CONTEXT = new EmptyAsyncContext();
 
   private RoutingContext context;
diff --git a/providers/provider-springmvc/src/main/java/io/servicecomb/provider/springmvc/reference/CommonToHttpServletRequest.java b/providers/provider-springmvc/src/main/java/io/servicecomb/provider/springmvc/reference/CommonToHttpServletRequest.java
index c2f36fa..9593983 100644
--- a/providers/provider-springmvc/src/main/java/io/servicecomb/provider/springmvc/reference/CommonToHttpServletRequest.java
+++ b/providers/provider-springmvc/src/main/java/io/servicecomb/provider/springmvc/reference/CommonToHttpServletRequest.java
@@ -38,10 +38,10 @@ import javax.ws.rs.core.HttpHeaders;
 import org.springframework.core.io.Resource;
 
 import io.servicecomb.common.rest.RestConst;
+import io.servicecomb.foundation.common.part.FilePart;
+import io.servicecomb.foundation.common.part.InputStreamPart;
+import io.servicecomb.foundation.common.part.ResourcePart;
 import io.servicecomb.foundation.vertx.http.AbstractHttpServletRequest;
-import io.servicecomb.foundation.vertx.part.FilePart;
-import io.servicecomb.foundation.vertx.part.InputStreamPart;
-import io.servicecomb.foundation.vertx.part.ResourcePart;
 
 // restTemplate convert parameters to invocation args.
 public class CommonToHttpServletRequest extends AbstractHttpServletRequest {

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.

[incubator-servicecomb-java-chassis] 01/11: JAV-548 fix springmvc upload bug, avoid getBytes not closed inputStream

Posted by ni...@apache.org.
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 887ab2a6de3732b35e50be73c30b1292a5ddd21d
Author: wujimin <wu...@huawei.com>
AuthorDate: Wed Dec 13 10:45:35 2017 +0800

    JAV-548 fix springmvc upload bug, avoid getBytes not closed inputStream
---
 .../invocation/converter/PartToMultipartFile.java  |  77 +++++++++
 .../converter/SpringMultipartConverter.java        |  47 +-----
 .../converter/TestPartToMultipartFile.java         | 186 +++++++++++++++++++++
 3 files changed, 264 insertions(+), 46 deletions(-)

diff --git a/swagger/swagger-invocation/invocation-springmvc/src/main/java/io/servicecomb/swagger/invocation/converter/PartToMultipartFile.java b/swagger/swagger-invocation/invocation-springmvc/src/main/java/io/servicecomb/swagger/invocation/converter/PartToMultipartFile.java
new file mode 100644
index 0000000..8e83d7c
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-springmvc/src/main/java/io/servicecomb/swagger/invocation/converter/PartToMultipartFile.java
@@ -0,0 +1,77 @@
+/*
+ * 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;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.servlet.http.Part;
+
+import org.apache.commons.io.IOUtils;
+import org.springframework.web.multipart.MultipartFile;
+
+public class PartToMultipartFile implements MultipartFile {
+  private Part part;
+
+  public PartToMultipartFile(Part part) {
+    this.part = part;
+  }
+
+  @Override
+  public String getName() {
+    return part.getName();
+  }
+
+  @Override
+  public String getOriginalFilename() {
+    return part.getSubmittedFileName();
+  }
+
+  @Override
+  public String getContentType() {
+    return part.getContentType();
+  }
+
+  @Override
+  public boolean isEmpty() {
+    return part.getSize() == 0;
+  }
+
+  @Override
+  public long getSize() {
+    return part.getSize();
+  }
+
+  @Override
+  public byte[] getBytes() throws IOException {
+    try (InputStream is = getInputStream()) {
+      return IOUtils.toByteArray(is);
+    }
+  }
+
+  @Override
+  public InputStream getInputStream() throws IOException {
+    return part.getInputStream();
+  }
+
+  @Override
+  public void transferTo(File dest) throws IOException, IllegalStateException {
+    part.write(dest.getPath());
+  }
+}
diff --git a/swagger/swagger-invocation/invocation-springmvc/src/main/java/io/servicecomb/swagger/invocation/converter/SpringMultipartConverter.java b/swagger/swagger-invocation/invocation-springmvc/src/main/java/io/servicecomb/swagger/invocation/converter/SpringMultipartConverter.java
index 5e8e0e0..d4618a5 100644
--- a/swagger/swagger-invocation/invocation-springmvc/src/main/java/io/servicecomb/swagger/invocation/converter/SpringMultipartConverter.java
+++ b/swagger/swagger-invocation/invocation-springmvc/src/main/java/io/servicecomb/swagger/invocation/converter/SpringMultipartConverter.java
@@ -17,14 +17,10 @@
 
 package io.servicecomb.swagger.invocation.converter;
 
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
 import java.lang.reflect.Type;
 
 import javax.servlet.http.Part;
 
-import org.apache.commons.io.IOUtils;
 import org.springframework.stereotype.Component;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -46,47 +42,6 @@ class SpringMultipartConverter implements CustomizedConverter {
       return null;
     }
 
-    Part part = (Part) value;
-    return new MultipartFile() {
-      @Override
-      public String getName() {
-        return part.getName();
-      }
-
-      @Override
-      public String getOriginalFilename() {
-        return part.getSubmittedFileName();
-      }
-
-      @Override
-      public String getContentType() {
-        return part.getContentType();
-      }
-
-      @Override
-      public boolean isEmpty() {
-        return part.getSize() == 0;
-      }
-
-      @Override
-      public long getSize() {
-        return part.getSize();
-      }
-
-      @Override
-      public byte[] getBytes() throws IOException {
-        return IOUtils.toByteArray(part.getInputStream());
-      }
-
-      @Override
-      public InputStream getInputStream() throws IOException {
-        return part.getInputStream();
-      }
-
-      @Override
-      public void transferTo(File dest) throws IOException, IllegalStateException {
-        part.write(dest.getPath());
-      }
-    };
+    return new PartToMultipartFile((Part) value);
   }
 }
diff --git a/swagger/swagger-invocation/invocation-springmvc/src/test/java/io/servicecomb/swagger/invocation/converter/TestPartToMultipartFile.java b/swagger/swagger-invocation/invocation-springmvc/src/test/java/io/servicecomb/swagger/invocation/converter/TestPartToMultipartFile.java
new file mode 100644
index 0000000..dc15aaa
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-springmvc/src/test/java/io/servicecomb/swagger/invocation/converter/TestPartToMultipartFile.java
@@ -0,0 +1,186 @@
+/*
+ * 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;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+
+import javax.servlet.http.Part;
+import javax.xml.ws.Holder;
+
+import org.hamcrest.Matchers;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import mockit.Expectations;
+import mockit.Mock;
+import mockit.MockUp;
+import mockit.Mocked;
+
+public class TestPartToMultipartFile {
+  @Mocked
+  Part part;
+
+  PartToMultipartFile multipartFile;
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  @Before
+  public void setup() {
+    multipartFile = new PartToMultipartFile(part);
+  }
+
+  @Test
+  public void getName() {
+    String name = "paramName";
+    new Expectations() {
+      {
+        part.getName();
+        result = name;
+      }
+    };
+
+    Assert.assertEquals(name, multipartFile.getName());
+  }
+
+  @Test
+  public void getOriginalFilename() {
+    String submittedFileName = "fileName";
+    new Expectations() {
+      {
+        part.getSubmittedFileName();
+        result = submittedFileName;
+      }
+    };
+
+    Assert.assertEquals(submittedFileName, multipartFile.getOriginalFilename());
+  }
+
+  @Test
+  public void getContentType() {
+    String contentType = "json";
+    new Expectations() {
+      {
+        part.getContentType();
+        result = contentType;
+      }
+    };
+
+    Assert.assertEquals(contentType, multipartFile.getContentType());
+  }
+
+  @Test
+  public void isEmptyTrue() {
+    new Expectations() {
+      {
+        part.getSize();
+        result = 0;
+      }
+    };
+
+    Assert.assertTrue(multipartFile.isEmpty());
+  }
+
+  @Test
+  public void isEmptyFalse() {
+    new Expectations() {
+      {
+        part.getSize();
+        result = 1;
+      }
+    };
+
+    Assert.assertFalse(multipartFile.isEmpty());
+  }
+
+  @Test
+  public void getSize() {
+    long size = 10;
+    new Expectations() {
+      {
+        part.getSize();
+        result = size;
+      }
+    };
+
+    Assert.assertEquals(size, multipartFile.getSize());
+  }
+
+  class ByteArrayInputStreamForTest extends ByteArrayInputStream {
+    boolean closed;
+
+    public ByteArrayInputStreamForTest(byte[] buf) {
+      super(buf);
+    }
+
+    @Override
+    public void close() throws IOException {
+      closed = true;
+    }
+  }
+
+  @Test
+  public void getBytes_normal() throws IOException {
+    byte[] bytes = new byte[] {1, 2, 3};
+    ByteArrayInputStreamForTest is = new ByteArrayInputStreamForTest(bytes);
+    new Expectations() {
+      {
+        part.getInputStream();
+        result = is;
+      }
+    };
+
+    Assert.assertArrayEquals(bytes, multipartFile.getBytes());
+    Assert.assertTrue(is.closed);
+  }
+
+  @Test
+  public void getBytes_exception() throws IOException {
+    new Expectations() {
+      {
+        part.getInputStream();
+        result = new IOException("open stream failed");
+      }
+    };
+
+    expectedException.expect(IOException.class);
+    expectedException.expectMessage(Matchers.is("open stream failed"));
+
+    multipartFile.getBytes();
+  }
+
+  @Test
+  public void transferTo() throws IllegalStateException, IOException {
+    File dest = new File("/dest");
+    Holder<String> destName = new Holder<>();
+    new MockUp<Part>(part) {
+      @Mock
+      void write(String fileName) throws IOException {
+        destName.value = fileName;
+      }
+    };
+
+    multipartFile.transferTo(dest);
+    Assert.assertEquals(dest.getPath(), destName.value);
+  }
+}

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.

[incubator-servicecomb-java-chassis] 04/11: JAV-548 change upload directory from "." to "target"

Posted by ni...@apache.org.
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 70afebd419e31850858b97d4f352ade4ba076380
Author: wujimin <wu...@huawei.com>
AuthorDate: Wed Dec 13 10:51:21 2017 +0800

    JAV-548 change upload directory from "." to "target"
---
 .../springmvc-server/src/main/resources/microservice.yaml               | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml b/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
index ad13042..f5d2304 100644
--- a/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
+++ b/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
@@ -28,7 +28,7 @@ service_description:
     - path: /test2/testpath
       property:
         checksession: true
-cse.uploads.directory: .
+cse.uploads.directory: target
 cse:
   service:
     registry:

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.