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.mobicents.servlet.restcomm.telephony.CallManager.java

public CallManager(final Configuration configuration, final ServletContext context, final ActorSystem system,
        final MediaServerControllerFactory msControllerFactory, final ActorRef conferences,
        final ActorRef bridges, final ActorRef sms, final SipFactory factory, final DaoManager storage) {
    super();//  w w  w .j av  a 2s  .  c o m
    this.system = 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());
}

From source file:org.mobicents.servlet.restcomm.telephony.CallManager.java

private void invite(final Object message) throws IOException, NumberParseException, ServletParseException {
    final ActorRef self = self();
    final SipServletRequest request = (SipServletRequest) message;
    // Make sure we handle re-invites properly.
    if (!request.isInitial()) {
        final SipServletResponse okay = request.createResponse(SC_OK);
        okay.send();/*from  www . j  a va  2 s .com*/
        return;
    }
    //Run proInboundAction Extensions here
    // If it's a new invite lets try to handle it.
    final AccountsDao accounts = storage.getAccountsDao();
    final ApplicationsDao applications = storage.getApplicationsDao();
    // Try to find an application defined for the client.
    final SipURI fromUri = (SipURI) request.getFrom().getURI();
    String fromUser = fromUri.getUser();
    final ClientsDao clients = storage.getClientsDao();
    final Client client = clients.getClient(fromUser);
    if (client != null) {
        // Make sure we force clients to authenticate.
        if (!authenticateUsers // https://github.com/Mobicents/RestComm/issues/29 Allow disabling of SIP authentication
                || CallControlHelper.checkAuthentication(request, storage)) {
            // if the client has authenticated, try to redirect to the Client VoiceURL app
            // otherwise continue trying to process the Client invite
            if (redirectToClientVoiceApp(self, request, accounts, applications, client)) {
                return;
            } // else continue trying other ways to handle the request
        } else {
            // Since the client failed to authenticate, we will take no further action at this time.
            return;
        }
    }
    // TODO Enforce some kind of security check for requests coming from outside SIP UAs such as ITSPs that are not
    // registered

    final String toUser = CallControlHelper.getUserSipId(request, useTo);
    final String ruri = ((SipURI) request.getRequestURI()).getHost();
    final String toHost = ((SipURI) request.getTo().getURI()).getHost();
    final String toHostIpAddress = InetAddress.getByName(toHost).getHostAddress();
    final String toPort = String.valueOf(((SipURI) request.getTo().getURI()).getPort()).equalsIgnoreCase("-1")
            ? "5060"
            : String.valueOf(((SipURI) request.getTo().getURI()).getHost());
    final String transport = ((SipURI) request.getTo().getURI()).getTransportParam() == null ? "udp"
            : ((SipURI) request.getTo().getURI()).getTransportParam();
    SipURI outboundIntf = outboundInterface(transport);

    if (logger.isInfoEnabled()) {
        logger.info("ToHost: " + toHost);
        logger.info("ruri: " + ruri);
        logger.info("myHostIp: " + myHostIp);
        logger.info("mediaExternalIp: " + mediaExternalIp);
        logger.info("proxyIp: " + proxyIp);
    }

    if (client != null) { // make sure the caller is a registered client and not some external SIP agent that we have little control over
        Client toClient = clients.getClient(toUser);
        if (toClient != null) { // looks like its a p2p attempt between two valid registered clients, lets redirect to the b2bua
            if (logger.isInfoEnabled()) {
                logger.info("Client is not null: " + client.getLogin() + " will try to proxy to client: "
                        + toClient);
            }
            if (B2BUAHelper.redirectToB2BUA(request, client, toClient, storage, sipFactory,
                    patchForNatB2BUASessions)) {
                if (logger.isInfoEnabled()) {
                    logger.info("Call to CLIENT.  myHostIp: " + myHostIp + " mediaExternalIp: "
                            + mediaExternalIp + " toHost: " + toHost + " fromClient: " + client.getUri()
                            + " toClient: " + toClient.getUri());
                }
                // if all goes well with proxying the invitation on to the next client
                // then we can end further processing of this INVITE
                return;
            } else {

                String errMsg = "Cannot Connect to Client: " + toClient.getFriendlyName()
                        + " : Make sure the Client exist or is registered with Restcomm";
                sendNotification(errMsg, 11001, "warning", true);

            }
        } else {
            // toClient is null or we couldn't make the b2bua call to another client. check if this call is for a registered
            // DID (application)
            if (redirectToHostedVoiceApp(self, request, accounts, applications, toUser)) {
                // This is a call to a registered DID (application)
                return;
            }
            // This call is not a registered DID (application). Try to proxy out this call.
            // log to console and to notification engine
            String errMsg = "A Restcomm Client is trying to call a Number/DID that is not registered with Restcomm";
            sendNotification(errMsg, 11002, "info", true);

            if (isWebRTC(request)) {
                //This is a WebRTC client that dials out
                proxyThroughMediaServer(request, client, toUser);
                return;
            }

            // https://telestax.atlassian.net/browse/RESTCOMM-335
            final String proxyURI = activeProxy;
            final String proxyUsername = activeProxyUsername;
            final String proxyPassword = activeProxyPassword;
            SipURI from = null;
            SipURI to = null;
            boolean callToSipUri = false;
            // proxy DID or number if the outbound proxy fields are not empty in the restcomm.xml
            if (proxyURI != null && !proxyURI.isEmpty()) {
                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);
                if ((myHostIp.equalsIgnoreCase(toHost) || mediaExternalIp.equalsIgnoreCase(toHost))
                        || (myHostIp.equalsIgnoreCase(toHostIpAddress)
                                || mediaExternalIp.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;
                }
            } else {
                String msg = "Restcomm tried to proxy this call to an outbound party but it seems the outbound proxy is not configured.";
                sendNotification(errMsg, 11004, "warning", true);
            }
        }
    } else {
        // Client is null, check if this call is for a registered DID (application)
        if (redirectToHostedVoiceApp(self, request, accounts, applications, toUser)) {
            // This is a call to a registered DID (application)
            return;
        }
    }
    final SipServletResponse response = request.createResponse(SC_NOT_FOUND);
    response.send();
    // We didn't find anyway to handle the call.
    String errMsg = "Restcomm cannot process this call because the destination number " + toUser
            + "cannot be found or there is application attached to that";
    sendNotification(errMsg, 11005, "error", true);

}

