-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Extract support for MultipartFile to separate module.
- Loading branch information
Showing
19 changed files
with
246 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>io.github.openfeign.form</groupId> | ||
<artifactId>feign-form-parent</artifactId> | ||
<version>2.0.1</version> | ||
</parent> | ||
|
||
<artifactId>feign-form-spring</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>Open Feign Forms Extension for Spring</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>feign-form</artifactId> | ||
<version>${project.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-web</artifactId> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-feign</artifactId> | ||
<version>1.1.5.RELEASE</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
44 changes: 44 additions & 0 deletions
44
feign-form-spring/src/main/java/feign/form/spring/SpringFormEncoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package feign.form.spring; | ||
|
||
import java.lang.reflect.Type; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import feign.RequestTemplate; | ||
import feign.codec.EncodeException; | ||
import feign.codec.Encoder; | ||
import feign.form.FormEncoder; | ||
|
||
/** | ||
* Adds support for {@link MultipartFile} type to {@link FormEncoder}. | ||
* | ||
* @author Tomasz Juchniewicz <tjuchniewicz@gmail.com> | ||
* @since 14.09.2016 | ||
*/ | ||
public class SpringFormEncoder extends FormEncoder { | ||
|
||
private final Encoder delegate; | ||
|
||
public SpringFormEncoder () { | ||
this(new Encoder.Default()); | ||
} | ||
|
||
public SpringFormEncoder(Encoder delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public void encode(Object object, Type bodyType, RequestTemplate template) throws EncodeException { | ||
if (!bodyType.equals(MultipartFile.class)) { | ||
delegate.encode(object, bodyType, template); | ||
return; | ||
} | ||
|
||
MultipartFile file = (MultipartFile) object; | ||
Map<String, Object> data = Collections.singletonMap(file.getName(), object); | ||
new SpringMultipartEncodedDataProcessor().process(data, template); | ||
} | ||
|
||
} |
Oops, something went wrong.