Hi John,
 
Yes, this is the intention regarding the null stream. Your workaround looks 
good. You may want to leverage the WrapperRepresentation
to not have to copy all the metadata in the original representation.
 
Also, I've just added a Message#getEntityAsText() method that caches the text 
content, like the existing getEntityAsDom() method.
This is available in SVN trunk.
 
Best regards,
Jerome Louvel
--
Restlet ~ Founder and Lead developer ~  <http://www.restlet.org/> 
http://www.restlet.org
Noelios Technologies ~ Co-founder ~  <http://www.noelios.com> 
http://www.noelios.com
 

 
  _____  

De : John Prystash [mailto:[email protected]] 
Envoye : mercredi 11 fevrier 2009 22:59
A : [email protected]
Objet : Re: [restlet] request.getEntity().getText() sets the InputStream to null


I should of mentioned I had used the approach you mentioned as a "workaround".


    Representation entity = new StringRepresentation(text, ...)
    request.setEntity(entity)

So is the call to setStream(null) just to ensure the stream is considered empty?

Thanks


  _____  

From: Stephen Groucutt <[email protected]>
To: [email protected]
Sent: Wednesday, February 11, 2009 4:39:55 PM
Subject: Re: [restlet] request.getEntity().getText() sets the InputStream to 
null

Hi John,

I never tried this, so I'm not sure it works, but just to throw an idea out...

If you must look at the entity body in the Guard, could you try putting the 
entity into a new representation and using
request.setEntity() to put it back on the Request once you were done?  I'm 
assuming that this is text data, so maybe a
DOMRepresentation or a StringRepresentation would do?  (This probably would 
cause your Guard to have to know everything about type
negotiation that your resources would - so, maybe not a good idea.)


On Wed, Feb 11, 2009 at 4:33 PM, Stephan Koops <[email protected]> wrote:


Hi John,

if you want to create the entity as String, you have to read the String.
But if it is read, the data is read ... and no available in the Stream
anymore.

best regards
  Stephan

John Prystash schrieb:

> Hey Everyone, I encountered this behavior and was wondering if it is
> intentional.  I'm sure it is, but if so I was wondering about the
> reasoning behind it.
>
> In my Guard override, during authorize() I need to inspect the body of
> the request:
>
>     @Override
>   public boolean authorize(Request request) {
>      ...
>      String text= request.getEntity().getText();
>      ...
>   }
>
>
> When I get the Resource method, the body is null:
>
>     @Override
>   public void post(Representation entity) {
>       ...
>       String text = entity.getText(); // is null
>             ...
>   }
>
> From InputRepresentation:
>
>     @Override
>     public InputStream getStream() throws IOException {
>      final InputStream result = this.stream;
>      setStream(null);
>      return result;
>   }
>
>   @Override
>   public String getText() throws IOException {
>       return ByteUtils.toString(getStream(), getCharacterSet());
>   }
>
> I was wondering if the setStream(null) is intended behavior (or if I'm
> abusing the purpose of the Guard) and if so, some background for my
> education would be much appreciated.  Thanks!
>


------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447
<http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1140979>
 &dsMessageId=1140979

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1143650

Reply via email to