From source file:org.mobicents.servlet.restcomm.telephony.CallManager.java

private void outboundToPstn(final CreateCall request, final ActorRef sender) throws ServletParseException {
    final String uri = activeProxy;
    SipURI outboundIntf = null;/*  w w w  .ja va 2s  . c o  m*/
    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.error(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.error(errMsg);
        sendNotification(errMsg, 11008, "error", true);
        sender.tell(new CallManagerResponse<ActorRef>(new NullPointerException(errMsg), this.createCallRequest),
                self());
    }
}

From source file:org.mobicents.servlet.restcomm.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();
    final ActorRef self = self();
    final boolean userAtDisplayedName = runtime.subset("outbound-proxy").getBoolean("user-at-displayed-name");
    InitializeOutbound init;//www  .j  ava 2 s.c o  m
    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.mobicents.servlet.restcomm.telephony.proxy.ProxyManagerProxy.java

@Override
public void servletInitialized(SipServletContextEvent event) {
    if (event.getSipServlet().getClass().equals(ProxyManagerProxy.class)) {
        if (logger.isInfoEnabled()) {
            logger.info("ProxyManagerProxy sip servlet initialized. Will proceed to create ProxyManager");
        }//from ww  w  .  j a v a 2 s  . c  o  m
        context = event.getServletContext();
        final SipFactory factory = (SipFactory) context.getAttribute(SIP_FACTORY);
        Configuration configuration = (Configuration) context.getAttribute(Configuration.class.getName());
        configuration = configuration.subset("runtime-settings");
        final String address = configuration.getString("external-ip");
        final DaoManager storage = (DaoManager) context.getAttribute(DaoManager.class.getName());
        system = (ActorSystem) context.getAttribute(ActorSystem.class.getName());
        manager = manager(context, factory, storage, address);
        context.setAttribute(ProxyManager.class.getName(), manager);
    }
}

From source file:org.mobicents.servlet.restcomm.telephony.ua.UserAgentManager.java

public UserAgentManager(final Configuration configuration, final SipFactory factory, final DaoManager storage,
        final ServletContext servletContext) {
    super();//from 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);
    getContext().setReceiveTimeout(Duration.create(pingInterval, TimeUnit.SECONDS));
    logger.info("About to run firstTimeCleanup()");
    firstTimeCleanup();
}

From source file:org.mobicents.servlet.restcomm.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 av a2  s. com*/
    final ActorRef source = self();

    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.mobicents.servlet.restcomm.ussd.telephony.UssdCallManager.java

/**
 * @param configuration/* w w  w .j av  a2s  . c o  m*/
 * @param context
 * @param system
 * @param gateway
 * @param conferences
 * @param sms
 * @param factory
 * @param storage
 */
public UssdCallManager(Configuration configuration, ServletContext context, ActorSystem system,
        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.mobicents.servlet.sip.restcomm.Bootstrapper.java

private static MgcpServerManager getMgcpServerManager(final Configuration configuration)
        throws ObjectInstantiationException {
    final MgcpServerManager mgcpServerManager = new MgcpServerManager();
    mgcpServerManager.configure(configuration.subset("media-server-manager"));
    mgcpServerManager.start();//  w  w w  . ja  va2  s .  co m
    return mgcpServerManager;
}

From source file:org.mobicents.servlet.sip.restcomm.Bootstrapper.java

private static SmsAggregator getSmsAggregator(final Configuration configuration)
        throws ObjectInstantiationException {
    final String classpath = configuration.getString("sms-aggregator[@class]");
    final SmsAggregator smsAggregator = (SmsAggregator) ObjectFactory.getInstance()
            .getObjectInstance(classpath);
    smsAggregator.configure(configuration.subset("sms-aggregator"));
    smsAggregator.start();//from   w w w  .ja  v a2 s.  com
    return smsAggregator;
}