Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support MultipartBody uploads with declarative HTTP client #722

Closed
goeh opened this issue Oct 12, 2018 · 6 comments
Closed

Support MultipartBody uploads with declarative HTTP client #722

goeh opened this issue Oct 12, 2018 · 6 comments
Assignees
Labels
closed: notabug The issue is not a bug

Comments

@goeh
Copy link
Contributor

goeh commented Oct 12, 2018

Upload MultipartBody with declarative HTTP @client seems to be unsupported. It would be nice if it was.

Steps to Reproduce

  1. Create a HTTP @client that takes a MultipartBody as request body
  2. Call the client method
  3. A serialization exception is thrown

Expected Behaviour

A multipart request should be sent to the destination

Actual Behaviour

| 08:35:06.552 [nioEventLoopGroup-1-9] WARN  i.n.util.concurrent.DefaultPromise - An exception was thrown by io.micronaut.http.client.DefaultHttpClient$$Lambda$475/670393269.operationComplete()
| io.micronaut.http.codec.CodecException: Error encoding object [io.micronaut.http.client.multipart.MultipartBody@740893f4] to JSON: No serializer found for class io.micronaut.http.client.multipart.MultipartBody and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
| 	at io.micronaut.jackson.codec.JsonMediaTypeCodec.encode(JsonMediaTypeCodec.java:174)
| 	at io.micronaut.jackson.codec.JsonMediaTypeCodec.encode(JsonMediaTypeCodec.java:180)
| 	at io.micronaut.http.client.DefaultHttpClient.lambda$buildNettyRequest$36(DefaultHttpClient.java:1474)
| 	at java.util.Optional.map(Optional.java:215)
| 	at io.micronaut.http.client.DefaultHttpClient.buildNettyRequest(DefaultHttpClient.java:1474)
| 	at io.micronaut.http.client.DefaultHttpClient.prepareRequest(DefaultHttpClient.java:1910)
| 	at io.micronaut.http.client.DefaultHttpClient.streamRequestThroughChannel(DefaultHttpClient.java:1547)
| 	at io.micronaut.http.client.DefaultHttpClient.lambda$null$20(DefaultHttpClient.java:938)

Environment Information

  • Operating System: MacOS 10.14
  • Micronaut Version: 1.0.0.RC2
  • JDK Version: 1.8.0_162-b12

Example Application

@goeh goeh changed the title Support MultipartBody uploads with declarative HTTP cient Support MultipartBody uploads with declarative HTTP client Oct 12, 2018
@graemerocher graemerocher added type: enhancement New feature or request help wanted Extra attention is needed labels Oct 12, 2018
@goeh
Copy link
Contributor Author

goeh commented Oct 12, 2018

The sample application includes a test with the standard HTTP client and that test passes but with a warning. I don't know if I'm guilty or if the framework does something wrong. Maybe it's related to issue #721

13:09:23.282 [nioEventLoopGroup-1-3] WARN  i.n.channel.DefaultChannelPipeline - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
io.netty.util.IllegalReferenceCountException: refCnt: 0, decrement: 1
	at io.netty.buffer.AbstractReferenceCountedByteBuf.release0(AbstractReferenceCountedByteBuf.java:100)
	at io.netty.buffer.AbstractReferenceCountedByteBuf.release(AbstractReferenceCountedByteBuf.java:84)
	at io.netty.handler.codec.http.HttpObjectAggregator$AggregatedFullHttpMessage.release(HttpObjectAggregator.java:386)
	at io.netty.util.ReferenceCountUtil.release(ReferenceCountUtil.java:88)
	at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:112)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
	at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
	at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:438)
	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310)
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:284)
	at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:253)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
	at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:628)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:563)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:480)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:442)
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.lang.Thread.run(Thread.java:748)

@goeh
Copy link
Contributor Author

goeh commented Oct 12, 2018

I created issue #726 for the IllegalReferenceCountException problem.

@jameskleeh jameskleeh added closed: invalid The issue doesn't seem right and removed help wanted Extra attention is needed type: enhancement New feature or request labels Oct 12, 2018
@jameskleeh
Copy link
Contributor

@goeh You have to set the correct content type. The test passes with
@Post(produces = MediaType.MULTIPART_FORM_DATA)

@jameskleeh jameskleeh added closed: notabug The issue is not a bug and removed closed: invalid The issue doesn't seem right labels Oct 12, 2018
@jameskleeh
Copy link
Contributor

@goeh I noticed that the same warning occurs when the declarative client is used. This is a different issue than 726 and I'm going to push the fix soon

@goeh
Copy link
Contributor Author

goeh commented Oct 12, 2018

@jameskleeh I just added produces = "...." and you are correct, it works. That's awesome, thanks!
Could the documentation be more specific about this or did I miss it?

@jameskleeh
Copy link
Contributor

@goeh Perhaps it could, I'm not sure. If you think the docs could be made more clear please submit a PR.

@jameskleeh jameskleeh self-assigned this Oct 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed: notabug The issue is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants