Example usage for org.apache.commons.configuration Configuration subset

List of usage examples for org.apache.commons.configuration Configuration subset

Introduction

In this page you can find the example usage for org.apache.commons.configuration Configuration subset.

Prototype

Configuration subset(String prefix);

Source Link

Document

Return a decorator Configuration containing every key from the current Configuration that starts with the specified prefix.

Usage

From source file:org.restcomm.connect.telephony.CallManager.java

public CallManager(final Configuration configuration, final ServletContext context,
        final MediaServerControllerFactory msControllerFactory, final ActorRef conferences,
        final ActorRef bridges, final ActorRef sms, final SipFactory factory, final DaoManager storage) {
    super();//from   w  w w  .j  a v  a 2s  .co m
    this.system = context().system();
    this.configuration = configuration;
    this.context = context;
    this.msControllerFactory = msControllerFactory;
    this.conferences = conferences;
    this.bridges = bridges;
    this.sms = sms;
    this.sipFactory = factory;
    this.storage = storage;
    final Configuration runtime = configuration.subset("runtime-settings");
    final Configuration outboundProxyConfig = runtime.subset("outbound-proxy");
    SipURI outboundIntf = outboundInterface("udp");
    if (outboundIntf != null) {
        myHostIp = ((SipURI) outboundIntf).getHost().toString();
    } else {
        String errMsg = "SipURI outboundIntf is null";
        sendNotification(errMsg, 14001, "error", false);

        if (context == null)
            errMsg = "SipServlet context is null";
        sendNotification(errMsg, 14002, "error", false);
    }
    Configuration mediaConf = configuration.subset("media-server-manager");
    mediaExternalIp = mediaConf.getString("mgcp-server.external-address");
    proxyIp = runtime.subset("telestax-proxy").getString("uri").replaceAll("http://", "").replaceAll(":2080",
            "");

    if (mediaExternalIp == null || mediaExternalIp.isEmpty())
        mediaExternalIp = myHostIp;

    if (proxyIp == null || proxyIp.isEmpty())
        proxyIp = myHostIp;

    this.useTo = runtime.getBoolean("use-to");
    this.authenticateUsers = runtime.getBoolean("authenticate");

    this.primaryProxyUri = outboundProxyConfig.getString("outbound-proxy-uri");
    this.primaryProxyUsername = outboundProxyConfig.getString("outbound-proxy-user");
    this.primaryProxyPassword = outboundProxyConfig.getString("outbound-proxy-password");

    this.fallBackProxyUri = outboundProxyConfig.getString("fallback-outbound-proxy-uri");
    this.fallBackProxyUsername = outboundProxyConfig.getString("fallback-outbound-proxy-user");
    this.fallBackProxyPassword = outboundProxyConfig.getString("fallback-outbound-proxy-password");

    this.activeProxy = primaryProxyUri;
    this.activeProxyUsername = primaryProxyUsername;
    this.activeProxyPassword = primaryProxyPassword;

    numberOfFailedCalls = new AtomicInteger();
    numberOfFailedCalls.set(0);
    useFallbackProxy = new AtomicBoolean();
    useFallbackProxy.set(false);

    allowFallback = outboundProxyConfig.getBoolean("allow-fallback", false);

    maxNumberOfFailedCalls = outboundProxyConfig.getInt("max-failed-calls", 20);

    allowFallbackToPrimary = outboundProxyConfig.getBoolean("allow-fallback-to-primary", false);

    patchForNatB2BUASessions = runtime.getBoolean("patch-for-nat-b2bua-sessions", true);

    //Monitoring Service
    this.monitoring = (ActorRef) context.getAttribute(MonitoringService.class.getName());

    extensions = ExtensionController.getInstance().getExtensions(ExtensionType.CallManager);
    if (logger.isInfoEnabled()) {
        logger.info("CallManager extensions: " + (extensions != null ? extensions.size() : "0"));
    }
    if (!runtime.subset("ims-authentication").isEmpty()) {
        final Configuration imsAuthentication = runtime.subset("ims-authentication");
        this.actAsImsUa = imsAuthentication.getBoolean("act-as-ims-ua");
        if (actAsImsUa) {
            this.imsProxyAddress = imsAuthentication.getString("proxy-address");
            this.imsProxyPort = imsAuthentication.getInt("proxy-port");
            if (imsProxyPort == 0) {
                imsProxyPort = DEFAUL_IMS_PROXY_PORT;
            }
            this.imsDomain = imsAuthentication.getString("domain");
            this.imsAccount = imsAuthentication.getString("account");
            if (actAsImsUa && (imsProxyAddress == null || imsProxyAddress.isEmpty() || imsDomain == null
                    || imsDomain.isEmpty())) {
                logger.warning("ims proxy-address or domain is not configured");
            }
            this.actAsImsUa = actAsImsUa && imsProxyAddress != null && !imsProxyAddress.isEmpty()
                    && imsDomain != null && !imsDomain.isEmpty();
        }
    }
    firstTimeCleanup();
}

