Reply To: Reload configuration (or add/remove filters) at runtime.

Splash Forums Rewrite Users Reload configuration (or add/remove filters) at runtime. Reply To: Reload configuration (or add/remove filters) at runtime.

#26695

You really shouldn’t try to reload the Rewrite configuration. And there is really no need to create one rule for each uploaded file. There are many ways to implement something like this. But this depends on your specific requirements. Where are the files images? Stored in the database?

This is one possible way to implement this. I didn’t test it but it shows how it could work. You create a rule that matches all inbound requests and then create a HttpOperation which checks if the requested URL is an uploaded image or not. If so, you load the image (from the db or whatever) and then write it to the response. At the end you tell Rewrite that it should end the request processing as you already sent the response.

.addRule()
.when(Direction.isInbound())
.perform(new HttpOperation() {
   public void performHttp(HttpServletRewrite event, EvaluationContext context)
   {
      
      String uri = event.getRequest().getRequestURI();
      
      if(isUploadedGraphic(uri)) {
         
         byte[] data = getGraphic(uri);
         
         Response.setContentType("image/jpg").perform(event, context);
         Response.write(data).perform(event, context);
         
         Lifecycle.handled().perform(event, context);
         
      }
      
   }
})

IMHO this is a much better approach compared to dynamically creating and removing rules at runtime.