Skip to content

Commit

Permalink
Merge pull request #7 from OpenFeign/gh-3
Browse files Browse the repository at this point in the history
Extract support for MultipartFile to separate module.
  • Loading branch information
xxlabaza authored Sep 18, 2016
2 parents b1f5a5c + 01284e5 commit 8252ad6
Show file tree
Hide file tree
Showing 19 changed files with 246 additions and 246 deletions.
202 changes: 44 additions & 158 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,104 +1,18 @@
# Created by https://www.gitignore.io
generated

### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
*.class

*.iml

## Directory-based project format:
.idea/
# if you remove the above rule, at least ignore the following:

# User-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# .idea/dictionaries

# Sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml
# .idea/uiDesigner.xml

# Gradle:
# .idea/gradle.xml
# .idea/libraries

# Mongo Explorer plugin:
# .idea/mongoSettings.xml

## File-based project format:
*.ipr
*.iws

## Plugin-specific files:

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml
# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
# Package Files #
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

### WebStorm ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm

*.iml

## Directory-based project format:
.idea/
# if you remove the above rule, at least ignore the following:

# User-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# .idea/dictionaries

# Sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml
# .idea/uiDesigner.xml

# Gradle:
# .idea/gradle.xml
# .idea/libraries

# Mongo Explorer plugin:
# .idea/mongoSettings.xml

## File-based project format:
*.ipr
*.iws

## Plugin-specific files:

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties


### Eclipse ###
*.pydevproject
.metadata
.gradle
Expand All @@ -112,15 +26,8 @@ local.properties
.settings/
.loadpath

### Netbeans ###
nbproject/private/
build/
nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml
.nb-gradle/
# Eclipse Core
.project

# External tool builders
.externalToolBuilders/
Expand All @@ -131,6 +38,12 @@ nb-configuration.xml
# CDT-specific
.cproject

# JDT-specific (Eclipse Java Development Tools)
.classpath

# Java annotation processor (APT)
.factorypath

# PDT-specific
.buildpath

Expand All @@ -140,25 +53,9 @@ nb-configuration.xml
# TeXlipse plugin
.texlipse

# STS (Spring Tool Suite)
.springBeans

### SublimeText ###
# cache files for sublime text
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache

# workspace files are user-specific
*.sublime-workspace

# project files should be checked into the repository, unless a significant
# proportion of contributors will probably not be using SublimeText
# *.sublime-project

# sftp configuration file
sftp-config.json


### Windows ###
# Windows image file caches
Thumbs.db
ehthumbs.db
Expand All @@ -174,40 +71,29 @@ $RECYCLE.BIN/
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk


### Linux ###
*~

# KDE directory preferences
.directory


### OSX ###
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear on external disk
.Spotlight-V100
.Trashes

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
/target/
*.pdfmarks
log.txt
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
/.project
/.settings/
/.classpath
*.classpath
*.project
*.classpath
*.project
/.apt_generated/

# IntelliJ Idea
.idea/
*.iml
*.ipr
*.iws
out/
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Then, include dependency to your project:
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form</artifactId>
<version>2.0.0</version>
<version>2.0.1</version>
</dependency>
...
</dependencies>
Expand Down Expand Up @@ -102,9 +102,17 @@ In example above, we send file in parameter named **photo** with additional fiel

> **IMPORTANT:** You can specify your files in API method by declaring type **File** or **byte[]**.
### Spring Cloud Netflix @FeingClient support
### Spring MultipartFile and Spring Cloud Netflix @FeingClient support

You can also use Form Encoder with `@FeingClient`:
You can also use Form Encoder with Spring `MultipartFile` and `@FeignClient`:

```xml
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form-spring</artifactId>
<version>2.0.1</version>
</dependency>
```

```java
@FeignClient(name = "file-upload-service", configuration = FileUploadServiceClient.MultipartSupportConfig.class)
Expand All @@ -117,7 +125,7 @@ public interface FileUploadServiceClient extends IFileUploadServiceClient {
@Primary
@Scope("prototype")
public Encoder feignFormEncoder() {
return new FormEncoder();
return new SpringFormEncoder();
}
}
}
Expand Down
36 changes: 36 additions & 0 deletions feign-form-spring/pom.xml
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>
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);
}

}
Loading

0 comments on commit 8252ad6

Please sign in to comment.