1
votes

I have created following simple stream in spring cloud data flow local httpsource | filesink using default properties. I am sending an XML file to httpsource via POST. I am using POSTMAN and doing following settings POST http://144.114.172.3:47783 Body -> form-data Key File of type File and value is chosen XML file contentType : multipart/form-data In file sink I am getting following error

Caused by: org.springframework.core.serializer.support.SerializationFailedException: Unable to deserialize [org.springframework.util.LinkedMultiValueMap] using the contentType [application/x-java-object;type=org.springframework.util.LinkedMultiValueMap] Unable to find class: org.springframework.integration.http.multipart.UploadedMultipartFile; nested exception is com.esotericsoftware.kryo.KryoException: Unable to find class: org.springframework.integration.http.multipart.UploadedMultipartFile at org.springframework.cloud.stream.binder.AbstractBinder.deserializePayload(AbstractBinder.java:265) ~[spring-cloud-stream-1.2.1.RELEASE.jar!/:1.2.1.RELEASE] at org.springframework.cloud.stream.binder.AbstractBinder.deserializePayload(AbstractBinder.java:234) ~[spring-cloud-stream-1.2.1.RELEASE.jar!/:1.2.1.RELEASE] at org.springframework.cloud.stream.binder.AbstractBinder.deserializePayloadIfNecessary(AbstractBinder.java:213) ~[spring-cloud-stream-1.2.1.RELEASE.jar!/:1.2.1.RELEASE] at org.springframework.cloud.stream.binder.AbstractBinder.deserializePayloadIfNecessary(AbstractBinder.java:207) ~[spring-cloud-stream-1.2.1.RELEASE.jar!/:1.2.1.RELEASE] at org.springframework.cloud.stream.binder.AbstractMessageChannelBinder$ReceivingHandler.handleRequestMessage(AbstractMessageChannelBinder.java:291) ~[spring-cloud-stream-1.2.1.RELEASE.jar!/:1.2.1.RELEASE] at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:109) ~[spring-integration-core-4.3.10.RELEASE.jar!/:4.3.10.RELEASE] at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127) ~[spring-integration-core-4.3.10.RELEASE.jar!/:4.3.10.RELEASE] ... 34 common frames omitted Caused by: com.esotericsoftware.kryo.KryoException: Unable to find class: org.springframework.integration.http.multipart.UploadedMultipartFile at com.esotericsoftware.kryo.util.DefaultClassResolver.readName(DefaultClassResolver.java:156) ~[kryo-shaded-3.0.3.jar!/:na] at com.esotericsoftware.kryo.util.DefaultClassResolver.readClass(DefaultClassResolver.java:133) ~[kryo-shaded-3.0.3.jar!/:na] at com.esotericsoftware.kryo.Kryo.readClass(Kryo.java:670) ~[kryo-shaded-3.0.3.jar!/:na] at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:781) ~[kryo-shaded-3.0.3.jar!/:na] at com.esotericsoftware.kryo.serializers.CollectionSerializer.read(CollectionSerializer.java:134) ~[kryo-shaded-3.0.3.jar!/:na] at com.esotericsoftware.kryo.serializers.CollectionSerializer.read(CollectionSerializer.java:40) ~[kryo-shaded-3.0.3.jar!/:na] at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:790) ~[kryo-shaded-3.0.3.jar!/:na] at com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:161) ~[kryo-shaded-3.0.3.jar!/:na] at com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:39) ~[kryo-shaded-3.0.3.jar!/:na] at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:686) ~[kryo-shaded-3.0.3.jar!/:na] at org.springframework.integration.codec.kryo.PojoCodec.doDecode(PojoCodec.java:97) ~[spring-integration-core-4.3.10.RELEASE.jar!/:4.3.10.RELEASE] at org.springframework.integration.codec.kryo.AbstractKryoCodec$3.execute(AbstractKryoCodec.java:96) ~[spring-integration-core-4.3.10.RELEASE.jar!/:4.3.10.RELEASE] at com.esotericsoftware.kryo.pool.KryoPoolQueueImpl.run(KryoPoolQueueImpl.java:61) ~[kryo-shaded-3.0.3.jar!/:na] at org.springframework.integration.codec.kryo.AbstractKryoCodec.decode(AbstractKryoCodec.java:93) ~[spring-integration-core-4.3.10.RELEASE.jar!/:4.3.10.RELEASE] at org.springframework.integration.codec.kryo.AbstractKryoCodec.decode(AbstractKryoCodec.java:79) ~[spring-integration-core-4.3.10.RELEASE.jar!/:4.3.10.RELEASE] at org.springframework.cloud.stream.binder.AbstractBinder.deserializePayload(AbstractBinder.java:260) ~[spring-cloud-stream-1.2.1.RELEASE.jar!/:1.2.1.RELEASE] ... 40 common frames omitted Caused by: java.lang.ClassNotFoundException: org.springframework.integration.http.multipart.UploadedMultipartFile at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_131] at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_131] at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94) ~[filesink-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_131] at java.lang.Class.forName0(Native Method) ~[na:1.8.0_131] at java.lang.Class.forName(Unknown Source) ~[na:1.8.0_131] at com.esotericsoftware.kryo.util.DefaultClassResolver.readName(DefaultClassResolver.java:154) ~[kryo-shaded-3.0.3.jar!/:na] ... 55 common frames omitted

