Example usage for org.apache.commons.configuration AbstractConfiguration getKeys

List of usage examples for org.apache.commons.configuration AbstractConfiguration getKeys

Introduction

In this page you can find the example usage for org.apache.commons.configuration AbstractConfiguration getKeys.

Prototype

public Iterator getKeys(final String prefix) 

Source Link

Usage

From source file:com.kixeye.chassis.transport.websocket.WebSocketTransportConfiguration.java

@Bean(initMethod = "start", destroyMethod = "stop")
@Order(0)/*from w  w w .  j ava  2  s .  c om*/
public Server webSocketServer(@Value("${websocket.enabled:false}") boolean websocketEnabled,
        @Value("${websocket.hostname:}") String websocketHostname,
        @Value("${websocket.port:-1}") int websocketPort,

        @Value("${secureWebsocket.enabled:false}") boolean secureWebsocketEnabled,
        @Value("${secureWebsocket.hostname:}") String secureWebsocketHostname,
        @Value("${secureWebsocket.port:-1}") int secureWebsocketPort,
        @Value("${secureWebsocket.selfSigned:false}") boolean selfSigned,
        @Value("${secureWebsocket.mutualSsl:false}") boolean mutualSsl,

        @Value("${secureWebsocket.keyStorePath:}") String keyStorePath,
        @Value("${secureWebsocket.keyStoreData:}") String keyStoreData,
        @Value("${secureWebsocket.keyStorePassword:}") String keyStorePassword,
        @Value("${secureWebsocket.keyManagerPassword:}") String keyManagerPassword,

        @Value("${secureWebsocket.trustStorePath:}") String trustStorePath,
        @Value("${secureWebsocket.trustStoreData:}") String trustStoreData,
        @Value("${secureWebsocket.trustStorePassword:}") String trustStorePassword,

        @Value("${securewebsocket.excludedCipherSuites:}") String[] excludedCipherSuites) throws Exception {
    // set up servlets
    ServletContextHandler context = new ServletContextHandler(
            ServletContextHandler.NO_SESSIONS | ServletContextHandler.NO_SECURITY);
    context.setErrorHandler(null);
    context.setWelcomeFiles(new String[] { "/" });

    for (final MessageSerDe serDe : serDes) {
        // create the websocket creator
        final WebSocketCreator webSocketCreator = new WebSocketCreator() {
            public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp) {
                // this will have spring construct a new one for every session
                ActionInvokingWebSocket webSocket = forwardingWebSocket();
                webSocket.setSerDe(serDe);
                webSocket.setUpgradeRequest(req);
                webSocket.setUpgradeResponse(resp);

                return webSocket;
            }
        };

        // configure the websocket servlet
        ServletHolder webSocketServlet = new ServletHolder(new WebSocketServlet() {
            private static final long serialVersionUID = -3022799271546369505L;

            @Override
            public void configure(WebSocketServletFactory factory) {
                factory.setCreator(webSocketCreator);
            }
        });

        Map<String, String> webSocketProperties = new HashMap<>();
        AbstractConfiguration config = ConfigurationManager.getConfigInstance();
        Iterator<String> webSocketPropertyKeys = config.getKeys("websocket");
        while (webSocketPropertyKeys.hasNext()) {
            String key = webSocketPropertyKeys.next();

            webSocketProperties.put(key.replaceFirst(Pattern.quote("websocket."), ""), config.getString(key));
        }

        webSocketServlet.setInitParameters(webSocketProperties);

        context.addServlet(webSocketServlet, "/" + serDe.getMessageFormatName() + "/*");
    }

    // create the server
    Server server;
    if (metricRegistry == null || !monitorThreadpool) {
        server = new Server();

        server.setHandler(context);
    } else {
        server = new Server(new InstrumentedQueuedThreadPool(metricRegistry));

        InstrumentedHandler instrumented = new InstrumentedHandler(metricRegistry);
        instrumented.setHandler(context);

        server.setHandler(instrumented);
    }

    // set up connectors
    if (websocketEnabled) {
        InetSocketAddress address = StringUtils.isBlank(websocketHostname)
                ? new InetSocketAddress(websocketPort)
                : new InetSocketAddress(websocketHostname, websocketPort);

        JettyConnectorRegistry.registerHttpConnector(server, address);
    }

    if (secureWebsocketEnabled) {
        InetSocketAddress address = StringUtils.isBlank(secureWebsocketHostname)
                ? new InetSocketAddress(secureWebsocketPort)
                : new InetSocketAddress(secureWebsocketHostname, secureWebsocketPort);

        JettyConnectorRegistry.registerHttpsConnector(server, address, selfSigned, mutualSsl, keyStorePath,
                keyStoreData, keyStorePassword, keyManagerPassword, trustStorePath, trustStoreData,
                trustStorePassword, excludedCipherSuites);
    }

    return server;
}

