diff --git a/.travis.yml b/.travis.yml index 441e3ba..8762519 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: java jdk: - - oraclejdk8 + - openjdk8 install: ./mvnw --settings .settings.xml install -DskipTests=true -Dmaven.javadoc.skip=true -Dgpg.skip -B -V diff --git a/feign-form/src/main/java/feign/form/MultipartFormContentProcessor.java b/feign-form/src/main/java/feign/form/MultipartFormContentProcessor.java index 6e2f84e..23037a9 100644 --- a/feign-form/src/main/java/feign/form/MultipartFormContentProcessor.java +++ b/feign-form/src/main/java/feign/form/MultipartFormContentProcessor.java @@ -33,12 +33,13 @@ import feign.codec.Encoder; import feign.form.multipart.ByteArrayWriter; import feign.form.multipart.DelegateWriter; -import feign.form.multipart.FormDataWriter; import feign.form.multipart.ManyFilesWriter; +import feign.form.multipart.ManyFormDatasWriter; import feign.form.multipart.ManyParametersWriter; import feign.form.multipart.Output; import feign.form.multipart.PojoWriter; import feign.form.multipart.SingleFileWriter; +import feign.form.multipart.SingleFormDataWriter; import feign.form.multipart.SingleParameterWriter; import feign.form.multipart.Writer; @@ -64,7 +65,8 @@ public class MultipartFormContentProcessor implements ContentProcessor { public MultipartFormContentProcessor (Encoder delegate) { writers = new LinkedList(); addWriter(new ByteArrayWriter()); - addWriter(new FormDataWriter()); + addWriter(new SingleFormDataWriter()); + addWriter(new ManyFormDatasWriter()); addWriter(new SingleFileWriter()); addWriter(new ManyFilesWriter()); addWriter(new SingleParameterWriter()); diff --git a/feign-form/src/main/java/feign/form/multipart/ManyFormDatasWriter.java b/feign-form/src/main/java/feign/form/multipart/ManyFormDatasWriter.java new file mode 100644 index 0000000..d4dbd50 --- /dev/null +++ b/feign-form/src/main/java/feign/form/multipart/ManyFormDatasWriter.java @@ -0,0 +1,65 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * 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 feign.form.multipart; + +import static lombok.AccessLevel.PRIVATE; + +import feign.codec.EncodeException; + +import feign.form.FormData; +import lombok.experimental.FieldDefaults; +import lombok.val; + +/** + * + * @author Sébastien Etronnier + */ +@FieldDefaults(level = PRIVATE, makeFinal = true) +public class ManyFormDatasWriter extends AbstractWriter { + + SingleFormDataWriter formDataWriter = new SingleFormDataWriter(); + + @Override + public boolean isApplicable (Object value) { + if (value instanceof FormData[]) { + return true; + } + if (!(value instanceof Iterable)) { + return false; + } + val iterable = (Iterable) value; + val iterator = iterable.iterator(); + return iterator.hasNext() && iterator.next() instanceof FormData; + } + + @Override + public void write (Output output, String boundary, String key, Object value) throws EncodeException { + if (value instanceof FormData[]) { + val formDatas = (FormData[]) value; + for (val formData : formDatas) { + formDataWriter.write(output, boundary, key, formData); + } + } else if (value instanceof Iterable) { + val iterable = (Iterable) value; + for (val formData : iterable) { + formDataWriter.write(output, boundary, key, formData); + } + } else { + throw new IllegalArgumentException(); + } + } +} diff --git a/feign-form/src/main/java/feign/form/multipart/SingleFormDataWriter.java b/feign-form/src/main/java/feign/form/multipart/SingleFormDataWriter.java new file mode 100644 index 0000000..c9df10f --- /dev/null +++ b/feign-form/src/main/java/feign/form/multipart/SingleFormDataWriter.java @@ -0,0 +1,42 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * 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 feign.form.multipart; + +import feign.codec.EncodeException; +import feign.form.FormData; + +import lombok.val; + +/** + * + * @author Guillaume Simard + * @since 24.03.2018 + */ +public class SingleFormDataWriter extends AbstractWriter { + + @Override + public boolean isApplicable (Object value) { + return value instanceof FormData; + } + + @Override + protected void write (Output output, String key, Object value) throws EncodeException { + val formData = (FormData) value; + writeFileMetadata(output, key, formData.getFileName(), formData.getContentType()); + output.write(formData.getData()); + } +}