@Override protected void configure() { bindSettings(FileSystemConf.class); }
@Provides @Singleton @Named("home") protected Path getHomeFolder(OxalisHomeDirectory oxalisHomeDirectory) { Path path = oxalisHomeDirectory.detect().toPath(); LOGGER.info("Home folder: {}", path); return path; }
findJarFiles(path), Thread.currentThread().getContextClassLoader() ); new URL[]{FileUtils.toUrl(path)}, Thread.currentThread().getContextClassLoader() );
@Override public Path persist(TransmissionIdentifier transmissionIdentifier, Header header, InputStream inputStream) throws IOException { // Create temp file Path path = PersisterUtils.createArtifactFolders(folder, header) .resolve(String.format("%s.xml", filterString(transmissionIdentifier.getIdentifier()))); // Copy content to temp file try (OutputStream outputStream = Files.newOutputStream(path)) { ByteStreams.copy(inputStream, outputStream); } // Return file name return path; }
@Provides @Singleton @Named("plugin") public ClassLoader providesClassLoader(@Named("home") Path homeDirectory, Settings<FileSystemConf> settings) { final Path pluginPath = settings.getPath(FileSystemConf.PLUGIN, homeDirectory); log.info("Loading plugins from '{}'.", pluginPath); return ClassLoaderUtils.initiate(pluginPath); } }
public File detect() { File directory = homeDetectors.stream() .sequential() .map(HomeDetector::detect) .filter(Objects::nonNull) .findFirst() .orElseThrow(() -> new OxalisLoadingException( "Unable to detect Oxalis home folder.")); try { validateOxalisHomeDirectory(directory); } catch (OxalisLoadingException ex) { log.error(ex.getMessage()); throw ex; } return directory; }
@Override public Path persist(TransmissionIdentifier transmissionIdentifier, Header header, InputStream inputStream) throws IOException { // Create temp file Path path = PersisterUtils.createArtifactFolders(folder, header) .resolve(String.format("%s.xml", filterString(transmissionIdentifier.getIdentifier()))); // Copy content to temp file try (OutputStream outputStream = Files.newOutputStream(path)) { ByteStreams.copy(inputStream, outputStream); } // Return file name return path; }
@Provides @Singleton @Named("plugin") public ClassLoader providesClassLoader(@Named("home") Path homeDirectory, Settings<FileSystemConf> settings) { final Path pluginPath = settings.getPath(FileSystemConf.PLUGIN, homeDirectory); log.info("Loading plugins from '{}'.", pluginPath); return ClassLoaderUtils.initiate(pluginPath); } }
findJarFiles(path), Thread.currentThread().getContextClassLoader() ); new URL[]{FileUtils.toUrl(path)}, Thread.currentThread().getContextClassLoader() );
@Override protected void configure() { bindSettings(FileSystemConf.class); }
@Provides @Singleton @Named("home") protected Path getHomeFolder(OxalisHomeDirectory oxalisHomeDirectory) { Path path = oxalisHomeDirectory.detect().toPath(); LOGGER.info("Home folder: {}", path); return path; }
public File detect() { File directory = homeDetectors.stream() .sequential() .map(HomeDetector::detect) .filter(Objects::nonNull) .findFirst() .orElseThrow(() -> new OxalisLoadingException( "Unable to detect Oxalis home folder.")); try { validateOxalisHomeDirectory(directory); } catch (OxalisLoadingException ex) { log.error(ex.getMessage()); throw ex; } return directory; }
@Override public Path persist(TransmissionIdentifier transmissionIdentifier, Header header, InputStream inputStream) throws IOException { Path path = PersisterUtils.createArtifactFolders(inboundFolder, header).resolve( String.format("%s.doc.xml", FileUtils.filterString(transmissionIdentifier.getIdentifier()))); try (OutputStream outputStream = Files.newOutputStream(path)) { ByteStreams.copy(inputStream, outputStream); } log.debug("Payload persisted to: {}", path); return path; }
@Test public void testBasicDataSource() throws Exception { Path jdbcDriverClassPath = settings.getPath(PersistenceConf.DRIVER_PATH, homeFolder); ClassLoader classLoader = ClassLoaderUtils.initiate(jdbcDriverClassPath); BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName(settings.getString(PersistenceConf.DRIVER_CLASS)); basicDataSource.setUrl(settings.getString(PersistenceConf.JDBC_CONNECTION_URI)); basicDataSource.setUsername(settings.getString(PersistenceConf.JDBC_USERNAME)); basicDataSource.setPassword(settings.getString(PersistenceConf.JDBC_PASSWORD)); // Does not work in 1.4, fixed in 1.4.1 basicDataSource.setDriverClassLoader(classLoader); try { Connection connection = basicDataSource.getConnection(); assertNotNull(connection); } catch (SQLException e) { // As expected when using DBCP 1.4 } }
@Override public Path persist(TransmissionIdentifier transmissionIdentifier, Header header, InputStream inputStream) throws IOException { Path path = PersisterUtils.createArtifactFolders(inboundFolder, header).resolve( String.format("%s.doc.xml", FileUtils.filterString(transmissionIdentifier.getIdentifier()))); try (OutputStream outputStream = Files.newOutputStream(path)) { ByteStreams.copy(inputStream, outputStream); } log.debug("Payload persisted to: {}", path); return path; }
/** * Computes the Path for a directory into which your file artifacts associated with * the supplied header may be written. Any intermediate directories are created for you. * * @param baseFolder the root folder to use as the basis for appending additional folders. * @param header meta data to be used as input for computation. * @return a path to a directory into which you may store your artifacts. * @throws IOException */ public static Path createArtifactFolders(Path baseFolder, Header header) throws IOException { Path folder = baseFolder.resolve(Paths.get( FileUtils.filterString(header.getReceiver().getIdentifier()), FileUtils.filterString(header.getSender().getIdentifier()))); Files.createDirectories(folder); return folder; } }
/** * Computes the Path for a directory into which your file artifacts associated with * the supplied header may be written. Any intermediate directories are created for you. * * @param baseFolder the root folder to use as the basis for appending additional folders. * @param header meta data to be used as input for computation. * @return a path to a directory into which you may store your artifacts. * @throws IOException */ public static Path createArtifactFolders(Path baseFolder, Header header) throws IOException { Path folder = baseFolder.resolve(Paths.get( FileUtils.filterString(header.getReceiver().getIdentifier()), FileUtils.filterString(header.getSender().getIdentifier()))); Files.createDirectories(folder); return folder; } }
@Override public void persist(InboundMetadata inboundMetadata, Path payloadPath) throws IOException { Path path = PersisterUtils.createArtifactFolders(inboundFolder, inboundMetadata.getHeader()).resolve( String.format("%s.receipt.dat", FileUtils.filterString(inboundMetadata.getTransmissionIdentifier().getIdentifier()))); try (OutputStream outputStream = Files.newOutputStream(path)) { evidenceFactory.write(outputStream, inboundMetadata); } catch (EvidenceException e) { throw new IOException("Unable to persist receipt.", e); } log.debug("Receipt persisted to: {}", path); }
protected void saveEvidence(TransmissionResponse transmissionResponse, File evidencePath, Span root) throws IOException, EvidenceException { Span span = tracer.buildSpan("save evidence").asChildOf(root).start(); String transIdent = FileUtils.filterString(transmissionResponse.getTransmissionIdentifier().toString()); File evidenceFile = new File(evidencePath, transIdent + ".receipt.dat"); try (OutputStream outputStream = Files.newOutputStream(evidenceFile.toPath())) { evidenceFactory.write(outputStream, transmissionResponse); } finally { span.finish(); } } }
protected void saveEvidence(TransmissionResponse transmissionResponse, File evidencePath, Span root) throws IOException, EvidenceException { Span span = tracer.buildSpan("save evidence").asChildOf(root).start(); String transIdent = FileUtils.filterString(transmissionResponse.getTransmissionIdentifier().toString()); File evidenceFile = new File(evidencePath, transIdent + ".receipt.dat"); try (OutputStream outputStream = Files.newOutputStream(evidenceFile.toPath())) { evidenceFactory.write(outputStream, transmissionResponse); } finally { span.finish(); } } }