hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Florent Georges <li...@fgeorges.org>
Subject Re: ContentProducer.writeTo() not called?
Date Wed, 11 Mar 2009 15:39:40 GMT
Oleg Kalnichevski wrote:
> Florent Georges wrote:

  Thanks for your response, Oleg.

> >   After having investigated further, I found the following
> > weird situation.  If I write a proxy HttpEntity, that wraps
> > the EntityTemplate, it seems writeTo() is never called
> > because getContentLength() does return -1.

> I am not sure I understand. What proxy entity? What does this
> all have to do with getContentLength() returning -1?

  Sorry, I should have explained that I guess.  By proxy, I
meant the Proxy pattern, a class implementing an interface but
delegating to another object implementing the same interface
<http://en.wikipedia.org/wiki/Proxy_pattern>, here for debugging

    private static class EntityProxy
            implements HttpEntity
        public EntityProxy(HttpEntity proxied) {
            myProxied = proxied;

        public long getContentLength() {
            long len = myProxied.getContentLength();
            System.err.println("getContentLength(): " + len);
            return len;


        private HttpEntity myProxied;

  By using such an object wrapping the EntityTemplate, I've seen
writeTo() was never called.  But if I used a StringEntity, I've
seen it was called.  As one of the difference between both
object was the result of getContentLength(), I tried to override
it and return the length of the string, and that time, writeTo()
was called...  But I am not sure this is relevant, in particular
because of the test described below.

> The following code works just fine for me. See wire log below.

  Thank you very much for your test.

  I tried it (by copy&paste), but it seems the content is not
written out.  I paste the logs at the end of the message, and
attach the Java class source.  If I change your ContentProducer
by adding output and overriding getContentLength(), it seems
they are never called:

    new ContentProducer() {
        public void writeTo(OutputStream outstream)
                throws IOException {
        public long getContentLength() {
            return 10;

  The relevant logs (all wire logs in the way >>, see all logs in attachment):

[DEBUG] wire - >> "POST / HTTP/1.1[EOL]"
[DEBUG] wire - >> "Transfer-Encoding: chunked[EOL]"
[DEBUG] wire - >> "Content-Type: application/xml[EOL]"
[DEBUG] wire - >> "Host: localhost:8079[EOL]"
[DEBUG] wire - >> "Connection: Keep-Alive[EOL]"
[DEBUG] wire - >> "User-Agent: Apache-HttpClient/4.0-beta2 (java 1.5)[EOL]"
[DEBUG] wire - >> "Expect: 100-Continue[EOL]"
[DEBUG] wire - >> "[EOL]"

  I do not know if I can provide you with more information, or
if I can check some setup data.  I use HTTP Core 4.0 and HTTP
Client 4.0beta2.

  Thanks for your help, regards,

Florent Georges


View raw message