Search in sources :

Example 11 with MCRConfigurationException

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);
}
Also used : MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) IOException(java.io.IOException)

Example 12 with MCRConfigurationException

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);
}
Also used : JDOMResult(org.jdom2.transform.JDOMResult) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) Document(org.jdom2.Document)

Example 13 with MCRConfigurationException

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");
    }
}
Also used : Arrays(java.util.Arrays) Templates(javax.xml.transform.Templates) TransformerException(javax.xml.transform.TransformerException) StreamResult(javax.xml.transform.stream.StreamResult) MCRTemplatesSource(org.mycore.common.xsl.MCRTemplatesSource) Result(javax.xml.transform.Result) MCRConfiguration(org.mycore.common.config.MCRConfiguration) MCRTraceListener(org.mycore.common.xsl.MCRTraceListener) SAXResult(javax.xml.transform.sax.SAXResult) MCRException(org.mycore.common.MCRException) ByteBuffer(java.nio.ByteBuffer) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) SAXTransformerFactory(javax.xml.transform.sax.SAXTransformerFactory) TraceManager(org.apache.xalan.trace.TraceManager) XMLReader(org.xml.sax.XMLReader) MCRParameterCollector(org.mycore.common.xsl.MCRParameterCollector) MCRCache(org.mycore.common.MCRCache) TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) LinkedList(java.util.LinkedList) OutputStream(java.io.OutputStream) Properties(java.util.Properties) TooManyListenersException(java.util.TooManyListenersException) MCRContent(org.mycore.common.content.MCRContent) MCRByteArrayOutputStream(org.mycore.common.content.streams.MCRByteArrayOutputStream) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) OutputKeys(javax.xml.transform.OutputKeys) MCRWrappedContent(org.mycore.common.content.MCRWrappedContent) MCRURIResolver(org.mycore.common.xml.MCRURIResolver) Base64(java.util.Base64) SAXSource(javax.xml.transform.sax.SAXSource) Logger(org.apache.logging.log4j.Logger) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) Optional(java.util.Optional) MCREntityResolver(org.mycore.common.xml.MCREntityResolver) MCRErrorListener(org.mycore.common.xsl.MCRErrorListener) TransformerFactory(javax.xml.transform.TransformerFactory) TransformerHandler(javax.xml.transform.sax.TransformerHandler) LogManager(org.apache.logging.log4j.LogManager) MCRXMLParserFactory(org.mycore.common.xml.MCRXMLParserFactory) FilenameUtils(org.apache.commons.io.FilenameUtils) MCRByteContent(org.mycore.common.content.MCRByteContent) TransformerImpl(org.apache.xalan.transformer.TransformerImpl) SAXTransformerFactory(javax.xml.transform.sax.SAXTransformerFactory) TransformerFactory(javax.xml.transform.TransformerFactory) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException)

Example 14 with MCRConfigurationException

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);
    }
}
Also used : Arrays(java.util.Arrays) ClassLoaderLeakPreventor(se.jiderhamn.classloader.leak.prevention.ClassLoaderLeakPreventor) MCRConfiguration(org.mycore.common.config.MCRConfiguration) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) MCRException(org.mycore.common.MCRException) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) MCRSessionMgr(org.mycore.common.MCRSessionMgr) LogManager(org.apache.logging.log4j.LogManager) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) Logger(org.apache.logging.log4j.Logger) ClassLoaderLeakPreventor(se.jiderhamn.classloader.leak.prevention.ClassLoaderLeakPreventor)

Example 15 with MCRConfigurationException

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;
}
Also used : MCRContentTransformer(org.mycore.common.content.transformer.MCRContentTransformer) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException)

Aggregations

MCRConfigurationException (org.mycore.common.config.MCRConfigurationException)30 MCRException (org.mycore.common.MCRException)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 IOException (java.io.IOException)5 MCRConfiguration (org.mycore.common.config.MCRConfiguration)5 Properties (java.util.Properties)3 File (java.io.File)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 Path (java.nio.file.Path)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 Arrays (java.util.Arrays)2 StringTokenizer (java.util.StringTokenizer)2 SAXParser (javax.xml.parsers.SAXParser)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 OutputStream (java.io.OutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ByteBuffer (java.nio.ByteBuffer)1 NotDirectoryException (java.nio.file.NotDirectoryException)1