Java Code Examples for org.apache.commons.lang.BooleanUtils#toBooleanDefaultIfNull()

The following examples show how to use org.apache.commons.lang.BooleanUtils#toBooleanDefaultIfNull() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RabbitMQListener.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public RabbitMQListener(InboundProcessorParams params) {
    this.name = params.getName();
    this.injectingSeq = params.getInjectingSeq();
    this.onErrorSeq = params.getOnErrorSeq();
    this.synapseEnvironment = params.getSynapseEnvironment();
    this.rabbitmqProperties = params.getProperties();

    this.sequential = BooleanUtils.toBooleanDefaultIfNull(BooleanUtils.toBooleanObject(
            rabbitmqProperties.getProperty(PollingConstants.INBOUND_ENDPOINT_SEQUENTIAL)), true);

    this.coordination = BooleanUtils.toBooleanDefaultIfNull(BooleanUtils.toBooleanObject(
            rabbitmqProperties.getProperty(PollingConstants.INBOUND_COORDINATION)), true);

    try {
        rabbitMQConnectionFactory = new RabbitMQConnectionFactory(rabbitmqProperties);
    } catch (RabbitMQException e) {
        throw new SynapseException("Error occurred while initializing the connection factory.", e);
    }

    injectHandler = new RabbitMQInjectHandler(injectingSeq, onErrorSeq, sequential, synapseEnvironment);
}
 
Example 2
Source File: RabbitMQConsumer.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Register a consumer to the queue
 *
 * @throws IOException
 */
private void initConsumer() throws IOException, RabbitMQException {
    if (connection == null) {
        connection = rabbitMQConnectionFactory.createConnection();
    }

    channel = connection.createChannel();
    ((Recoverable) this.channel).addRecoveryListener(new RabbitMQRecoveryListener());

    // set the qos value
    int qos = NumberUtils.toInt(rabbitMQProperties.get(RabbitMQConstants.CONSUMER_QOS),
            RabbitMQConstants.DEFAULT_CONSUMER_QOS);
    channel.basicQos(qos);

    // declaring queue, exchange and binding
    queueName = rabbitMQProperties.get(RabbitMQConstants.QUEUE_NAME);
    String exchangeName = rabbitMQProperties.get(RabbitMQConstants.EXCHANGE_NAME);
    RabbitMQUtils.declareQueuesExchangesAndBindings(channel, queueName, exchangeName, rabbitMQProperties);

    // get max dead-lettered count
    maxDeadLetteredCount =
            NumberUtils.toLong(rabbitMQProperties.get(RabbitMQConstants.MESSAGE_MAX_DEAD_LETTERED_COUNT));

    // get consumer tag if given
    String consumerTag = rabbitMQProperties.get(RabbitMQConstants.CONSUMER_TAG);

    autoAck = BooleanUtils.toBooleanDefaultIfNull(BooleanUtils.toBooleanObject(rabbitMQProperties
            .get(RabbitMQConstants.QUEUE_AUTO_ACK)), true);

    if (StringUtils.isNotEmpty(consumerTag)) {
        channel.basicConsume(queueName, autoAck, consumerTag, this);
    } else {
        channel.basicConsume(queueName, autoAck, this);
    }
}
 
Example 3
Source File: DocumentSearchCriteriaBoLookupableHelperService.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Returns true if the document handler should open in a new window.
 */
protected boolean isDocumentHandlerPopup() {
  return BooleanUtils.toBooleanDefaultIfNull(
            CoreFrameworkServiceLocator.getParameterService().getParameterValueAsBoolean(
                KewApiConstants.KEW_NAMESPACE,
                KRADConstants.DetailTypes.DOCUMENT_SEARCH_DETAIL_TYPE,
                KewApiConstants.DOCUMENT_SEARCH_DOCUMENT_POPUP_IND),
            DOCUMENT_HANDLER_POPUP_DEFAULT);
}
 
