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

org.ow2.petals.binding.rest.RESTBootstrap Maven / Gradle / Ivy

There is a newer version: 2.4.0
Show newest version
/**
 * Copyright (c) 2017-2020 Linagora
 * 
 * This program/library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 2.1 of the License, or (at your
 * option) any later version.
 * 
 * This program/library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program/library; If not, see http://www.gnu.org/licenses/
 * for the GNU Lesser General Public License version 2.1.
 */
package org.ow2.petals.binding.rest;

import java.util.Collection;

import javax.management.InvalidAttributeValueException;

import org.ow2.petals.component.framework.DefaultBootstrap;

/**
 * Bootstrap of the BC Rest supporting configuration parameters
 * 
 * @author Christophe DENEUX - Linagora
 *
 */
public class RESTBootstrap extends DefaultBootstrap {

    public static final String ATTR_NAME_HTTP_HOST = "httpHost";

    public static final String ATTR_NAME_HTTP_PORT = "httpPort";

    public static final String ATTR_NAME_CONNECTION_TIMEOUT = "connectionTimeout";

    public static final String ATTR_NAME_READ_TIMEOUT = "readTimeout";

    @Override
    public Collection getMBeanAttributesNames() {
        final Collection attributes = super.getMBeanAttributesNames();

        attributes.add(ATTR_NAME_HTTP_HOST);
        attributes.add(ATTR_NAME_HTTP_PORT);
        attributes.add(ATTR_NAME_CONNECTION_TIMEOUT);
        attributes.add(ATTR_NAME_READ_TIMEOUT);

        return attributes;
    }

    /**
     * Get the listening interface(s) of the embedded HTTP server.
     * 
     * @return the listening interface(s) of the embedded HTTP server
     */
    public String getHttpHost() {
        return this.getParamAsString(RESTConstants.ComponentParameter.HTTP_HOST,
                RESTConstants.HTTPServer.DEFAULT_HTTP_SERVER_HOSTNAME);
    }

    /**
     * Set the listening interface(s) of the embedded HTTP server.
     * 
     * @param httpHost
     *            the listening interface(s)
     * @throws InvalidAttributeValueException
     *             Invalid value given
     */
    public void setHttpHost(final String httpHost) throws InvalidAttributeValueException {
        this.setParam(RESTConstants.ComponentParameter.HTTP_HOST, httpHost);
    }

    /**
     * Get the TCP port of the embedded HTTP server.
     * 
     * @return the TCP port used by the embedded HTTP server
     */
    public int getHttpPort() {
        return this.getParamAsInteger(RESTConstants.ComponentParameter.HTTP_PORT,
                RESTConstants.HTTPServer.DEFAULT_HTTP_SERVER_PORT);
    }

    /**
     * Set the TCP port used by the embedded HTTP server.
     * 
     * @param httpPort
     *            the TCP port to use
     * @throws InvalidAttributeValueException
     *             Invalid value given
     */
    public void setHttpPort(final int httpPort) throws InvalidAttributeValueException {
        this.setParamAsPositiveInteger(RESTConstants.ComponentParameter.HTTP_PORT, httpPort);
    }

    /**
     * Get the connection timeout in milliseconds used for outgoing REST request.
     * 
     * @return the the connection timeout in milliseconds
     */
    public long getConnectionTimeout() {
        return this.getParamAsLong(RESTConstants.ComponentParameter.CONNECTION_TIMEOUT,
                RESTConstants.ComponentParameter.DEFAULT_CONNECTION_TIMEOUT);
    }

    /**
     * Set the connection timeout in milliseconds used for outgoing REST request.
     * 
     * @param connectionTimeout
     *            the connection timeout in milliseconds
     * @throws InvalidAttributeValueException
     *             Invalid value given
     */
    public void setConnectionTimeout(final long connectionTimeout) throws InvalidAttributeValueException {
        this.setParamAsPositiveLong(RESTConstants.ComponentParameter.CONNECTION_TIMEOUT, connectionTimeout);
    }

    /**
     * Get the read timeout in milliseconds used for outgoing REST request.
     * 
     * @return the the read timeout in milliseconds
     */
    public long getReadTimeout() {
        return this.getParamAsLong(RESTConstants.ComponentParameter.READ_TIMEOUT,
                RESTConstants.ComponentParameter.DEFAULT_READ_TIMEOUT);
    }

    /**
     * Set the read timeout in milliseconds used for outgoing REST request.
     * 
     * @param readTimeout
     *            the read timeout in milliseconds
     * @throws InvalidAttributeValueException
     *             Invalid value given
     */
    public void setReadTimeout(final long readTimeout) throws InvalidAttributeValueException {
        this.setParamAsPositiveLong(RESTConstants.ComponentParameter.READ_TIMEOUT, readTimeout);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy