For anyone else who comes across this later, the solution was as Thierry 
suggested, however, we needed to use a custom BoundedInputStream which would 
throw a ResourceException when the max length was exceeded.

Filter filter = new Filter(getContext(), router) {
  @Override
  protected int beforeHandle(Request request, Response response) {
    Series<Header> params = (Series<Header>) 
request.getAttributes().get("org.restlet.http.headers");
    long length = HeaderUtils.getContentLength(params);
    if (length != Representation.UNKNOWN_SIZE && length > MAX_CONTENTS_LENGTH) {
      // TODO: report your error here
      return STOP;
    }

    if (request.isEntityAvailable()) {
      request.setEntity(new WrapperRepresentation(request.getEntity()) {
        @Override
        public InputStream getStream() throws IOException {
          InputStream result = super.getStream();
          if (result != null) {
            result = new BoundedInputStream(result, MAX_CONTENTS_LENGTH); // 
TODO: this is our implementation which throws ResourceException when limit is 
exceeded
          }
          return result;
        }

        @Override
        public String getText() throws IOException {
          return BioUtils.toString(getStream(), getCharacterSet());
        }
      });
    }

    return super.beforeHandle(request, response);
  }
};

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

Reply via email to