I have a Restlet ServerResource
, which should process a GET request with a parameter user
. If user
is equal to some value, it should return some image, otherwise send an error response (404 or 403) indicating that the sender is not allowed to get the image.
import org.restlet.data.MediaType;
import org.restlet.representation.ObjectRepresentation;
import org.restlet.representation.Representation;
import org.restlet.resource.Get;
import org.restlet.resource.ResourceException;
import org.restlet.resource.ServerResource;
public class GetMap extends ServerResource {
@Get
public Representation getImage() {
final String user = getQuery().getValues("user");
if (user.equals("me")) {
//Read map from file and return it
byte[] data = readImage();
final ObjectRepresentation<byte[]> or=new ObjectRepresentation<byte[]>(data, MediaType.IMAGE_PNG) {
@Override
public void write(OutputStream os) throws IOException {
super.write(os);
os.write(this.getObject());
}
};
return or;
}
return null; // Here I want to send an error response
}
[...]
}
How can I send a standardized error response in the getImage
method (instead of return null
) ?