Search in sources :

Example 6 with MCRConfigurationException

use of org.mycore.common.config.MCRConfigurationException in project mycore by MyCoRe-Org.

the class MCRCStoreVFS method init.

@Override
public void init(String storeId) {
    super.init(storeId);
    uri = MCRConfiguration.instance().getString(storeConfigPrefix + "URI");
    String check = MCRConfiguration.instance().getString(storeConfigPrefix + "StrictHostKeyChecking", "no");
    try {
        fsManager = VFS.getManager();
        opts = new FileSystemOptions();
        SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, check);
        FileObject baseDir = getBase();
        // Create a folder, if it does not exist or throw an
        // exception, if baseDir is not a folder
        baseDir.createFolder();
        if (!baseDir.isWriteable()) {
            String msg = "Content store base directory is not writeable: " + uri;
            throw new MCRConfigurationException(msg);
        }
    } catch (FileSystemException ex) {
        throw new MCRException(ex.getCode(), ex);
    }
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) MCRException(org.mycore.common.MCRException) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) FileObject(org.apache.commons.vfs2.FileObject) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions)

Example 7 with MCRConfigurationException

use of org.mycore.common.config.MCRConfigurationException in project mycore by MyCoRe-Org.

the class MCRContentStoreFactory method buildExtender.

/**
 * If the MCRContentStore of the MCRFile given provides an
 * MCRAudioVideoExtender implementation, this method creates and initializes
 * the MCRAudioVideoExtender instance for the MCRFile. The instance that is
 * returned is configured by the property
 * <tt>MCR.IFS.AVExtender.&lt;StoreID&gt;.Class</tt> in mycore.properties.
 *
 * @param file
 *            the non-null MCRFile that should get an MCRAudioVideoExtender
 * @return the MCRAudioVideoExtender for the MCRFile given, or null
 * @throws MCRConfigurationException
 *             if the MCRAudioVideoExtender implementation class could not
 *             be loaded
 */
static MCRAudioVideoExtender buildExtender(MCRFile file) {
    if (file == null || !providesAudioVideoExtender(file.getStoreID())) {
        return null;
    }
    Class<? extends MCRAudioVideoExtender> cl = getExtenderClass(file.getStoreID());
    try {
        MCRAudioVideoExtender ext = cl.getDeclaredConstructor().newInstance();
        ext.init(file);
        return ext;
    } catch (Exception exc) {
        if (exc instanceof MCRException) {
            throw (MCRException) exc;
        }
        String msg = "Could not build MCRAudioVideoExtender instance";
        throw new MCRConfigurationException(msg, exc);
    }
}
Also used : MCRException(org.mycore.common.MCRException) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) MCRException(org.mycore.common.MCRException) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException)

Example 8 with MCRConfigurationException

use of org.mycore.common.config.MCRConfigurationException in project mycore by MyCoRe-Org.

the class MCRPIRegistrationService method getGenerator.

private MCRPersistentIdentifierGenerator<T> getGenerator() {
    Supplier<? extends RuntimeException> generatorPropertiesNotSetError = () -> new MCRConfigurationException("Configuration property " + REGISTRATION_CONFIG_PREFIX + registrationServiceID + ".Generator is not set");
    String generatorName = Optional.ofNullable(getProperties().get("Generator")).orElseThrow(generatorPropertiesNotSetError);
    String inscriberPropertyKey = GENERATOR_CONFIG_PREFIX + generatorName;
    String className = MCRConfiguration.instance().getString(inscriberPropertyKey);
    try {
        @SuppressWarnings("unchecked") Class<MCRPersistentIdentifierGenerator<T>> classObject = (Class<MCRPersistentIdentifierGenerator<T>>) Class.forName(className);
        Constructor<MCRPersistentIdentifierGenerator<T>> constructor = classObject.getConstructor(String.class);
        return constructor.newInstance(generatorName);
    } catch (ClassNotFoundException e) {
        throw new MCRConfigurationException("Configurated class (" + inscriberPropertyKey + ") not found: " + className, e);
    } catch (NoSuchMethodException e) {
        throw new MCRConfigurationException("Configurated class (" + inscriberPropertyKey + ") needs a string constructor: " + className);
    } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
        throw new MCRException(e);
    }
}
Also used : MCRException(org.mycore.common.MCRException) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 9 with MCRConfigurationException

use of org.mycore.common.config.MCRConfigurationException in project mycore by MyCoRe-Org.

the class MCRPIRegistrationServiceManager method getRegistrationService.

public <T extends MCRPersistentIdentifier> MCRPIRegistrationService<T> getRegistrationService(String registrationServiceID) {
    String propertyName = REGISTRATION_SERVICE_CONFIG_PREFIX + registrationServiceID;
    Class<? extends MCRPIRegistrationService<T>> piClass = MCRConfiguration.instance().getClass(propertyName);
    try {
        Constructor<? extends MCRPIRegistrationService<T>> constructor = piClass.getConstructor(String.class);
        return constructor.newInstance(registrationServiceID);
    } catch (NoSuchMethodException e) {
        throw new MCRConfigurationException("The property : " + propertyName + " points to existing class, but without string constructor(serviceid)!", e);
    } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
        throw new MCRException("Cant initialize class the class defined in: " + propertyName, e);
    }
}
Also used : MCRException(org.mycore.common.MCRException) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 10 with MCRConfigurationException

use of org.mycore.common.config.MCRConfigurationException in project mycore by MyCoRe-Org.

the class MCRTokenRequest method post.

/**
 * Posts the request and returns the response.
 *
 * @throws MCRConfigurationException if request fails, e.g. because of misconfigured client ID and secret
 */
public MCRTokenResponse post() throws MCRConfigurationException, IOException {
    Entity<Form> formEntity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE);
    WebTarget target = baseTarget.path("token");
    Builder b = target.request().accept(MediaType.APPLICATION_JSON);
    Response r = b.post(formEntity);
    MCRTokenResponse response = new MCRTokenResponse(r);
    if (!response.wasSuccessful()) {
        throw new MCRConfigurationException(response.getStatusMessage());
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) Form(javax.ws.rs.core.Form) Builder(javax.ws.rs.client.Invocation.Builder) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) WebTarget(javax.ws.rs.client.WebTarget)

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