log.debug("Watching resource: " + watchedResource.getLocation() + ", polling frequency: {}ms, max retry attempts: {}", pollFrequency, maxRetryAttempts); if (watchedResource.exists()) { resourceExist = true; lastModification = watchedResource.getLastModifiedTime(); } else { resourceExist = false; log.warn("Resource " + watchedResource.getLocation() + " could not be accessed", e); currentRetryAttempts++; if (currentRetryAttempts >= maxRetryAttempts) { log.error("Resource {} was not accessible at time of ResourceChangeWatcher construction and max retrys are exceeded", watchedResource.getLocation()); throw e;
/** * Constructor. * * @param resource resource from which to read the metadata file. * @param timer task timer used to schedule metadata refresh tasks * * @throws MetadataProviderException thrown if there is a problem retrieving information about the resource */ public ResourceBackedMetadataProvider(Timer timer, Resource resource) throws MetadataProviderException { super(timer); try { if (!resource.exists()) { throw new MetadataProviderException("Resource " + resource.getLocation() + " does not exist."); } metadataResource = resource; } catch (ResourceException e) { throw new MetadataProviderException("Unable to read resource", e); } }
for (int i = 0; i < numOfResources; i++) { configurationResource = configurationResources.get(i); if (configurationResource != null && configurationResource.exists()) { configSources[i] = new InputStreamResource(configurationResources.get(i).getInputStream(), configurationResource.getLocation()); } else { log.warn("Configuration resource not loaded because it does not exist: {}", configurationResource .getLocation());
/** {@inheritDoc} */ protected byte[] fetchMetadata() throws MetadataProviderException { try { DateTime metadataUpdateTime = metadataResource.getLastModifiedTime(); log.debug("resource {} was last modified {}", metadataResource.getLocation(), metadataUpdateTime); if (getLastRefresh() == null || metadataUpdateTime.isAfter(getLastRefresh())) { return inputstreamToByteArray(metadataResource.getInputStream()); } return null; } catch (ResourceException e) { String errorMsg = "Unable to read metadata file"; log.error(errorMsg, e); throw new MetadataProviderException(errorMsg, e); } } }
/** {@inheritDoc} */ public void afterPropertiesSet() throws Exception { DefaultBootstrap.bootstrap(); if(configResources != null && !configResources.isEmpty()){ XMLConfigurator configurator = new XMLConfigurator(); for(Resource config : configResources){ try{ log.debug("Loading OpenSAML configuration file: {}", config.getLocation()); configurator.load(config.getInputStream()); }catch(Exception e){ log.error("Unable to load OpenSAML configuration file: " + config.getLocation()); } } } if (getParserPool() != null) { Configuration.setParserPool(getParserPool()); } } }
/** {@inheritDoc} */ protected String getMetadataIdentifier() { return metadataResource.getLocation(); }
/** * Constructor. * * @param resource resource from which to read the metadata file. * @param timer task timer used to schedule metadata refresh tasks * @param maxMetadataCacheDuration maximum amount of time, in milliseconds, that metadata may be cached before being * re-read * * @throws MetadataProviderException thrown if there is a problem retrieving information about the resource * * @deprecated */ public ResourceBackedMetadataProvider(Resource resource, Timer timer, long maxMetadataCacheDuration) throws MetadataProviderException { super(timer); try { if (!resource.exists()) { throw new MetadataProviderException("Resource " + resource.getLocation() + " does not exist."); } metadataResource = resource; } catch (ResourceException e) { throw new MetadataProviderException("Unable to read resource", e); } }
/** * Configures logback using the given resource as the Joran configuration file. * * @param configuration logback configuration file */ protected void configureLogback(Resource configuration) { LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); StatusManager statusManager = loggerContext.getStatusManager(); statusManager.add(new InfoStatus("Loading logging configuration file: " + configuration.getLocation(), this)); try { //loggerContext.stop(); loggerContext.reset(); JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(loggerContext); configurator.doConfigure(configuration.getInputStream()); loggerContext.start(); } catch (JoranException e) { statusManager.add(new ErrorStatus("Error loading logging configuration file: " + configuration.getLocation(), this, e)); } catch (ResourceException e) { statusManager.add(new ErrorStatus("Error loading logging configuration file: " + configuration.getLocation(), this, e)); } StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext); } }
switch (changeType) { case CREATION: log.debug("Publishing creation event for resource: {}", watchedResource.getLocation()); for (ResourceChangeListener listener : resourceListeners) { listener.onResourceCreate(watchedResource); log.debug("Publishing update event for resource: {}", watchedResource.getLocation()); for (ResourceChangeListener listener : resourceListeners) { listener.onResourceUpdate(watchedResource); log.debug("Publishing delete event for resource: {}", watchedResource.getLocation()); for (ResourceChangeListener listener : resourceListeners) { listener.onResourceDelete(watchedResource);
log.trace("Checking resource for changes: {}", watchedResource.getLocation()); if (watchedResource.exists()) { if (!resourceExist) { resourceExist = true; signalListeners(ResourceChange.CREATION); lastModification = watchedResource.getLastModifiedTime(); } else { if (lastModification.isBefore(watchedResource.getLastModifiedTime())) { signalListeners(ResourceChange.UPDATE); lastModification = watchedResource.getLastModifiedTime(); log.warn("Resource " + watchedResource.getLocation() + " could not be accessed", e); currentRetryAttempts++; if (currentRetryAttempts >= maxRetryAttempts) { cancel(); log.error("Resource {} was not accessible for max number of retry attempts. This resource will no longer be watched", watchedResource.getLocation());