Spring integration Spring集成dsl-HTTP入站网关使用多部分/表单数据
我想通过http inboud网关使用多部分/表单数据。第一部分是对象为json,我想按内容类型将其序列化为对象:application/json。第二部分是pdf文件。可以简单地序列化吗?我需要自定义消息转换器吗 原始请求:Spring integration Spring集成dsl-HTTP入站网关使用多部分/表单数据,spring-integration,spring-integration-dsl,spring-integration-http,Spring Integration,Spring Integration Dsl,Spring Integration Http,我想通过http inboud网关使用多部分/表单数据。第一部分是对象为json,我想按内容类型将其序列化为对象:application/json。第二部分是pdf文件。可以简单地序列化吗?我需要自定义消息转换器吗 原始请求: POST http://localhost:18080/api/v2/attachments HTTP/1.1 Content-Type: multipart/form-data; boundary=-------------------------acebdf13572
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--
编辑:
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--
我已经在SpringBoot2.0.3.0版本上试用过了。它似乎不适用于org.springframework.web.multipart.commons.commons MultipartResolver
。在有效负载中,我总是看到空的LinkedMultiValueMap。但我注意到它在默认配置下正常工作org.springframework.web.multipart.support.StandardServletMultipartResolver
。
CommonsMultipartResolver和StandardServletMultipartResolver之间的区别是什么
依赖关系
+- 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
首先,您需要将
StandardServletMultipartResolver
注册为DispatcherServlet.MULTIPART\u RESOLVER\u BEAN\u NAME
BEAN:
然后您需要期望一个多值映射
作为下游的有效负载。只有在那里你才能对地图的每一部分做些什么
另请参阅有关此问题的一些Spring集成示例:感谢您的快速响应。我更新了我的问题我不知道为什么它不起作用。可能有些版本不兼容。我们需要分开玩。但是既然您说
StandardServletMultipartResolver
适合您,那么让我们将其作为继续并解决问题的指示!