use of org.mycore.common.config.MCRConfigurationException in project mycore by MyCoRe-Org.
the class MCRReadPublicTokenFactory method requestToken.
/**
* Requests the token from the OAuth2 API of ORCID.org.
* Logs a warning, so you better check your logs and directly configure
* MCR.ORCID.OAuth.ReadPublicToken
*/
private static void requestToken() {
LOGGER.info("requesting read-public access token...");
MCRTokenRequest request = MCROAuthClient.instance().getTokenRequest();
request.set("grant_type", "client_credentials");
request.set("scope", "/read-public");
try {
MCRTokenResponse response = request.post();
token = response.getAccessToken();
} catch (IOException ex) {
String msg = "Could not get read-public access token from ORCID OAuth API";
throw new MCRConfigurationException(msg, ex);
}
LOGGER.warn("You should set the access token in mycore.properties:");
LOGGER.warn(CONFIG_PROPERTY + "={}", token);
}
use of org.mycore.common.config.MCRConfigurationException in project mycore by MyCoRe-Org.
the class MCRXSL2XMLTransformer method getTransformedContent.
@Override
protected MCRContent getTransformedContent(MCRContent source, XMLReader reader, TransformerHandler transformerHandler) throws IOException, SAXException {
JDOMResult result = new JDOMResult();
transformerHandler.setResult(result);
// Parse the source XML, and send the parse events to the
// TransformerHandler.
reader.parse(source.getInputSource());
Document resultDoc = getDocument(result);
if (resultDoc == null) {
throw new MCRConfigurationException("Stylesheets " + Arrays.asList(templateSources) + " does not return any content for " + source.getSystemId());
}
return new MCRJDOMContent(resultDoc);
}
use of org.mycore.common.config.MCRConfigurationException in project mycore by MyCoRe-Org.
the class MCRXSLTransformer method setTransformerFactory.
public synchronized void setTransformerFactory(String factoryClass) throws TransformerFactoryConfigurationError {
TransformerFactory transformerFactory = Optional.ofNullable(factoryClass).map(c -> TransformerFactory.newInstance(c, null)).orElseGet(TransformerFactory::newInstance);
LOGGER.info("Transformerfactory: {}", transformerFactory.getClass().getName());
transformerFactory.setURIResolver(URI_RESOLVER);
transformerFactory.setErrorListener(MCRErrorListener.getInstance());
if (transformerFactory.getFeature(SAXSource.FEATURE) && transformerFactory.getFeature(SAXResult.FEATURE)) {
this.tFactory = (SAXTransformerFactory) transformerFactory;
} else {
throw new MCRConfigurationException("Transformer Factory " + transformerFactory.getClass().getName() + " does not implement SAXTransformerFactory");
}
}
use of org.mycore.common.config.MCRConfigurationException in project mycore by MyCoRe-Org.
the class MCRShutdownHandler method shutDown.
void shutDown() {
Logger logger = LogManager.getLogger(MCRShutdownHandler.class);
String cfgSystemName = "MyCoRe:";
try {
cfgSystemName = MCRConfiguration.instance().getString(PROPERTY_SYSTEM_NAME) + ":";
} catch (MCRConfigurationException e) {
// may occur early if there is an error starting mycore up or in JUnit tests
logger.warn("Error getting '" + PROPERTY_SYSTEM_NAME + "': {}", e.getMessage());
}
final String system = cfgSystemName;
System.out.println(system + " Shutting down system, please wait...\n");
logger.debug(() -> "requests: " + requests);
Closeable[] closeables = requests.stream().toArray(Closeable[]::new);
Stream.of(closeables).peek(c -> logger.debug("Prepare Closing (1): {}", c)).forEach(Closeable::prepareClose);
shutdownLock.writeLock().lock();
try {
shuttingDown = true;
// during shut down more request may come in MCR-1726
requests.stream().filter(c -> !Arrays.asList(closeables).contains(c)).peek(c -> logger.debug("Prepare Closing (2): {}", c)).forEach(Closeable::prepareClose);
requests.stream().peek(c -> logger.debug("Closing: {}", c)).forEach(Closeable::close);
System.out.println(system + " closing any remaining MCRSession instances, please wait...\n");
MCRSessionMgr.close();
System.out.println(system + " Goodbye, and remember: \"Alles wird gut.\"\n");
LogManager.shutdown();
SINGLETON = null;
} finally {
shutdownLock.writeLock().unlock();
}
// may be needed in webapp to release file handles correctly.
if (leakPreventor != null) {
ClassLoaderLeakPreventor myLeakPreventor = leakPreventor;
leakPreventor = null;
myLeakPreventor.contextDestroyed(null);
}
}
use of org.mycore.common.config.MCRConfigurationException in project mycore by MyCoRe-Org.
the class MCRMetsIIIFPresentationImpl method getTransformer.
protected MCRContentTransformer getTransformer() {
String transformerID = getProperties().get(TRANSFORMER_ID_CONFIGURATION_KEY);
MCRContentTransformer transformer = MCRContentTransformerFactory.getTransformer(transformerID);
if (transformer == null) {
throw new MCRConfigurationException("Could not resolve transformer with id : " + transformerID);
}
return transformer;
}
Aggregations