Hi Tom,

Thanks for sharing this workaround, this looks good. You could simplify this
code block:

  if(!((status.getCode() >= 200)&&(status.getCode() <= 299))){ 

by this one:

  if(!status.isSuccess()){

Best regards,
Jerome  

> -----Message d'origine-----
> De : Tom McGee [mailto:[EMAIL PROTECTED] 
> Envoyé : samedi 8 septembre 2007 01:51
> À : [email protected]
> Objet : Flex rest weakness work-around
> 
> I've been looking a Flex as a front end for a rest service. But Flex
> has a weakness. It does not grantee that it will return the http
> status when a call in returned. All the flex client knows is that the
> call susedde4d or failed. And the header data is not returned to the
> Flex client. (see:http://www.fngtps.com/2007/06/flex-can-t-do-rest).
> To get around this I am thinking that in the restlets code I could
> catch any non 200 results and send a modified 200 result that the Flex
> code would be looking for. Here's my first cut at some code:
> 
> public class FlexOverrideStatusService extends StatusService {
> 
>       public FlexOverrideStatusService() {
>               super(true);
>       }
> 
>       public Representation getRepresentation(Status status, 
> Request request,
>                       Response response) {
>               Representation result = null;
>               if(!((status.getCode() >= 
> 200)&&(status.getCode() <= 299))){
>                       Form query = 
> request.getResourceRef().getQueryAsForm(null);
>                       String testFlex = 
> query.getFirstValue("flexErrorStatusOverride");
>                       if ((testFlex != 
> null)&&(testFlex.equalsIgnoreCase("true"))) {
>                               response.setStatus(Status.SUCCESS_OK);
>                               result = new
> StringRepresentation("statusError="+String.valueOf(status.getC
> ode()+"\n\n"+status.getDescription()));
>                       }
>                       
> request.getAttributes().put("preStatus", status);
>               }
>               if(result == null){
>                       result = 
> super.getRepresentation(status, request, response);
>               }
>               return result;
>       }
> 
> }
> 
> Any options?

Reply via email to