FileFilterAppComponent

Required to implement a file-filter component. File filters parses an input stream of a certain file and returns the result directly to the user as an output stream. This can be used to apply filters to images, GZip files or anything else that involves transforming a file stream .

Source: Github

Example:

package my.org.components;

import io.dexi.service.AppContext;
import io.dexi.service.components.AppComponent;
import io.dexi.service.components.FileFilterAppComponent;
import io.dexi.service.exceptions.UserErrorException;
import org.apache.commons.io.IOUtils;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

@AppComponent("filter-file-with-my-app")
public class MyAppFileFilterAppComponent implements FileFilterAppComponent<MyAppConfig, MyComponentConfig> {

    @Override
    public Class<MyComponentConfig> getComponentConfigClass() {
        return MyComponentConfig.class;
    }

    @Override
    public void filter(AppContext<MyAppConfig, MyComponentConfig> ctxt, HttpServletRequest request, HttpServletResponse response) {

        try (OutputStream out = response.getOutputStream()) {
            try (InputStream in = request.getInputStream()) {
                //Does nothing - just pass through
                IOUtils.copyLarge(in, out);
            }          
        } catch (IOException e) {
            throw new UserErrorException("Failed to pass through stream" ,e );
        }
    }
}
components:
- name: filter-file-with-my-app
  type: file-filter
  title: Apply filter to a file using my app
  specification:
    endpoint: # Will invoke MyAppFileFiltereAppComponent::filter
      url: "${baseUrl}/dexi/file/filter"
      method: POST