Jerome,

Thank you for the response...I thought I had an Aha! moment there. :)

I've changed my Representation to set the size to Representation.UNKNOWN_SIZE, 
however, I still think I am having a problem. I think the problem lies in the 
Message.isEntityAvailable() method, shown here:

    public boolean isEntityAvailable()
    {
        return (getEntity() != null) && (getEntity().getSize() > 0)
            && getEntity().isAvailable();
    }

The entity is my Representation class which returns a -1 size, however it is 
still checking to see if the size of the entity is greater than 0, not "!=" to 
0. This then returns false, and the calling method, which is 
HttpClientCall.sendRequest() still determines that the Representation entity is 
null and doesn't send the data.

Thanks,

Mitch

-----Original Message-----
From: Jerome Louvel [mailto:[EMAIL PROTECTED]
Sent: Thu 11/23/2006 3:32 AM
To: discuss@restlet.tigris.org
Subject:  RE: POSTing dynamic Representations
 

Hi Mitch,

You got nearly everything right. The only thing that you missed is that when
the size of a Representation is unknown, you need to set it to -1 (using the
Representation.UNKNOWN_SIZE constant). Setting the size to 0 means that
there is no content in the representation which is not true in your case.

Best regards,
Jerome  

> -----Message d'origine-----
> De : Mitch Stewart [mailto:[EMAIL PROTECTED] 
> Envoyé : mercredi 22 novembre 2006 22:19
> À : discuss@restlet.tigris.org
> Objet : POSTing dynamic Representations
> 
> 
> 
> I'm using the Restlet HTTP client implementation to post a 
> dynamic Representation to my Restlet server implementation, 
> however it doesn't look like my data is getting written to 
> the HTTP stream. I might be missing something critical, but 
> I've been able to understand the API so far. :) My 
> Representation class resembles the ObjectRepresentation that 
> already exists, except instead of serializing a Java object 
> to an ObjectOutputStream, it serializes a Java object to an 
> XML stream. But, testing with the ObjectRepresentation 
> produces the same result.
> 
> Here's the basics of what I am trying to do:
> 
>     Client client = new Client(Protocol.HTTP);
>     Response response = 
> client.post("http://somehost.com/someurl";, new 
> ObjectRepresentation("TestData"));
> 
> 
> The response variable is not filled with any status or response.
> 
> Drilling down through the code I think I found the culprit:
> 
> in com.noelios.restlet.http.HttpClientCall.sendRequest() 
> there's a check to see if an entity exists:
> 
>     Representation entity = request.isEntityAvailable() ? 
> request.getEntity() : null;
>                
>     if(entity != null)
>     {
>         //The code to write the representation to the output stream.
>     }
> 
> 
> The call to request.isEntityAvailable() goes back to the 
> org.restlet.data.Message class which checks that the entity 
> is not null and that the size of the entity is greater than 
> 0. This is where I'm having difficulty. In my Representation, 
> I do not know the size of the resulting data prior to it 
> being written to the output stream, so my size is 0. However, 
> if you look at the 
> com.noelios.restlet.ext.net.HttpUrlConnectionCall.sendRequest(
> ) method, you see this:
> 
>     // Adjust the streaming mode
>     if (entity.getSize() > 0)
>     {
>         // The size of the entity is known in advance
>         getConnection().setFixedLengthStreamingMode((int) 
> entity.getSize());
>     }
>     else
>     {
>         // The size of the entity is not known in advance
>         if (this.clientHelper.getChunkLength() >= 0)
>         {
>             // Use chunked encoding
>             getConnection().setChunkedStreamingMode(
>                 this.clientHelper.getChunkLength());
>         }
>         else
>         {
>             // Use entity buffering to determine the content length
>         }
>     }
> 
> This suggests that the data I am sending can have a size of 
> 0, but when it does it is never sent. And I can't "guess" a 
> size, because if I guess wrong then the 
> setFixedLengthStreamingMode will cause the HTTP Post to fail 
> when more bytes are written than expected.
> 
> I guess my question is: When we subclass Representation, do 
> we have to calculate the getSize() value or can we allow it 
> to be 0? In my case, I don't really want to serialize my Java 
> object until absolutely necessary, and I also don't want to 
> hold the serialized form of the object in memory prior to POSTing it.
> 
> Am I missing something? Maybe it's not supposed to work this way.
> 
> Mitch 
> 
> 

<<winmail.dat>>

Reply via email to