From source file:org.restcomm.connect.telephony.CallManager.java

private boolean proxyOut(SipServletRequest request, Client client, String toUser, String toHost,
        String toHostIpAddress, String toPort, SipURI outboundIntf, String proxyURI, String proxyUsername,
        String proxyPassword, SipURI from, SipURI to, boolean callToSipUri) throws UnknownHostException {
    final Configuration runtime = configuration.subset("runtime-settings");
    final boolean useLocalAddressAtFromHeader = runtime.getBoolean("use-local-address", false);
    final boolean outboudproxyUserAtFromHeader = runtime.subset("outbound-proxy")
            .getBoolean("outboudproxy-user-at-from-header", true);

    final String fromHost = ((SipURI) request.getFrom().getURI()).getHost();
    final String fromHostIpAddress = InetAddress.getByName(fromHost).getHostAddress();
    //                    final String fromPort = String.valueOf(((SipURI) request.getFrom().getURI()).getPort()).equalsIgnoreCase("-1") ? "5060"
    //                            : String.valueOf(((SipURI) request.getFrom().getURI()).getHost());

    if (logger.isInfoEnabled()) {
        logger.info("fromHost: " + fromHost + "fromHostIP: " + fromHostIpAddress + "myHostIp: " + myHostIp
                + " mediaExternalIp: " + mediaExternalIp + " toHost: " + toHost + " toHostIP: "
                + toHostIpAddress + " proxyUri: " + proxyURI);
    }// w w w . j  av  a  2s.c om
    if ((myHostIp.equalsIgnoreCase(toHost) || mediaExternalIp.equalsIgnoreCase(toHost))
            || (myHostIp.equalsIgnoreCase(toHostIpAddress) || mediaExternalIp.equalsIgnoreCase(toHostIpAddress))
            // https://github.com/RestComm/Restcomm-Connect/issues/1357
            || (fromHost.equalsIgnoreCase(toHost) || fromHost.equalsIgnoreCase(toHostIpAddress))
            || (fromHostIpAddress.equalsIgnoreCase(toHost)
                    || fromHostIpAddress.equalsIgnoreCase(toHostIpAddress))) {
        if (logger.isInfoEnabled()) {
            logger.info("Call to NUMBER.  myHostIp: " + myHostIp + " mediaExternalIp: " + mediaExternalIp
                    + " toHost: " + toHost + " proxyUri: " + proxyURI);
        }
        try {
            if (useLocalAddressAtFromHeader) {
                if (outboudproxyUserAtFromHeader) {
                    from = (SipURI) sipFactory.createSipURI(proxyUsername,
                            mediaExternalIp + ":" + outboundIntf.getPort());
                } else {
                    from = sipFactory.createSipURI(((SipURI) request.getFrom().getURI()).getUser(),
                            mediaExternalIp + ":" + outboundIntf.getPort());
                }
            } else {
                if (outboudproxyUserAtFromHeader) {
                    // https://telestax.atlassian.net/browse/RESTCOMM-633. Use the outbound proxy username as
                    // the userpart of the sip uri for the From header
                    from = (SipURI) sipFactory.createSipURI(proxyUsername, proxyURI);
                } else {
                    from = sipFactory.createSipURI(((SipURI) request.getFrom().getURI()).getUser(), proxyURI);
                }
            }
            to = sipFactory.createSipURI(((SipURI) request.getTo().getURI()).getUser(), proxyURI);
        } catch (Exception exception) {
            if (logger.isInfoEnabled()) {
                logger.info("Exception: " + exception);
            }
        }
    } else {
        if (logger.isInfoEnabled()) {
            logger.info("Call to SIP URI. myHostIp: " + myHostIp + " mediaExternalIp: " + mediaExternalIp
                    + " toHost: " + toHost + " proxyUri: " + proxyURI);
        }
        from = sipFactory.createSipURI(((SipURI) request.getFrom().getURI()).getUser(),
                outboundIntf.getHost() + ":" + outboundIntf.getPort());
        to = sipFactory.createSipURI(toUser, toHost + ":" + toPort);
        callToSipUri = true;
    }
    if (B2BUAHelper.redirectToB2BUA(request, client, from, to, proxyUsername, proxyPassword, storage,
            sipFactory, callToSipUri, patchForNatB2BUASessions)) {
        return true;
    }
    return false;
}

