UnsupportedOperationException thrown when Proxying File Upload

174 views
Skip to first unread message

Chathurika Sandarenu

unread,
May 19, 2015, 12:47:10 PM5/19/15
to littl...@googlegroups.com

Hi,

I got following error when I was trying to proxy a file upload using little proxy. 
Request doesn't go the real server. Exception is thrown before that.

jvm 1    | 2015-05-19 21:15:31,829 DEBUG ClientToProxyConnection [] [LittleProxy-ClientToProxyWorker-2] - (AWAITING_INITIAL): Configuring ChannelPipeline
jvm 1    | 2015-05-19 21:15:31,830 DEBUG ClientToProxyConnection [] [LittleProxy-ClientToProxyWorker-2] - (AWAITING_INITIAL): Created ClientToProxyConnection
jvm 1    | 2015-05-19 21:15:31,831 DEBUG ClientToProxyConnection [] [LittleProxy-ClientToProxyWorker-2] - (AWAITING_INITIAL) [id: 0x3fd92bb1, /127.0.0.1:34704 => /127.0.0.1:8082]: Connected
jvm 1    | 2015-05-19 21:15:32,831 ERROR ClientToProxyConnection [] [LittleProxy-ClientToProxyWorker-2] - (AWAITING_INITIAL) [id: 0x3fd92bb1, /127.0.0.1:34704 => /127.0.0.1:8082]: Caught an exception on ClientToProxyConnection
jvm 1    | java.lang.UnsupportedOperationException: unsupported message type: DefaultFullHttpResponse (expected: ByteBuf, FileRegion)
jvm 1    |  at io.netty.channel.nio.AbstractNioByteChannel.filterOutboundMessage(AbstractNioByteChannel.java:276)
jvm 1    |  at io.netty.channel.AbstractChannel$AbstractUnsafe.write(AbstractChannel.java:654)
jvm 1    |  at io.netty.channel.DefaultChannelPipeline$HeadContext.write(DefaultChannelPipeline.java:1054)
jvm 1    |  at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:658)
jvm 1    |  at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:716)
jvm 1    |  at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:706)
jvm 1    |  at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:741)
jvm 1    |  at io.netty.handler.codec.http.HttpObjectAggregator.decode(HttpObjectAggregator.java:131)
jvm 1    |  at io.netty.handler.codec.http.HttpObjectAggregator.decode(HttpObjectAggregator.java:54)
jvm 1    |  at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89)
jvm 1    |  at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
jvm 1    |  at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
jvm 1    |  at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
jvm 1    |  at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
jvm 1    |  at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
jvm 1    |  at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)
jvm 1    |  at org.littleshoot.proxy.impl.ProxyConnection$RequestReadMonitor.channelRead(ProxyConnection.java:699)
jvm 1    |  at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
jvm 1    |  at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
jvm 1    |  at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:163)
jvm 1    |  at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
jvm 1    |  at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
jvm 1    |  at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)
jvm 1    |  at org.littleshoot.proxy.impl.ProxyConnection$BytesReadMonitor.channelRead(ProxyConnection.java:676)
jvm 1    |  at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
jvm 1    |  at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
jvm 1    |  at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787)
jvm 1    |  at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:130)
jvm 1    |  at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
jvm 1    |  at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
jvm 1    |  at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
jvm 1    |  at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
jvm 1    |  at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
jvm 1    |  at java.lang.Thread.run(Thread.java:744)
jvm 1    | 2015-05-19 21:15:32,836 DEBUG ClientToProxyConnectio

I'm using following CURL to send the request.

curl -v -H "Content-Type: multipart/form-data" -k http://localhost:8082/group/upload -F csv=@"Contact-List-with-names.csv" -F appId="APP_000001" -F groupId="GRP_000001"

My Filter looks like follows.

new HttpFiltersSourceAdapter() {
            public HttpFilters filterRequest(HttpRequest originalRequest, ChannelHandlerContext ctx) {
               return new HttpFiltersAdapter(originalRequest) {
                  @Override
                  public HttpResponse clientToProxyRequest(HttpObject httpObject) {
                      // TODO: implement your filtering here ????
                       if(httpObject instanceof FullHttpRequest){
                                   FullHttpRequest httpRequest = (FullHttpRequest)httpObject;
                                   httpRequest.headers().remove("Host")
                                   httpRequest.headers().add("Host", "localhost:8080")
                        }
                      return null;
                  }

                  @Override
                  public HttpResponse proxyToServerRequest(HttpObject httpObject) {
                      // TODO: implement your filtering here ????
                      return null;
                  }

                  @Override
                  public HttpObject serverToProxyResponse(HttpObject httpObject) {
                      // TODO: implement your filtering here ????
                      return httpObject;
                  }

                  @Override
                  public HttpObject proxyToClientResponse(HttpObject httpObject) {
                      // TODO: implement your filtering here ????
                      return httpObject;
                  }   
               };
            }
        }

I get above error even when real server is down as well. What am I doing wrong here?


Thanks and Regards,

Sandarenu.

Frank Ganske

unread,
May 19, 2015, 1:34:57 PM5/19/15
to littl...@googlegroups.com
Hello,

please check your curl line.

This works for me:
- I've started hudson-ci on localhost:8084 since it provides an API
for POST requests.
- I've created a job "test" and copied the config.xml from
~/.hudson/test/config.xml to my working dir.
- This command create a second job via file upload:
$ curl -H "Content-Type: text/xml" --data @config.xml
http://localhost:8084/createItem?name=test2
- This command create a third job via a LittleProxy on port 9090:
$ curl -x localhost:9090 -H "Content-Type: text/xml" --data @config.xml
http://localhost:8084/createItem?name=test3

$ curl --version
curl 7.38.0 (x86_64-pc-linux-gnu) libcurl/7.38.0 OpenSSL/1.0.1k
zlib/1.2.8 libidn/1.29 libssh2/1.4.3 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps
pop3 pop3s rtmp rtsp scp sftp smtp smtps telnet tftp
Features: AsynchDNS IDN IPv6 Largefile GSS-API SPNEGO NTLM NTLM_WB SSL
libz TLS-SRP
> --
> You received this message because you are subscribed to the Google
> Groups "LittleProxy" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to littleproxy...@googlegroups.com
> <mailto:littleproxy...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages