FileSourceAppComponent
Required to implement a file-source component. File source reads a file from a remote source such as a remote file system (FTP) or a URL
Source: Github
Example:
package my.org.components;
import io.dexi.service.AppContext;
import io.dexi.service.components.AppComponent;
import io.dexi.service.components.FileSourceAppComponent;
import io.dexi.service.exceptions.UserErrorException;
import org.apache.commons.io.IOUtils;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@AppComponent("read-file-from-my-app")
public class MyAppFileSourceAppComponent implements FileSourceAppComponent<MyAppConfig, MyComponentConfig> {
@Override
public void read(AppContext<MyAppConfig, MyComponentConfig> ctxt, HttpServletResponse response) {
File file = new File("some-file.txt");
try (InputStream in = new FileInputStream(file)) {
IOUtils.copyLarge(in, response.getOutputStream());
} catch (IOException e) {
throw new UserErrorException("Failed to read file" ,e );
}
}
@Override
public Class<MyComponentConfig> getComponentConfigClass() {
return MyComponentConfig.class;
}
}
components:
- name: read-file-from-my-app
type: file-source
title: Read a file from my app
specification:
endpoint: # Will invoke MyAppFileSourceAppComponent::read
url: "${baseUrl}/dexi/file/source/read"
method: POST
Updated about 5 years ago