From source file:org.restcomm.connect.telephony.CallManager.java

private void outboundToPstn(final CreateCall request, final ActorRef sender) throws ServletParseException {
    final String uri = (request.getOutboundProxy() != null && (!request.getOutboundProxy().isEmpty()))
            ? request.getOutboundProxy()
            : activeProxy;/*from  w  ww  .  jav a 2  s.co  m*/
    SipURI outboundIntf = null;
    SipURI from = null;
    SipURI to = null;

    final Configuration runtime = configuration.subset("runtime-settings");
    final boolean useLocalAddressAtFromHeader = runtime.getBoolean("use-local-address", false);

    final String proxyUsername = (request.username() != null) ? request.username() : activeProxyUsername;

    if (uri != null) {
        try {
            to = sipFactory.createSipURI(request.to(), uri);
            String transport = (to.getTransportParam() != null) ? to.getTransportParam() : "udp";
            outboundIntf = outboundInterface(transport);
            final boolean outboudproxyUserAtFromHeader = runtime.subset("outbound-proxy")
                    .getBoolean("outboudproxy-user-at-from-header");
            if (request.from() != null && request.from().contains("@")) {
                // https://github.com/Mobicents/RestComm/issues/150 if it contains @ it means this is a sip uri and we allow
                // to use it directly
                from = (SipURI) sipFactory.createURI(request.from());
            } else if (useLocalAddressAtFromHeader) {
                from = sipFactory.createSipURI(request.from(), mediaExternalIp + ":" + outboundIntf.getPort());
            } else {
                if (outboudproxyUserAtFromHeader) {
                    // https://telestax.atlassian.net/browse/RESTCOMM-633. Use the outbound proxy username as the userpart
                    // of the sip uri for the From header
                    from = (SipURI) sipFactory.createSipURI(proxyUsername, uri);
                } else {
                    from = sipFactory.createSipURI(request.from(), uri);
                }
            }
            if (((SipURI) from).getUser() == null || ((SipURI) from).getUser() == "") {
                if (uri != null) {
                    from = sipFactory.createSipURI(request.from(), uri);
                } else {
                    from = (SipURI) sipFactory.createURI(request.from());
                }
            }
        } catch (Exception exception) {
            sender.tell(new CallManagerResponse<ActorRef>(exception, this.createCallRequest), self());
        }
        if (from == null || to == null) {
            //In case From or To are null we have to cancel outbound call and hnagup initial call if needed
            final String errMsg = "From and/or To are null, we cannot proceed to the outbound call to: "
                    + request.to();
            logger.warning(errMsg);
            sender.tell(
                    new CallManagerResponse<ActorRef>(new NullPointerException(errMsg), this.createCallRequest),
                    self());
        } else {
            sender.tell(new CallManagerResponse<ActorRef>(createOutbound(request, from, to, false)), self());
        }
    } else {
        String errMsg = "Cannot create call to: " + request.to()
                + ". The Active Outbound Proxy is null. Please check configuration";
        logger.warning(errMsg);
        sendNotification(errMsg, 11008, "error", true);
        sender.tell(new CallManagerResponse<ActorRef>(new NullPointerException(errMsg), this.createCallRequest),
                self());
    }
}

From source file:org.restcomm.connect.telephony.CallManager.java

