I have to believe that I am doing this the hard way. I am retrieving and XML
response from a server and am writing an HttpResponseInterceptor to capture
the bytes as a string while the normal flow passes the response on to the
application as a parsed xml document.

So, I have something like this. Any suggestions?


    captureEntity = new MyCaptureEntity()

    client.addResponseInterceptor( captureEntity )

    println captureEntity.capturedText()


    class MyCaptureIntercaptor implements HttpResponseInterceptor {
        ... process(...) {

            response.setEntity( new MyCaptureEntity( response.getEntity() )
)
        }
    }

    class MyCaptureEntity extends HttpEntityWrapper {
        ... getContent() {
             return new MyCaptureStream( wrappedEntity.getContent() );
        }
    }

    class MyCaptureStream extends BufferedInputStream {
        ... read(b, off, len) {
            int bytesRead = super.read(b,off,len)

            if (bytesRead > 0) {
                println new String(b, off, len)
            }

            return bytesRead
        }
    }



Ed Sumerfield

Reply via email to