Here is how message from source to sink looks like

(Body:'[B@24fcbde5(byte[4784])' MessageProperties [headers={content-length=4858, http_requestMethod=POST, host=144.114.172.3:47783, http_requestUrl=http://144.114.172.3:47783/, connection=keep-alive, cache-control=no-cache, contentType=application/x-java-object;type=org.springframework.util.LinkedMultiValueMap, accept-encoding=gzip, deflate, accept=/, originalContentType=multipart/form-data;boundary=--------------------------512524439543335584289928;charset=UTF-8, user-agent=PostmanRuntime/6.1.6}, timestamp=null, messageId=null, userId=null, receivedUserId=null, appId=null, clusterId=null, type=null, correlationId=null, correlationIdString=null, replyTo=null, contentType=application/x-java-object;type=org.springframework.util.LinkedMultiValueMap, contentEncoding=null, contentLength=0, deliveryMode=null, receivedDeliveryMode=PERSISTENT, expiration=null, priority=0, redelivered=false, receivedExchange=test.idea-httpsource, receivedRoutingKey=test.idea-httpsource, receivedDelay=null, deliveryTag=6, messageCount=0, consumerTag=amq.ctag-IVuCqSrqPF11rqIS4lPoUg, consumerQueue=test.httpsource.test])

What could be going wrong?

1
So I added spring-integration-http as dependecy in POM and notw getting following error : Caused by: org.springframework.messaging.MessageHandlingException: failed to write Message payload to file; nested exception is java.lang.IllegalArgumentException: unsupported Message payload type [org.springframework.util.LinkedMultiValueMap]gamepop

1 Answers

2
votes

This is due contentType negotiation. When you set the contentType to multipart, the httpsource is probably converting it to LinkedMultiValueMap, and then because the default for java types is to use Kryo serialization, what is sent over the wire is actually a serialized payload of that class. On the receiving side you probably can't deserialize it back.

[Update]

The issue is indeed due content type conversion. Take a look at this section on the spring cloud stream docs: http://docs.spring.io/spring-cloud-stream/docs/Chelsea.BUILD-SNAPSHOT/reference/htmlsingle/#contenttypemanagement

If you send your data as text/plain instead of using POSTMAN. The dataflow shell as a nice utility command : http post that can send data to an app: http post http://localhost:9000 --file logback-spring.xml, with this you will avoid type conversion.

Also please note that you would need to set the directory and file names of the file sink. A simple example would be: --file.directory=/tmp/ --file.name-expression='file.'+headers.id This will create a new file on your /tmp/ dir named 'file.', from this example you could build better expressions to suit your needs