Thread: Re: [xSocket-develop] Proxy example - piping data to file
Status: Inactive
Brought to you by:
grro
|
From: <gre...@we...> - 2008-04-10 11:18:53
|
Hi Martin, the xSocket Junit test BodyForwardingTest (http://xsocket.svn.sourceforge.net/viewvc/xsocket/xsocket/http/tags/V2_0_alpha4/src/test/java/org/xsocket/connection/http/BodyForwardingTest.java) contains a ForwardHandler which shows you how to control the message/body streaming. One fast way to fetch the complete message header is to call the toString method ... HttpResponseHeader resHdr = response.getResponseHeader(); String hdrCopy = resHdr.toString(); FileChannel fileChannel = new .... fileChannel.write(...) ... The body data can be fetched by duplicating the body ByteBuffer : ... ByteBuffer[] data = bodyDataSource.readByteBufferByLength(available); for (ByteBuffer buf : data) { fileChannel.write(buf.duplicate()); } dataSink.write(data); ... Take care with the NonThreaded annotations of the example code. If you are writing to a file, the handler should run in a multithreaded mode. The Nonthreaded annotation should be removed. Gregor > -----Ursprüngliche Nachricht----- > Von: "Martin Thelian" <Mar...@gm...> > Gesendet: 10.04.08 09:56:16 > An: xso...@li... > Betreff: [xSocket-develop] Proxy example - piping data to file > > Hi, > > I would like to use xsocket as described in [1] chapter "3.2 Reusing message objects - a proxy example" and additionally I would like to pipe the response-message into a file while transfering it back to the client. > > What is the best way to do this? > > Thanks, > Martin > > [1] http://xsocket.sourceforge.net/http/tutorial/V2/TutorialHttp.htm > -- > Psssst! Schon vom neuen GMX MultiMessenger gehört? > Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger > > ------------------------------------------------------------------------- > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference > Don't miss this year's exciting event. There's still time to save $100. > Use priority code J8TL2D2. > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone > _______________________________________________ > xSocket-develop mailing list > xSo...@li... > https://lists.sourceforge.net/lists/listinfo/xsocket-develop |
|
From: <gre...@we...> - 2008-04-25 14:01:12
|
Hi Martin, the HttpServer.setWriteTransferRate() is a unsupported method. Currently throttling is not supported. A built-in throttling support should be available in future versions. Please file a feature request, with your requirements (http://sourceforge.net/tracker/?atid=850945&group_id=169583). Thanks Gregor > -----Ursprüngliche Nachricht----- > Von: "Martin Thelian" <Mar...@gm...> > Gesendet: 25.04.08 08:00:50 > An: gre...@we... > Betreff: Re: [xSocket-develop] Proxy example - piping data to file Hi, > > does configuring the transfer rate via HttpServer.setWriteTransferRate( > ) work with this approach? I've tried to limit the transfer rate to > 5KB/s but currently my test-download uses 200KB/s. > > Martin > > gre...@we... schrieb:Hi Martin, the xSocket Junit test > BodyForwardingTest (http://xsocket.svn.sourceforge.net/viewvc/xsocket/ > xsocket/http/tags/V2_0_alpha4/src/test/java/org/xsocket/connection/ > http/BodyForwardingTest.java) contains a ForwardHandler which shows > you how to control the message/body streaming. One fast way to fetch > the complete message header is to call the toString method ... > HttpResponseHeader resHdr = response.getResponseHeader(); String > hdrCopy = resHdr.toString(); FileChannel fileChannel = new .... > fileChannel.write(...) ... The body data can be fetched by duplicating > the body ByteBuffer : ... ByteBuffer[] data = bodyDataSource. > readByteBufferByLength(available); for (ByteBuffer buf : data) { > fileChannel.write(buf.duplicate()); } dataSink.write(data); ... Take > care with the NonThreaded annotations of the example code. If you are > writing to a file, the handler should run in a multithreaded mode. > The Nonthreaded annotation should be removed. Gregor -----Ursprüngliche > Nachricht----- Von: "Martin Thelian" <Mar...@gm...>Gesendet: > 10.04.08 09:56:16 An: xso...@li...: [ > xSocket-develop] Proxy example - piping data to file Hi, I would like > to use xsocket as described in [1] chapter "3.2 Reusing message > objects - a proxy example" and additionally I would like to pipe the > response-message into a file while transfering it back to the client. > What is the best way to do this? Thanks, Martin [1] http://xsocket. > sourceforge.net/http/tutorial/V2/TutorialHttp.htm-- Psssst! Schon vom > neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx. > net/de/go/multimessenger---------------------------------------------- > --------------------------- This SF.net email is sponsored by the > 2008 JavaOne(SM) Conference Don't miss this year's exciting event. > There's still time to save $100. Use priority code J8TL2D2. http://ad. > doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone__ > _____________________________________________ xSocket-develop mailing > lis...@li...://lists.sourceforge. > net/lists/listinfo/xsocket-develop > > -- Gregor Roth |
|
From: Martin T. <Mar...@gm...> - 2008-04-11 00:00:12
|
Hi, thank you for your hints. Now it works :-) One pitfall was that if I'm using |> responseCtx.send(respHdr); instead of |> responseCtx.send(respHdr,respHdr.getContentLength()); if the content-length header is available, then the body is transfered using transfer-encoding but without setting the proper transfer-encoding header. Another bug I've found is > java.lang.ArrayIndexOutOfBoundsException: 1 > at > org.xsocket.connection.http.HttpRequestHeader.getParamMap(HttpRequestHeader.java:580) > at > org.xsocket.connection.http.HttpRequestHeader.getParameterMap(HttpRequestHeader.java:535) > at > org.paxle.crawler.proxy.impl.ProxyResponseHandler.shouldCrawl(ProxyResponseHandler.java:128) > at > org.paxle.crawler.proxy.impl.ProxyResponseHandler.onResponse(ProxyResponseHandler.java:81) > at > org.xsocket.connection.http.client.HttpClientConnection$ResponseHandlerAdapter.performOnResponse(HttpClientConnection.java:967) > at > org.xsocket.connection.http.client.HttpClientConnection$ResponseHandlerAdapter.run(HttpClientConnection.java:961) > at > org.xsocket.connection.http.AbstractHttpConnection.performPendingTasks(AbstractHttpConnection.java:796) > at > org.xsocket.connection.http.AbstractHttpConnection.access$500(AbstractHttpConnection.java:67) > at > org.xsocket.connection.http.AbstractHttpConnection$MultithreadedTaskProcessor.run(AbstractHttpConnection.java:826) > at > java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650) > at > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675) > at java.lang.Thread.run(Thread.java:595) The query-parameter parser seems to assume that an http-query-parameter always has a value. Regards, Martin gre...@we... schrieb: > Hi Martin, > > the xSocket Junit test BodyForwardingTest (http://xsocket.svn.sourceforge.net/viewvc/xsocket/xsocket/http/tags/V2_0_alpha4/src/test/java/org/xsocket/connection/http/BodyForwardingTest.java) contains a ForwardHandler which shows you how to control the message/body streaming. > > One fast way to fetch the complete message header is to call the toString method > > ... > HttpResponseHeader resHdr = response.getResponseHeader(); > > String hdrCopy = resHdr.toString(); > FileChannel fileChannel = new .... > fileChannel.write(...) > ... > > > The body data can be fetched by duplicating the body ByteBuffer : > > ... > ByteBuffer[] data = bodyDataSource.readByteBufferByLength(available); > > for (ByteBuffer buf : data) { > fileChannel.write(buf.duplicate()); > } > > dataSink.write(data); > ... > > Take care with the NonThreaded annotations of the example code. If you are writing to a file, the handler should run in a multithreaded mode. The Nonthreaded annotation should be removed. > > > Gregor > |