view artifact-database/src/main/java/de/intevation/artifactdatabase/rest/Standalone.java @ 77:48d1a9a082c2 0.5

Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>' to make the sources to be able to be formatted with jalopy (http://jalopy.sourceforge.net). artifacts/trunk@695 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 21 Feb 2010 23:05:32 +0000
parents 4ae4dc99127d
children 69c84cf7c5d7
line wrap: on
line source
package de.intevation.artifactdatabase.rest;

import org.restlet.Component;

import org.restlet.data.Protocol;

import de.intevation.artifacts.ArtifactDatabase;

import de.intevation.artifactdatabase.Config;

import de.intevation.artifactdatabase.rest.RestApp;

import org.apache.log4j.Logger;

/**
 * @author <a href="mailto:sascha.teichmann@intevation">Sascha L. Teichmann</a>
 */
public class Standalone
{
    private static Logger logger = Logger.getLogger(Standalone.class);

    public static final String REST_PORT =
        "/artifact-database/rest-server/port/text()";

    public static final String LISTEN_INTERFACE =
        "/artifact-database/rest-server/listen/text()";

    public static final int DEFAULT_PORT = 8181;

    public static void startAsServer(ArtifactDatabase db) {
        String portString   = Config.getStringXPath(REST_PORT);
        String listenString = Config.getStringXPath(LISTEN_INTERFACE);

        int port = DEFAULT_PORT;

        if (portString != null) {
            try {
                port = Integer.parseInt(portString);
                if (port < 0) {
                    throw new NumberFormatException();
                }
            }
            catch (NumberFormatException nfe) {
                logger.error("rest port is not a positive integer value.", nfe);
                return;
            }
        }

        RestApp app = new RestApp(db);

        Component component = new Component();

        if (listenString != null) {
            component.getServers().add(Protocol.HTTP, listenString, port);
        }
        else {
            component.getServers().add(Protocol.HTTP, port);
        }

        component.getDefaultHost().attach(app);

        logger.info("Starting rest HTTP server on "
            + (listenString != null ? listenString : "*")
            + ":" + port);

        try {
            component.start();
        }
        catch (Exception e) {
            logger.error(e.getLocalizedMessage(), e);
        }
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org