private ActorRef createOutbound(final CreateCall request, final SipURI from, final SipURI to,
        final boolean webRTC) {
    final Configuration runtime = configuration.subset("runtime-settings");
    final String proxyUsername = (request.username() != null) ? request.username() : activeProxyUsername;
    final String proxyPassword = (request.password() != null) ? request.password() : activeProxyPassword;

    final ActorRef call = call(request);
    final ActorRef self = self();
    final boolean userAtDisplayedName = runtime.subset("outbound-proxy").getBoolean("user-at-displayed-name");
    InitializeOutbound init;//from   w w w .  j av  a  2 s.  com
    if (request.from() != null && !request.from().contains("@") && userAtDisplayedName) {
        init = new InitializeOutbound(request.from(), from, to, proxyUsername, proxyPassword, request.timeout(),
                request.isFromApi(), runtime.getString("api-version"), request.accountId(), request.type(),
                storage, webRTC);
    } else {
        init = new InitializeOutbound(null, from, to, proxyUsername, proxyPassword, request.timeout(),
                request.isFromApi(), runtime.getString("api-version"), request.accountId(), request.type(),
                storage, webRTC);
    }
    if (request.parentCallSid() != null) {
        init.setParentCallSid(request.parentCallSid());
    }
    call.tell(init, self);
    return call;
}

From source file:org.restcomm.connect.telephony.ua.UserAgentManager.java

public UserAgentManager(final Configuration configuration, final SipFactory factory, final DaoManager storage,
        final ServletContext servletContext) {
    super();/*  w w w.j  a  v a2 s  .  co  m*/
    // this.configuration = configuration;
    this.servletContext = servletContext;
    monitoringService = (ActorRef) servletContext.getAttribute(MonitoringService.class.getName());
    final Configuration runtime = configuration.subset("runtime-settings");
    this.authenticateUsers = runtime.getBoolean("authenticate");
    this.factory = factory;
    this.storage = storage;
    pingInterval = runtime.getInt("ping-interval", 60);
    logger.info("About to run firstTimeCleanup()");
    instanceId = RestcommConfiguration.getInstance().getMain().getInstanceId();
    if (!runtime.subset("ims-authentication").isEmpty()) {
        final Configuration imsAuthentication = runtime.subset("ims-authentication");
        this.actAsImsUa = imsAuthentication.getBoolean("act-as-ims-ua");
        if (actAsImsUa) {
            this.imsProxyAddress = imsAuthentication.getString("proxy-address");
            this.imsProxyPort = imsAuthentication.getInt("proxy-port");
            if (imsProxyPort == 0) {
                imsProxyPort = DEFAUL_IMS_PROXY_PORT;
            }
            this.imsDomain = imsAuthentication.getString("domain");
            if (actAsImsUa && (imsProxyAddress == null || imsProxyAddress.isEmpty() || imsDomain == null
                    || imsDomain.isEmpty())) {
                logger.warning("ims proxy-address or domain is not configured");
            }
            this.actAsImsUa = actAsImsUa && imsProxyAddress != null && !imsProxyAddress.isEmpty()
                    && imsDomain != null && !imsDomain.isEmpty();
        }
    }

    firstTimeCleanup();
}

From source file:org.restcomm.connect.ussd.interpreter.UssdInterpreter.java

