<commit_before>/*
 Created as part of the StratusLab project (http://stratuslab.eu),
 co-funded by the European Commission under the Grant Agreement
 INSFO-RI-261552.

 Copyright (c) 2011, Centre National de la Recherche Scientifique (CNRS)

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */
package eu.stratuslab.storage.disk.main;

import java.util.Map;

import org.restlet.Application;
import org.restlet.Component;
import org.restlet.Context;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.Restlet;
import org.restlet.data.ChallengeScheme;
import org.restlet.data.LocalReference;
import org.restlet.data.Protocol;
import org.restlet.ext.freemarker.ContextTemplateLoader;
import org.restlet.resource.Directory;
import org.restlet.routing.Router;
import org.restlet.security.ChallengeAuthenticator;

import eu.stratuslab.storage.disk.resources.DiskResource;
import eu.stratuslab.storage.disk.resources.DisksResource;
import eu.stratuslab.storage.disk.resources.HomeResource;
import eu.stratuslab.storage.disk.resources.MountResource;
import eu.stratuslab.storage.disk.resources.MountsResource;
import eu.stratuslab.storage.disk.utils.DumpVerifier;
import freemarker.template.Configuration;

public class RootApplication extends Application {

    public static final String SVC_CONFIGURATION_KEY = "PDISK_SVC_CONFIG";
    public static final String FM_CONFIGURATION_KEY = "PDISK_FM_CONFIG";

    public static final ServiceConfiguration CONFIGURATION = ServiceConfiguration
            .getInstance();

    private Configuration freeMarkerConfiguration = null;

	public static void main(String[] args) throws Exception {

		Component component = new Component();

		component.getServers().add(Protocol.HTTP, 8182);
		component.getServers().add(Protocol.FILE);
		component.getClients().add(Protocol.FILE);
		component.getClients().add(Protocol.CLAP);
		Application rootApplication = new RootApplication();
		component.getDefaultHost().attach("", rootApplication);

		try {
			component.start();
		} catch (Exception e) {
			e.printStackTrace();
			System.err.println("\nStarting StratusLab Storage Server FAILED!\n");
			System.exit(1);
		}
		System.out.println("\nStratusLab Storage Server started!\n");
	}
    
    
    public RootApplication() {
        setName("StratusLab Persistent Disk Server");
        setDescription("StratusLab server for persistent disk storage.");
        setOwner("StratusLab");
        setAuthor("<NAME>");

        setStatusService(new CommonStatusService());

        getTunnelService().setUserAgentTunnel(true);
    }

    @Override
    public Restlet createInboundRoot() {
        Context context = getContext();

        freeMarkerConfiguration = createFreeMarkerConfig(context);

        ServiceConfiguration configuration = ServiceConfiguration.getInstance();
        Router router = new RootRouter(context, configuration,
                freeMarkerConfiguration);

        router.attach("/disks/{uuid}/mounts/{mountid}/", MountResource.class);
        router.attach("/disks/{uuid}/mounts/{mountid}", MountResource.class);

        router.attach("/disks/{uuid}/mounts/", MountsResource.class);
        router.attach("/disks/{uuid}/mounts", MountsResource.class);

        router.attach("/disks/{uuid}/", DiskResource.class);
        router.attach("/disks/{uuid}", DiskResource.class);

        router.attach("/disks/", DisksResource.class);
        router.attach("/disks", DisksResource.class);

        router.attach("/", HomeResource.class);

        router.attach("/css/", createCssDirectory(context));

        return createGuard(context, router);
    }

    private static Directory createCssDirectory(Context context) {
        Directory cssDir = new Directory(context, "war:///css");
        cssDir.setNegotiatingContent(false);
        cssDir.setIndexName("index.html");

        return cssDir;
    }

