All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nosi.core.embedded.server.ContainerConfiguration Maven / Gradle / Ivy

Go to download

IGRP Framework is a powerful and highly customizable platform developed by the Operational Nucleus for the Information Society (NOSi) to create web applications, it provides out of box, several modules to make easy to create stand-alone, production-grade web applications: authentication and access-control, business processes automation, reporting, page builder with automatic code generation and incorporation of the Once-Only-Principle, written in Java. IGRP Framework WAR - Contains some keys resources that give UI to IGRP Framework and others supports files.

There is a newer version: 2.0.0.240912-RCM
Show newest version
package nosi.core.embedded.server;

import nosi.core.config.ConfigCommonMainConstants;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.tomee.embedded.Configuration;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.Properties;

/**
 * @author Iekiny Marcel
 * Mar 18, 2022
 */
public final class ContainerConfiguration extends Configuration {

    private static final Logger LOGGER = LogManager.getLogger(ContainerConfiguration.class);

    public static final String CONFIGURATION_RESOURCE_PATH = "config/common/main.xml";
    public static final String DEFAULT_CONTEXT_PATH = "/IGRP";
    public static final int DEFAULT_HTTP_PORT = 8080;

    private String contextPath;

    public void loadConfigurations() {
        final Properties configs = this.loadConfigurationProperties();
        this.setHttpPort(Integer.parseInt(configs.getProperty(ConfigCommonMainConstants.IGRP_EMBEDDED_SERVER_HTTP_PORT.value(), DEFAULT_HTTP_PORT + "")));
        contextPath = configs.getProperty(ConfigCommonMainConstants.IGRP_EMBEDDED_SERVER_SERVLET_CONTEXT_PATH.value(), DEFAULT_CONTEXT_PATH);
        // ... more configuration loaded can be defined here ...
    }

    private Properties loadConfigurationProperties() {
        final Properties configs = new Properties();
        try (InputStream inputStream = this.getResourceStream()) {
            configs.loadFromXML(inputStream);
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
        return configs;
    }

    private InputStream getResourceStream() throws IOException {
        final InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(CONFIGURATION_RESOURCE_PATH);
        if (inputStream == null) {
            final File file = new File(CONFIGURATION_RESOURCE_PATH);
            if (file.exists())
                return Files.newInputStream(file.toPath());
        }
        return inputStream;
    }

    public String getContextPath() {
        return contextPath;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy