Re: [xSocket-develop] Proxy example - piping data to file
Status: Inactive
Brought to you by:
grro
|
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 > |