    //
    // This guard is needed although JAAS is doing all of the
    // authentication. This allows the authentication information
    // to be retrieved from the request through the challenge
    // request.
    //<commit_msg>Added sys prop for static content location<commit_after>/*
 Created as part of the StratusLab project (http://stratuslab.eu),
 co-funded by the European Commission under the Grant Agreement
 INSFO-RI-261552.

 Copyright (c) 2011, Centre National de la Recherche Scientifique (CNRS)

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */
package eu.stratuslab.storage.disk.main;

import java.util.Map;

import org.restlet.Application;
import org.restlet.Component;
import org.restlet.Context;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.Restlet;
import org.restlet.data.ChallengeScheme;
import org.restlet.data.LocalReference;
import org.restlet.data.Protocol;
import org.restlet.ext.freemarker.ContextTemplateLoader;
import org.restlet.resource.Directory;
import org.restlet.routing.Router;
import org.restlet.security.ChallengeAuthenticator;

import eu.stratuslab.storage.disk.resources.DiskResource;
import eu.stratuslab.storage.disk.resources.DisksResource;
import eu.stratuslab.storage.disk.resources.HomeResource;
import eu.stratuslab.storage.disk.resources.MountResource;
import eu.stratuslab.storage.disk.resources.MountsResource;
import eu.stratuslab.storage.disk.utils.DumpVerifier;
import freemarker.template.Configuration;

public class RootApplication extends Application {

    public static final String SVC_CONFIGURATION_KEY = "PDISK_SVC_CONFIG";
    public static final String FM_CONFIGURATION_KEY = "PDISK_FM_CONFIG";

    public static final ServiceConfiguration CONFIGURATION = ServiceConfiguration
            .getInstance();

    private Configuration freeMarkerConfiguration = null;

	public static void main(String[] args) throws Exception {

		Component component = new Component();

		component.getServers().add(Protocol.HTTP, 8182);
		component.getServers().add(Protocol.FILE);
		component.getClients().add(Protocol.FILE);
		component.getClients().add(Protocol.CLAP);
		Application rootApplication = new RootApplication();
		component.getDefaultHost().attach("", rootApplication);

		try {
			component.start();
		} catch (Exception e) {
			e.printStackTrace();
			System.err.println("\nStarting StratusLab Storage Server FAILED!\n");
			System.exit(1);
		}
		System.out.println("\nStratusLab Storage Server started!\n");
	}
    
    
    public RootApplication() {
        setName("StratusLab Persistent Disk Server");
        setDescription("StratusLab server for persistent disk storage.");
        setOwner("StratusLab");
        setAuthor("<NAME>");

        setStatusService(new CommonStatusService());

        getTunnelService().setUserAgentTunnel(true);
    }

    @Override
    public Restlet createInboundRoot() {
        Context context = getContext();

        freeMarkerConfiguration = createFreeMarkerConfig(context);

        ServiceConfiguration configuration = ServiceConfiguration.getInstance();
        Router router = new RootRouter(context, configuration,
                freeMarkerConfiguration);

        router.attach("/disks/{uuid}/mounts/{mountid}/", MountResource.class);
        router.attach("/disks/{uuid}/mounts/{mountid}", MountResource.class);

        router.attach("/disks/{uuid}/mounts/", MountsResource.class);
        router.attach("/disks/{uuid}/mounts", MountsResource.class);

        router.attach("/disks/{uuid}/", DiskResource.class);
        router.attach("/disks/{uuid}", DiskResource.class);

        router.attach("/disks/", DisksResource.class);
        router.attach("/disks", DisksResource.class);

        router.attach("/", HomeResource.class);

        router.attach("/css/", createCssDirectory(context));

        return createGuard(context, router);
    }

    private static Directory createCssDirectory(Context context) {
		String cssLocation = System.getProperty(
				"css.content.location", "war:///css");
        Directory cssDir = new Directory(context, cssLocation);
        cssDir.setNegotiatingContent(false);
        cssDir.setIndexName("index.html");

        return cssDir;
    }

    //
    // This guard is needed although JAAS is doing all of the
    // authentication. This allows the authentication information
    // to be retrieved from the request through the challenge
    // request.
    //
{'fraction_non_alphanumeric': 0.10496881049688105, 'fraction_numerical': 0.004086900408690041, 'mean_word_length': 3.994092373791622, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3113646', 'n_tokens_mistral': 2579, 'n_tokens_neox': 2423, 'n_words': 643}