I would like to consume multipart/form-data through http inboud gateway. First part is object as json which I want to serialize it to object by content-type: application/json. And second part is pdf file. Is it possible to simply serialize? Do I need my custom message converter?
RAW request:
POST http://localhost:18080/api/v2/attachments HTTP/1.1
Content-Type: multipart/form-data; boundary=-------------------------acebdf13572468
Host: localhost:18080
Content-Length: 542
---------------------------acebdf13572468
Content-Disposition: form-data; name="metadata"
Content-Type: application/json
{
"version" : "1.0",
}
---------------------------acebdf13572468
Content-Disposition: form-data; name="file"; filename="test.pdf"
Content-Type: application/pdf
<<pdf data>>
---------------------------acebdf13572468--
HTTP Inboud Gateway
@Bean
public IntegrationFlow multipartForm() {
return IntegrationFlows.from(Http.inboundGateway("/api/v2/attachments")
.errorChannel("rest.general.error")
.requestMapping(m -> m
.methods(HttpMethod.POST)
.consumes(MediaType.MULTIPART_FORM_DATA_VALUE)
))
.channel("requestAttachment.input")
.get();
}
EDIT:
I have tried it on spring boot 2.0.3.RELEASE. It seems that it is not working with org.springframework.web.multipart.commons.CommonsMultipartResolver
. In the payload I always see empty LinkedMultiValueMap. But I noticed that it is working correctly with default configuration org.springframework.web.multipart.support.StandardServletMultipartResolver
.
What is difference between CommonsMultipartResolver and StandardServletMultipartResolver?
dependencies
+- org.springframework.boot:spring-boot-starter-web:jar:2.0.3.RELEASE:compile
| +- org.springframework.boot:spring-boot-starter:jar:2.0.3.RELEASE:compile
| | +- org.springframework.boot:spring-boot:jar:2.0.3.RELEASE:compile
| | +- org.springframework.boot:spring-boot-autoconfigure:jar:2.0.3.RELEASE:compile
| | +- org.springframework.boot:spring-boot-starter-logging:jar:2.0.3.RELEASE:compile
| | | +- ch.qos.logback:logback-classic:jar:1.2.3:compile
| | | | \- ch.qos.logback:logback-core:jar:1.2.3:compile
| | | +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.10.0:compile
| | | | \- org.apache.logging.log4j:log4j-api:jar:2.10.0:compile
| | | \- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
| | +- javax.annotation:javax.annotation-api:jar:1.3.2:compile
| | \- org.yaml:snakeyaml:jar:1.19:runtime
| +- org.springframework.boot:spring-boot-starter-json:jar:2.0.3.RELEASE:compile
| | +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.6:compile
| | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
| | | \- com.fasterxml.jackson.core:jackson-core:jar:2.9.6:compile
| | +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.9.6:compile
| | +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.9.6:compile
| | \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.9.6:compile
| +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.0.3.RELEASE:compile
| | +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.31:compile
| | +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.31:compile
| | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.31:compile
| +- org.hibernate.validator:hibernate-validator:jar:6.0.10.Final:compile
| | +- javax.validation:validation-api:jar:2.0.1.Final:compile
| | +- org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
| | \- com.fasterxml:classmate:jar:1.3.4:compile
| +- org.springframework:spring-web:jar:5.0.7.RELEASE:compile
| | \- org.springframework:spring-beans:jar:5.0.7.RELEASE:compile
| \- org.springframework:spring-webmvc:jar:5.0.7.RELEASE:compile
| +- org.springframework:spring-aop:jar:5.0.7.RELEASE:compile
| +- org.springframework:spring-context:jar:5.0.7.RELEASE:compile
| \- org.springframework:spring-expression:jar:5.0.7.RELEASE:compile
+- org.springframework.boot:spring-boot-starter-data-jpa:jar:2.0.3.RELEASE:compile
| +- org.springframework.boot:spring-boot-starter-aop:jar:2.0.3.RELEASE:compile
| | \- org.aspectj:aspectjweaver:jar:1.8.13:compile
| +- org.springframework.boot:spring-boot-starter-jdbc:jar:2.0.3.RELEASE:compile
| | +- com.zaxxer:HikariCP:jar:2.7.9:compile
| | \- org.springframework:spring-jdbc:jar:5.0.7.RELEASE:compile
| +- org.hibernate:hibernate-core:jar:5.3.1.Final:compile
| | +- javax.persistence:javax.persistence-api:jar:2.2:compile
| | +- org.javassist:javassist:jar:3.22.0-GA:compile
| | +- net.bytebuddy:byte-buddy:jar:1.7.11:compile
| | +- antlr:antlr:jar:2.7.7:compile
| | +- org.jboss:jandex:jar:2.0.3.Final:compile
| | +- dom4j:dom4j:jar:1.6.1:compile
| | \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.3.Final:compile
| +- javax.transaction:javax.transaction-api:jar:1.2:compile
| +- org.springframework.data:spring-data-jpa:jar:2.0.8.RELEASE:compile
| | +- org.springframework.data:spring-data-commons:jar:2.0.8.RELEASE:compile
| | +- org.springframework:spring-tx:jar:5.0.7.RELEASE:compile
| | \- org.slf4j:slf4j-api:jar:1.7.25:compile
| \- org.springframework:spring-aspects:jar:5.0.7.RELEASE:compile
+- org.springframework.boot:spring-boot-starter-integration:jar:2.0.3.RELEASE:compile
| \- org.springframework.integration:spring-integration-core:jar:5.0.6.RELEASE:compile
| +- org.springframework:spring-messaging:jar:5.0.7.RELEASE:compile
| +- org.springframework.retry:spring-retry:jar:1.2.2.RELEASE:compile
| \- io.projectreactor:reactor-core:jar:3.1.8.RELEASE:compile
| \- org.reactivestreams:reactive-streams:jar:1.0.2:compile
+- org.springframework.integration:spring-integration-http:jar:5.0.6.RELEASE:compile
+- org.springframework.integration:spring-integration-jpa:jar:5.0.6.RELEASE:compile
| \- org.springframework:spring-orm:jar:5.0.7.RELEASE:compile
+- commons-fileupload:commons-fileupload:jar:1.3.3:compile
| \- commons-io:commons-io:jar:2.2:compile
+- com.h2database:h2:jar:1.4.197:runtime
+- net.rakugakibox.spring.boot:orika-spring-boot-starter:jar:1.6.0:compile
| \- ma.glasnost.orika:orika-core:jar:1.5.2:compile
| +- com.thoughtworks.paranamer:paranamer:jar:2.8:compile
| +- com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:jar:1.4.2:compile
| +- com.carrotsearch:java-sizeof:jar:0.0.4:compile
| \- org.codehaus.janino:janino:jar:3.0.8:compile
| \- org.codehaus.janino:commons-compiler:jar:3.0.8:compile
+- sk.cfh.demo:demo-rest-docs-api:jar:1.0-SNAPSHOT:compile
+- org.springframework.boot:spring-boot-starter-test:jar:2.0.3.RELEASE:test
| +- org.springframework.boot:spring-boot-test:jar:2.0.3.RELEASE:test
| +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.0.3.RELEASE:test
| +- com.jayway.jsonpath:json-path:jar:2.4.0:test
| | \- net.minidev:json-smart:jar:2.3:test
| | \- net.minidev:accessors-smart:jar:1.2:test
| | \- org.ow2.asm:asm:jar:5.0.4:test
| +- junit:junit:jar:4.12:test
| +- org.assertj:assertj-core:jar:3.9.1:test
| +- org.mockito:mockito-core:jar:2.15.0:test
| | +- net.bytebuddy:byte-buddy-agent:jar:1.7.11:test
| | \- org.objenesis:objenesis:jar:2.6:test
| +- org.hamcrest:hamcrest-core:jar:1.3:test
| +- org.hamcrest:hamcrest-library:jar:1.3:test
| +- org.skyscreamer:jsonassert:jar:1.5.0:test
| | \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
| +- org.springframework:spring-core:jar:5.0.7.RELEASE:compile
| | \- org.springframework:spring-jcl:jar:5.0.7.RELEASE:compile
| +- org.springframework:spring-test:jar:5.0.7.RELEASE:test
| \- org.xmlunit:xmlunit-core:jar:2.5.1:test
+- org.springframework.restdocs:spring-restdocs-mockmvc:jar:2.0.1.RELEASE:test
| +- javax.servlet:javax.servlet-api:jar:3.1.0:test
| \- org.springframework.restdocs:spring-restdocs-core:jar:2.0.1.RELEASE:test
\- org.junit.jupiter:junit-jupiter-engine:jar:5.2.0:test
+- org.apiguardian:apiguardian-api:jar:1.0.0:test
+- org.junit.platform:junit-platform-engine:jar:1.2.0:test
| +- org.junit.platform:junit-platform-commons:jar:1.2.0:test
| \- org.opentest4j:opentest4j:jar:1.1.0:test
\- org.junit.jupiter:junit-jupiter-api:jar:5.1.1:test