It is a Spring Integration (based on Spring Boot) project, I've configured Spring Integration application as below,
Configuration xml:
<int:channel id="httpChannel"/>
<int-http:inbound-gateway supported-methods="GET,POST" request-channel="httpChannel" reply-channel="outputChannel" path="/"
message-converters="converter"
/>
<bean id="converter" class="in.tc.springintegrationdemo.CustomConverter" />
<int:transformer ref="customTransformer" input-channel="httpChannel" output-channel="outputChannel" />
<bean id="customTransformer" class="in.tc.springintegrationdemo.MultipartTransformer" />
<bean class="in.tc.springintegrationdemo.MessageUpdateBean" id="printMessage"/>
<int:service-activator ref="printMessage" method="print" input-channel="outputChannel">
</int:service-activator>
CustomConverter defined as below
public class CustomConverter implements HttpMessageConverter<MultiValueMap<String,?>> {
@Override
public boolean canRead(Class<?> clazz, MediaType mediaType) {
...
}
@Override
public boolean canWrite(Class<?> clazz, MediaType mediaType) {
return false;
}
@Override
public List<MediaType> getSupportedMediaTypes() {
return Collections.singletonList(MediaType.MULTIPART_FORM_DATA);
}
@Override
public MultiValueMap<String,?> read(Class<? extends MultiValueMap<String,?>> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
MultiValueMap<String, ?> result = new LinkedMultiValueMap<>();
String str = "";
MediaType contentType = inputMessage.getHeaders().getContentType();
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(inputMessage.getBody(), contentType.getCharset()));
while((str=bufferedReader.readLine())!=null) {
//code to retrieve multipart data
}
return result;
}
@Override
public void write(MultiValueMap<String,?> t, MediaType contentType, HttpOutputMessage outputMessage)
throws IOException, HttpMessageNotWritableException {
throw new UnsupportedOperationException();
}
for multipart/form-data, I'm always getting a blank payload in CustomConverter class.
I've also tried adding a multipartResolver as below
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/> but it has the same result.
I've followed a similar question on stackoverflow Spring Integration dsl - HTTP inbound gateway consume multipart/form-data.
But for me it's not working.
Multipart/form-data payload
POST / HTTP/1.1
User-Agent: PostmanRuntime/7.26.8
Accept: */*
Postman-Token: d24d89ef-c52b-492a-96b9-6ef6807e8d1a
Host: localhost:9090
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Type: multipart/form-data; boundary=--------------------------865732735860935509694157
Content-Length: 217
----------------------------865732735860935509694157
Content-Disposition: form-data; name=""; filename="testfile.txt"
Content-Type: text/plain
testcontent
----------------------------865732735860935509694157--
Thanks in anticipation.
question from:
https://stackoverflow.com/questions/66051029/spring-integration-unable-to-process-multipart-form-data-with-http-inbound-gat 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…