public UssdInterpreter(final Configuration configuration, final Sid account, final Sid phone,
        final String version, final URI url, final String method, final URI fallbackUrl,
        final String fallbackMethod, final URI statusCallback, final String statusCallbackMethod,
        final String emailAddress, final ActorRef callManager, final ActorRef conferenceManager,
        final ActorRef sms, final DaoManager storage) {
    super();/*from  ww  w.j a  va2s . com*/
    final ActorRef source = self();
    this.system = context().system();

    uninitialized = new State("uninitialized", null, null);
    observeCall = new State("observe call", new ObserveCall(source), null);
    acquiringCallInfo = new State("acquiring call info", new AcquiringCallInfo(source), null);
    downloadingRcml = new State("downloading rcml", new DownloadingRcml(source), null);
    downloadingFallbackRcml = new State("downloading fallback rcml", new DownloadingFallbackRcml(source), null);
    preparingMessage = new State("Preparing message", new PreparingMessage(source), null);
    processingInfoRequest = new State("Processing info request from client", new ProcessingInfoRequest(source),
            null);

    ready = new State("ready", new Ready(source), null);
    notFound = new State("notFound", new NotFound(source), null);

    cancelling = new State("Cancelling", new Cancelling(source), null);
    disconnecting = new State("Disconnecting", new Disconnecting(source), null);

    finished = new State("finished", new Finished(source), null);

    transitions.add(new Transition(uninitialized, acquiringCallInfo));
    transitions.add(new Transition(uninitialized, cancelling));
    transitions.add(new Transition(acquiringCallInfo, downloadingRcml));
    transitions.add(new Transition(acquiringCallInfo, cancelling));
    transitions.add(new Transition(downloadingRcml, ready));
    transitions.add(new Transition(downloadingRcml, cancelling));
    transitions.add(new Transition(downloadingRcml, notFound));
    transitions.add(new Transition(downloadingRcml, downloadingFallbackRcml));
    transitions.add(new Transition(downloadingRcml, finished));
    transitions.add(new Transition(downloadingRcml, ready));
    transitions.add(new Transition(ready, preparingMessage));
    transitions.add(new Transition(preparingMessage, downloadingRcml));
    transitions.add(new Transition(preparingMessage, processingInfoRequest));
    transitions.add(new Transition(preparingMessage, disconnecting));
    transitions.add(new Transition(preparingMessage, finished));
    transitions.add(new Transition(processingInfoRequest, preparingMessage));
    transitions.add(new Transition(processingInfoRequest, ready));
    transitions.add(new Transition(processingInfoRequest, finished));
    transitions.add(new Transition(disconnecting, finished));

    // Initialize the FSM.
    this.fsm = new FiniteStateMachine(uninitialized, transitions);
    // Initialize the runtime stuff.
    this.accountId = account;
    this.phoneId = phone;
    this.version = version;
    this.url = url;
    this.method = method;
    this.fallbackUrl = fallbackUrl;
    this.fallbackMethod = fallbackMethod;
    this.statusCallback = statusCallback;
    this.statusCallbackMethod = statusCallbackMethod;
    this.emailAddress = emailAddress;
    this.configuration = configuration;

    this.storage = storage;
    final Configuration runtime = configuration.subset("runtime-settings");
    String path = runtime.getString("cache-path");
    if (!path.endsWith("/")) {
        path = path + "/";
    }
    path = path + accountId.toString();
    this.downloader = downloader();
}

From source file:org.restcomm.connect.ussd.telephony.UssdCallManager.java

/**
 * @param configuration/* w  ww.  j a  va2  s. c o m*/
 * @param context
 * @param conferences
 * @param sms
 * @param factory
 * @param storage
 */
public UssdCallManager(final ActorSystem system, Configuration configuration, ServletContext context,
        ActorRef conferences, ActorRef sms, SipFactory factory, DaoManager storage) {
    super();
    this.system = system;
    this.configuration = configuration;
    this.context = context;
    this.sipFactory = factory;
    this.storage = storage;
    final Configuration runtime = configuration.subset("runtime-settings");
    final Configuration ussdGatewayConfig = runtime.subset("ussd-gateway");
    this.ussdGatewayUri = ussdGatewayConfig.getString("ussd-gateway-uri");
    this.ussdGatewayUsername = ussdGatewayConfig.getString("ussd-gateway-user");
    this.ussdGatewayPassword = ussdGatewayConfig.getString("ussd-gateway-password");
}

From source file:org.restcomm.sbc.Bootstrapper.java