Example 4
Source File: DocumentSearchCriteriaBoLookupableHelperService.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Returns true if the route log should open in a new window.
 */
public boolean isRouteLogPopup() {
    return BooleanUtils.toBooleanDefaultIfNull(
            CoreFrameworkServiceLocator.getParameterService().getParameterValueAsBoolean(KewApiConstants.KEW_NAMESPACE,
                    KRADConstants.DetailTypes.DOCUMENT_SEARCH_DETAIL_TYPE,
                    KewApiConstants.DOCUMENT_SEARCH_ROUTE_LOG_POPUP_IND), ROUTE_LOG_POPUP_DEFAULT);
}
 
Example 5
Source File: RestartAction.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public ActionForward execute(ActionMapping mapping,
                             ActionForm formIn,
                             HttpServletRequest request,
                             HttpServletResponse response) {

    DynaActionForm form = (DynaActionForm) formIn;
    RequestContext ctx = new RequestContext(request);

    if (isSubmitted(form)) {
        Boolean restart = ((Boolean) form.get(RESTART));
        if (BooleanUtils.toBooleanDefaultIfNull(restart, false)) {
            RestartSatelliteEvent event = new
                RestartSatelliteEvent(ctx.getCurrentUser());
            MessageQueue.publish(event);
            createSuccessMessage(request, "restart.config.success",
                                String.valueOf(RESTART_DELAY_IN_MINUTES));
            request.setAttribute(RESTART, Boolean.TRUE);
            request.setAttribute(RESTART_DELAY_LABEL,
                                String.valueOf(RESTART_DELAY_IN_MINUTES * 60));
        }
        else {
            addMessage(request, "restart.config.norestart");
            request.setAttribute(RESTART, Boolean.FALSE);
        }
    }
    else {
        if (request.getParameter(RESTARTED) != null &&
            request.getParameter(RESTARTED).equals("true")) {
            addMessage(request, "restart.config.restarted");
        }

        form.set(RESTART, Boolean.FALSE);
        request.setAttribute(RESTART, Boolean.FALSE);
    }

    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
}
 
Example 6
Source File: RabbitMQConnectionFactory.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
/**
 * Initiate rabbitmq connection factory from the connection parameters
 *
 * @param parameters connection parameters
 */