From source file:com.netflix.explorers.AppConfigGlobalModelContext.java

@Inject
public AppConfigGlobalModelContext(@Named("explorerAppName") String appName) {
    final String propertiesFileName = appName + "-explorers-app.properties";

    try {/*  w  w  w.ja  v a2  s. com*/
        ConfigurationManager.loadPropertiesFromResources(propertiesFileName);
    } catch (IOException e) {
        LOG.error(String.format(
                "Exception loading properties file - %s, Explorers application may not work correctly ",
                propertiesFileName));
    }

    AbstractConfiguration configuration = ConfigurationManager.getConfigInstance();

    environmentName = configuration.getString(PROPERTY_ENVIRONMENT_NAME);
    currentRegion = configuration.getString(PROPERTY_CURRENT_REGION);
    applicationVersion = (String) configuration.getProperty(PROPERTY_APPLICATION_VERSION);
    applicationName = (String) configuration.getProperty(PROPERTY_APPLICATION_NAME);
    isLocal = configuration.getBoolean(PROPERTY_IS_LOCAL, false);
    homePageUrl = configuration.getString(PROPERTY_HOME_PAGE);
    defaultPort = configuration.getShort(PROPERTY_DEFAULT_PORT, (short) 8080);
    dataCenter = configuration.getString(PROPERTY_DATA_CENTER);
    defaultExplorerName = configuration.getString(PROPERTY_DEFAULT_EXPLORER);

    try {
        Iterator<String> dcKeySet = configuration.getKeys(PROPERTIES_PREFIX + ".dc");
        while (dcKeySet.hasNext()) {
            String dcKey = dcKeySet.next();
            String key = StringUtils.substringBefore(dcKey, ".");
            String attr = StringUtils.substringAfter(dcKey, ".");

            CrossLink link = links.get(key);
            if (link == null) {
                link = new CrossLink();
                links.put(key, link);
            }

            BeanUtils.setProperty(link, attr, configuration.getProperty(dcKey));
        }
    } catch (Exception e) {
        LOG.error("Exception in constructing links map ", e);
        throw new RuntimeException(e);
    }
}

From source file:org.skb.util.types.composite.util.TSPropertyMap.java

public String loadFromFile(String fn) {
    try {//from  ww w . j ava2s. co m
        AbstractConfiguration cfg;
        String prefix = "";
        if (fn.endsWith(".ini")) {
            cfg = new INIConfiguration(fn);
            prefix = "tribe.";
        } else if (fn.endsWith(".xml"))
            cfg = new XMLConfiguration(fn);
        else if (fn.endsWith(".properties"))
            cfg = new PropertiesConfiguration(fn);
        else
            return "unknown configuration file format, use '.ini' or '.xml' or '.properties'";

        File file = new File(fn);
        if (!file.canRead())
            return "can't read configuration file <" + fn + ">";

        Iterator<?> it;
        if (prefix != "")
            it = cfg.getKeys(prefix);
        else
            it = cfg.getKeys();
        while (it.hasNext()) {
            String p = it.next().toString();
            if (this.containsKey(p)) {
                String type = this.get(p, TSPropertyMap.pmValType).toString();
                if (type.equals(TSRepository.TString.TS_ATOMIC_JAVA_STRING))
                    this.put(p, TSPropertyMap.pmValValueFile, cfg.getString(p));
                else if (type.equals(TSRepository.TString.TS_ATOMIC_JAVA_BOOLEAN))
                    this.put(p, TSPropertyMap.pmValValueFile, cfg.getBoolean(p, false));
                else if (type.equals(TSRepository.TString.TS_ATOMIC_JAVA_INTEGER))
                    this.put(p, TSPropertyMap.pmValValueFile, cfg.getInteger(p, 0));
                else if (type.equals(TSRepository.TString.TS_ATOMIC_JAVA_DOUBLE))
                    this.put(p, TSPropertyMap.pmValValueFile, cfg.getDouble(p));
                else if (type.equals(TSRepository.TString.TS_ATOMIC_JAVA_LONG))
                    this.put(p, TSPropertyMap.pmValValueFile, cfg.getLong(p, 0));
                //                 else
                //                    System.err.println("TSPropMap, loadfromfile, unknown type <"+type+"> for <"+p+">");
            }

        }
    } catch (Exception e) {
        //           ReportManager repMgr=ReportManager.getInstance();
        //           repMgr.reportErrorNoFile(e.toString());
    }
    return null;
}