Restlet-GWT: Status + LocationRef

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Restlet-GWT: Status + LocationRef

Damian Harden
Hi everyone,

I'm using Restlet on the server side and Restlet-GWT on the client
side.  I'm having difficulties getting a Status and LocationRef to
filter through from the server to the client.

On the server side, I am doing the following:

@Override
public void storeRepresentation(Representation entity) throws
ResourceException {
    addSomething();
    getResponse().setLocationRef(getRequest().getResourceRef().getBaseRef()
+ "/" + newObject.getId());
    getResponse().setStatus(Status.SUCCESS_CREATED);
}

On the client side, I am doing the following:

@Override
public void onEvent(Request request, Response response) {
    Window.alert("Status code: " + response.getStatus().getCode() +
"\nLocation: " + response.getLocationRef());
}

Restlet-GWT is always receiving a Status of 200 (instead of 201) and a
LocationRef of null (instead of the location of the newly created
object).

Has anyone else experienced this issue?  I am using GWT Hosted Mode at
the moment (with the GWTShellServlet and GwtShellServletWrapper) -
could this be the issue?

Any help greatly appreciated :-)

Thanks,

Damian
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Restlet-GWT: Status + LocationRef

Rob Heittman
Hi Damian,

This is due to an issue in the embedded Tomcat server used in GWT Hosted Mode.  When sending a redirect, you must (ignoring the Restlet warning to the contrary) supply some sort of entity.  Otherwise, the hosted mode Tomcat server will replace it with a generic 200 response.  It's not clear yet whether the actual problem is in the original Tomcat bits or in the Google changes thereto.  We may have to put a workaround into Restlet meanwhile, because it's quite annoying.

For now, just attach something like a new StringRepresentation of "I am working around the hosted mode entity bug" to your redirects, and it should resolve the problem.  Personally, I have a system property I set that triggers the workaround -- the property is set in my hosted mode launcher, but not on the production server.

- Rob

On Sun, Nov 16, 2008 at 6:40 AM, Damian Harden <[hidden email]> wrote:
Has anyone else experienced this issue?  I am using GWT Hosted Mode at
the moment (with the GWTShellServlet and GwtShellServletWrapper) -
could this be the issue?

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Restlet-GWT: Status + LocationRef

Thierry Boileau
Hi Damian,

if you want to keep your resources intact, just add a filter as the root
Restlet of yourRestlet  application which tests the Response status in
the "afterHandle" method.

best regards,
Thierry


> Hi Damian,
>
> This is due to an issue in the embedded Tomcat server used in GWT
> Hosted Mode.  When sending a redirect, you must (ignoring the Restlet
> warning to the contrary) supply some sort of entity.  Otherwise, the
> hosted mode Tomcat server will replace it with a generic 200 response.
>  It's not clear yet whether the actual problem is in the original
> Tomcat bits or in the Google changes thereto.  We may have to put a
> workaround into Restlet meanwhile, because it's quite annoying.
>
> For now, just attach something like a new StringRepresentation of "I
> am working around the hosted mode entity bug" to your redirects, and
> it should resolve the problem.  Personally, I have a system property I
> set that triggers the workaround -- the property is set in my hosted
> mode launcher, but not on the production server.
>
> - Rob
>
> On Sun, Nov 16, 2008 at 6:40 AM, Damian Harden <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Has anyone else experienced this issue?  I am using GWT Hosted Mode at
>     the moment (with the GWTShellServlet and GwtShellServletWrapper) -
>     could this be the issue?
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Restlet-GWT: Status + LocationRef

Damian Harden
In reply to this post by Rob Heittman
Hi Rob,

That worked a treat.  Thanks!  :-)

Code which looks like the following ensures a Status and LocationRef
are picked up in Restlet-GWT:

@Override
public void storeRepresentation(Representation entity) throws
ResourceException {
    addSomething();
    getResponse().setEntity(new StringRepresentation("Not to be done
in production."));
    getResponse().setLocationRef(getRequest().getResourceRef().getBaseRef()
+ "/" + newObject.getId());
    getResponse().setStatus(Status.SUCCESS_CREATED);
}

Thanks again,

Damian

2008/11/16 Rob Heittman <[hidden email]>:

> Hi Damian,
> This is due to an issue in the embedded Tomcat server used in GWT Hosted
> Mode.  When sending a redirect, you must (ignoring the Restlet warning to
> the contrary) supply some sort of entity.  Otherwise, the hosted mode Tomcat
> server will replace it with a generic 200 response.  It's not clear yet
> whether the actual problem is in the original Tomcat bits or in the Google
> changes thereto.  We may have to put a workaround into Restlet meanwhile,
> because it's quite annoying.
> For now, just attach something like a new StringRepresentation of "I am
> working around the hosted mode entity bug" to your redirects, and it should
> resolve the problem.  Personally, I have a system property I set that
> triggers the workaround -- the property is set in my hosted mode launcher,
> but not on the production server.
>
> - Rob
> On Sun, Nov 16, 2008 at 6:40 AM, Damian Harden <[hidden email]> wrote:
>>
>> Has anyone else experienced this issue?  I am using GWT Hosted Mode at
>> the moment (with the GWTShellServlet and GwtShellServletWrapper) -
>> could this be the issue?
>
>
Loading...