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 <stephen.grouc...@gmail.com>
To: discuss@restlet.tigris.org
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 <stephan.ko...@web.de> 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&dsMessageId=1140979

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

Reply via email to