@Test public void testExtractMetadata() throws IOException { FileMetadataExtractor extractor = new FileMetadataExtractorImpl(); Map<String, Object> metadata = extractor.extractMetadata(file); assertNotNull(metadata); assertTrue(metadata.size() > 0); log.info("Extracted metadata: {}", metadata); }
@Override public Map<String, Object> extractMetadata(File file) throws IOException { try { return extractMetadata(file.getResource()); } catch (NoClassDefFoundError ncdfe) { log.info("Caught exception: {}, Attempting to reload metadata extractor bundle", String.valueOf(ncdfe)); Bundle metadataExtractorBundle = Arrays.stream(bcx.getBundles()) .filter(b -> METADATA_EXTRACTOR_BUNDLE_NAME.equals(b.getSymbolicName())).findFirst().orElse(null); if (metadataExtractorBundle != null) { try { log.debug("Reloading metadata bundle: {}", metadataExtractorBundle); Bundle systemBundle = bcx.getBundle(0); metadataExtractorBundle.stop(); metadataExtractorBundle.start(); FrameworkWiring frameworkWiring = systemBundle.adapt(FrameworkWiring.class); frameworkWiring.refreshBundles(Collections.singleton(metadataExtractorBundle)); log.debug("Bundle reloaded successfully!"); } catch (Exception e) { log.warn("Failed to refresh metadata exporter packages", e); } } try { return extractMetadata(file.getResource()); } catch (SAXException | TikaException | NoClassDefFoundError e) { throw new IOException("Failed to parse metadata after reloading metadata extractor bundle", e); } } catch (SAXException | TikaException e) { throw new IOException("Failed to parse metadata", e); } }
FileMetadataExtractorImpl implements FileMetadataExtractor { @Override public Map<String, Object> extractMetadata(File file) throws IOException { try { return extractMetadata(file.getResource()); } catch (NoClassDefFoundError ncdfe) { log.info("Caught exception: {}, Attempting to reload metadata extractor bundle", String.valueOf(ncdfe)); Bundle metadataExtractorBundle = Arrays.stream(bcx.getBundles()) .filter(b -> METADATA_EXTRACTOR_BUNDLE_NAME.equals(b.getSymbolicName())).findFirst().orElse(null); if (metadataExtractorBundle != null) { try { log.debug("Reloading metadata bundle: {}", metadataExtractorBundle); Bundle systemBundle = bcx.getBundle(0); metadataExtractorBundle.stop(); metadataExtractorBundle.start(); FrameworkWiring frameworkWiring = systemBundle.adapt(FrameworkWiring.class); frameworkWiring.refreshBundles(Collections.singleton(metadataExtractorBundle)); log.debug("Bundle reloaded successfully!"); } catch (Exception e) { log.warn("Failed to refresh metadata exporter packages", e); } } try { return extractMetadata(file.getResource()); } catch (SAXException | TikaException | NoClassDefFoundError e) { throw new IOException("Failed to parse metadata after reloading metadata extractor bundle", e); } } catch (SAXException | TikaException e) { throw new IOException("Failed to parse metadata", e); } } }
FileMetadataExtractorImpl implements FileMetadataExtractor { @Override public Map<String, Object> extractMetadata(File file) throws IOException { try { return extractMetadata(file.getResource()); } catch (NoClassDefFoundError ncdfe) { log.info("Caught exception: {}, Attempting to reload metadata extractor bundle", String.valueOf(ncdfe)); Bundle metadataExtractorBundle = Arrays.stream(bcx.getBundles()) .filter(b -> METADATA_EXTRACTOR_BUNDLE_NAME.equals(b.getSymbolicName())).findFirst().orElse(null); if (metadataExtractorBundle != null) { try { log.debug("Reloading metadata bundle: {}", metadataExtractorBundle); Bundle systemBundle = bcx.getBundle(0); metadataExtractorBundle.stop(); metadataExtractorBundle.start(); FrameworkWiring frameworkWiring = systemBundle.adapt(FrameworkWiring.class); frameworkWiring.refreshBundles(Collections.singleton(metadataExtractorBundle)); log.debug("Bundle reloaded successfully!"); } catch (Exception e) { log.warn("Failed to refresh metadata exporter packages", e); } } try { return extractMetadata(file.getResource()); } catch (SAXException | TikaException | NoClassDefFoundError e) { throw new IOException("Failed to parse metadata after reloading metadata extractor bundle", e); } } catch (SAXException | TikaException e) { throw new IOException("Failed to parse metadata", e); } }  }
FileMetadataExtractorImpl implements FileMetadataExtractor { @Override public Map<String, Object> extractMetadata(File file) throws IOException { try { return extractMetadata(file.getResource()); } catch (NoClassDefFoundError ncdfe) { log.info("Caught exception: {}, Attempting to reload metadata extractor bundle", String.valueOf(ncdfe)); Bundle metadataExtractorBundle = Arrays.stream(bcx.getBundles()) .filter(b -> METADATA_EXTRACTOR_BUNDLE_NAME.equals(b.getSymbolicName())).findFirst().orElse(null); if (metadataExtractorBundle != null) { try { log.debug("Reloading metadata bundle: {}", metadataExtractorBundle); Bundle systemBundle = bcx.getBundle(0); metadataExtractorBundle.stop(); metadataExtractorBundle.start(); FrameworkWiring frameworkWiring = systemBundle.adapt(FrameworkWiring.class); frameworkWiring.refreshBundles(Collections.singleton(metadataExtractorBundle)); log.debug("Bundle reloaded successfully!"); } catch (Exception e) { log.warn("Failed to refresh metadata exporter packages", e); } } try { return extractMetadata(file.getResource()); } catch (SAXException | TikaException | NoClassDefFoundError e) { throw new IOException("Failed to parse metadata after reloading metadata extractor bundle", e); } } catch (SAXException | TikaException e) { throw new IOException("Failed to parse metadata", e); } }  @Activate void activate(ComponentContext context); @Override Map<String, Object> extractMetadata(File file); @Override void updateMetadata(File file); @Override void updateMetadata(File file, boolean persist); Map<String, Object> extractMetadata(Resource resource); }
FileMetadataExtractorImpl implements FileMetadataExtractor { @Override public Map<String, Object> extractMetadata(File file) throws IOException { try { return extractMetadata(file.getResource()); } catch (NoClassDefFoundError ncdfe) { log.info("Caught exception: {}, Attempting to reload metadata extractor bundle", String.valueOf(ncdfe)); Bundle metadataExtractorBundle = Arrays.stream(bcx.getBundles()) .filter(b -> METADATA_EXTRACTOR_BUNDLE_NAME.equals(b.getSymbolicName())).findFirst().orElse(null); if (metadataExtractorBundle != null) { try { log.debug("Reloading metadata bundle: {}", metadataExtractorBundle); Bundle systemBundle = bcx.getBundle(0); metadataExtractorBundle.stop(); metadataExtractorBundle.start(); FrameworkWiring frameworkWiring = systemBundle.adapt(FrameworkWiring.class); frameworkWiring.refreshBundles(Collections.singleton(metadataExtractorBundle)); log.debug("Bundle reloaded successfully!"); } catch (Exception e) { log.warn("Failed to refresh metadata exporter packages", e); } } try { return extractMetadata(file.getResource()); } catch (SAXException | TikaException | NoClassDefFoundError e) { throw new IOException("Failed to parse metadata after reloading metadata extractor bundle", e); } } catch (SAXException | TikaException e) { throw new IOException("Failed to parse metadata", e); } }  @Activate void activate(ComponentContext context); @Override Map<String, Object> extractMetadata(File file); @Override void updateMetadata(File file); @Override void updateMetadata(File file, boolean persist); Map<String, Object> extractMetadata(Resource resource);  }