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.getCode()+"\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