private void initConnectionFactory(Map<String, String> parameters) throws RabbitMQException {
    String hostnames = StringUtils.defaultIfEmpty(
            parameters.get(RabbitMQConstants.SERVER_HOST_NAME), ConnectionFactory.DEFAULT_HOST);
    String ports = StringUtils.defaultIfEmpty(
            parameters.get(RabbitMQConstants.SERVER_PORT), String.valueOf(ConnectionFactory.DEFAULT_AMQP_PORT));
    String username = StringUtils.defaultIfEmpty(
            parameters.get(RabbitMQConstants.SERVER_USER_NAME), ConnectionFactory.DEFAULT_USER);
    String password = StringUtils.defaultIfEmpty(
            parameters.get(RabbitMQConstants.SERVER_PASSWORD), ConnectionFactory.DEFAULT_PASS);
    String virtualHost = StringUtils.defaultIfEmpty(
            parameters.get(RabbitMQConstants.SERVER_VIRTUAL_HOST), ConnectionFactory.DEFAULT_VHOST);
    int heartbeat = NumberUtils.toInt(
            parameters.get(RabbitMQConstants.HEARTBEAT), ConnectionFactory.DEFAULT_HEARTBEAT);
    int connectionTimeout = NumberUtils.toInt(
            parameters.get(RabbitMQConstants.CONNECTION_TIMEOUT), ConnectionFactory.DEFAULT_CONNECTION_TIMEOUT);
    long networkRecoveryInterval = NumberUtils.toLong(
            parameters.get(RabbitMQConstants.NETWORK_RECOVERY_INTERVAL), ConnectionFactory.DEFAULT_NETWORK_RECOVERY_INTERVAL);
    this.retryInterval = NumberUtils.toInt(
            parameters.get(RabbitMQConstants.RETRY_INTERVAL), RabbitMQConstants.DEFAULT_RETRY_INTERVAL);
    this.retryCount = NumberUtils.toInt(
            parameters.get(RabbitMQConstants.RETRY_COUNT), RabbitMQConstants.DEFAULT_RETRY_COUNT);
    boolean sslEnabled = BooleanUtils.toBooleanDefaultIfNull(
            BooleanUtils.toBoolean(parameters.get(RabbitMQConstants.SSL_ENABLED)), false);

    String[] hostnameArray = hostnames.split(",");
    String[] portArray = ports.split(",");
    if (hostnameArray.length == portArray.length) {
        addresses = new Address[hostnameArray.length];
        for (int i = 0; i < hostnameArray.length; i++) {
            try {
                addresses[i] = new Address(hostnameArray[i].trim(), Integer.parseInt(portArray[i].trim()));
            } catch (NumberFormatException e) {
                throw new RabbitMQException("Number format error in port number", e);
            }
        }
    } else {
        throw new RabbitMQException("The number of hostnames must be equal to the number of ports");
    }

    connectionFactory = new ConnectionFactory();
    connectionFactory.setUsername(username);
    connectionFactory.setPassword(password);
    connectionFactory.setVirtualHost(virtualHost);
    connectionFactory.setRequestedHeartbeat(heartbeat);
    connectionFactory.setConnectionTimeout(connectionTimeout);
    connectionFactory.setNetworkRecoveryInterval(networkRecoveryInterval);
    connectionFactory.setAutomaticRecoveryEnabled(true);
    connectionFactory.setTopologyRecoveryEnabled(true);
    setSSL(parameters, sslEnabled);
}
 
Example 7
Source File: ConfigureBootstrapCommand.java    From spacewalk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ValidatorError[] storeConfiguration() {
    Executor e = getExecutor();
    ValidatorError[] errors = new ValidatorError[1];
    String errorKey = "bootstrap.config.error.";

    List args = new LinkedList();
    args.add("/usr/bin/sudo");
    args.add("/usr/bin/rhn-bootstrap");
    if (BooleanUtils.toBooleanDefaultIfNull(this.allowConfigActions, false)) {
        args.add("--allow-config-actions");
    }
    if (BooleanUtils.toBooleanDefaultIfNull(this.allowRemoteCommands, false)) {
        args.add("--allow-remote-commands");
    }
    if (!BooleanUtils.toBooleanDefaultIfNull(this.enableSsl, false)) {
        args.add("--no-ssl");
    }
    if (!BooleanUtils.toBooleanDefaultIfNull(this.enableGpg, false)) {
        args.add("--no-gpg");
    }

    if (!StringUtils.isEmpty(this.hostname)) {
        args.add("--hostname=" + this.hostname);
    }
    if (!StringUtils.isEmpty(this.sslPath)) {
        args.add("--ssl-cert=" + this.sslPath);
    }
    if (!StringUtils.isEmpty(this.httpProxy)) {
        args.add("--http-proxy=" + this.httpProxy);
    }
    if (!StringUtils.isEmpty(this.httpProxyUsername)) {
        args.add("--http-proxy-username=" + this.httpProxyUsername);
    }
    if (!StringUtils.isEmpty(this.httpProxyPassword)) {
        args.add("--http-proxy-password=" + this.httpProxyPassword);
    }

    int exitcode = e.execute((String[]) args.toArray(new String[0]));
    if (exitcode != 0) {
        errorKey = errorKey + exitcode;
        if (!LocalizationService.getInstance().hasMessage(errorKey)) {
            errorKey = "bootstrap.config.error.127";
        }
        errors[0] = new ValidatorError(errorKey);
        return errors;
    }
    return null;

}