@Override
public void init(final ServletConfig config) throws ServletException {
    final ServletContext context = config.getServletContext();
    final String path = context.getRealPath("WEB-INF/conf/sbc.xml");
    // Initialize the configuration interpolator.
    final ConfigurationStringLookup strings = new ConfigurationStringLookup();
    strings.addProperty("home", home(config));
    strings.addProperty("uri", uri(config));
    ConfigurationInterpolator.registerGlobalLookup("sbc", strings);
    // Load the RestComm configuration file.
    Configuration xml = null;
    try {//from w ww.  j  ava2s  .co m
        xml = new XMLConfiguration(path);
    } catch (final ConfigurationException exception) {
        logger.error(exception);
    }
    xml.setProperty("runtime-settings.home-directory", home(config));
    xml.setProperty("runtime-settings.root-uri", uri(config));
    context.setAttribute(Configuration.class.getName(), xml);
    // Initialize global dependencies.
    final ClassLoader loader = getClass().getClassLoader();
    // Create the actor system.
    //final Config settings = ConfigFactory.load();
    ConfigFactory.load();
    // Create the storage system.
    DaoManager storage = null;
    try {
        storage = storage(xml, loader);
    } catch (final ObjectInstantiationException exception) {
        throw new ServletException(exception);
    }

    context.setAttribute(DaoManager.class.getName(), storage);
    ShiroResources.getInstance().set(DaoManager.class, storage);
    ShiroResources.getInstance().set(Configuration.class, xml.subset("runtime-settings"));
    // Create high-level restcomm configuration
    RestcommConfiguration.createOnce(xml);
    // Initialize identityContext
    IdentityContext identityContext = new IdentityContext(xml);
    context.setAttribute(IdentityContext.class.getName(), identityContext);

    logger.info("Extern IP:" + xml.getString("runtime-settings.external-ip"));

    Version.printVersion();

}

From source file:org.restcomm.sbc.Bootstrapper.java

private DaoManager storage(final Configuration configuration, final ClassLoader loader)
        throws ObjectInstantiationException {
    final String classpath = configuration.getString("dao-manager[@class]");
    final DaoManager daoManager = (DaoManager) new ObjectFactory(loader).getObjectInstance(classpath);
    daoManager.configure(configuration.subset("dao-manager"));
    daoManager.start();/*  w  w  w .  jav  a  2  s . c  o  m*/
    logger.info("DaoManager started");
    return daoManager;
}

From source file:org.seedstack.elasticsearch.internal.ElasticSearchPlugin.java

@Override
public InitState init(InitContext initContext) {
    ApplicationPlugin applicationPlugin = initContext.dependency(ApplicationPlugin.class);
    Configuration elasticSearchConfiguration = applicationPlugin.getApplication().getConfiguration()
            .subset(ELASTIC_SEARCH_PLUGIN_CONFIGURATION_PREFIX);

    String[] elasticSearchClientNames = elasticSearchConfiguration.getStringArray("clients");
    if (elasticSearchClientNames != null && elasticSearchClientNames.length > 0) {
        for (String elasticSearchClientName : elasticSearchClientNames) {
            Configuration elasticSearchClientConfiguration = elasticSearchConfiguration
                    .subset("client." + elasticSearchClientName);

            Iterator<String> it = elasticSearchClientConfiguration.getKeys("property");
            Map<String, String> propertiesMap = new HashMap<String, String>();
            while (it.hasNext()) {
                String name = it.next();
                propertiesMap.put(name.substring(9), elasticSearchClientConfiguration.getString(name));
            }//from   w w w  .j  a va  2  s .  co  m

            if (!propertiesMap.containsKey("path.home")) {
                propertiesMap.put("path.home",
                        applicationPlugin.getApplication().getStorageLocation(
                                ElasticSearchPlugin.ELASTIC_SEARCH_STORAGE_ROOT + elasticSearchClientName)
                                .getAbsolutePath());
            }

            String[] hosts = elasticSearchClientConfiguration.getStringArray("hosts");
            if (hosts == null || hosts.length == 0) {
                LOGGER.info("Creating ElasticSearch client {} on its local node", elasticSearchClientName);

                Node node = buildLocalNode(buildSettings(propertiesMap));
                elasticSearchLocalNodes.put(elasticSearchClientName, node);
                elasticSearchClients.put(elasticSearchClientName, node.client());
            } else {
                LOGGER.info("Creating ElasticSearch client {} for remote instance at {}",
                        elasticSearchClientName, Arrays.toString(hosts));

                elasticSearchClients.put(elasticSearchClientName,
                        buildRemoteClient(buildSettings(propertiesMap), hosts));
            }
        }

    } else {
        LOGGER.info("No ElasticSearch client configured, ElasticSearch support disabled");
    }

    return InitState.INITIALIZED;
}