Package org.structr.common

Examples of org.structr.common.StructrConf


    System.out.println("\n######################################################################################");
    System.out.println("# Starting " + getClass().getSimpleName() + "#" + getName());
    System.out.println("######################################################################################");

    final StructrConf config = Services.getBaseConfiguration();
    final Date now           = new Date();
    final long timestamp     = now.getTime();

    basePath = "/tmp/structr-test-" + timestamp;

    // enable "just testing" flag to avoid JAR resource scanning
    config.setProperty(Services.TESTING, "true");

    config.setProperty(Services.CONFIGURED_SERVICES, "NodeService LogService HttpService SchemaService");
    config.setProperty(Services.CONFIGURATION, JarConfigurationProvider.class.getName());
    config.setProperty(Services.TMP_PATH, "/tmp/");
    config.setProperty(Services.BASE_PATH, basePath);
    config.setProperty(Services.DATABASE_PATH, basePath + "/db");
    config.setProperty(Services.FILES_PATH, basePath + "/files");
    config.setProperty(Services.LOG_DATABASE_PATH, basePath + "/logDb.dat");
    config.setProperty(Services.TCP_PORT, "13465");
    config.setProperty(Services.UDP_PORT, "13466");
    config.setProperty(Services.SUPERUSER_USERNAME, "superadmin");
    config.setProperty(Services.SUPERUSER_PASSWORD, "sehrgeheim");

    config.setProperty(HttpService.APPLICATION_TITLE, "structr unit test app" + timestamp);
    config.setProperty(HttpService.APPLICATION_HOST, host);
    config.setProperty(HttpService.APPLICATION_HTTP_PORT, Integer.toString(httpPort));

    // configure JsonRestServlet
    config.setProperty(HttpService.SERVLETS, "JsonRestServlet");
    config.setProperty("JsonRestServlet.class", JsonRestServlet.class.getName());
    config.setProperty("JsonRestServlet.path", restUrl);
    config.setProperty("JsonRestServlet.resourceprovider", DefaultResourceProvider.class.getName());
    config.setProperty("JsonRestServlet.authenticator", SuperUserAuthenticator.class.getName());
    config.setProperty("JsonRestServlet.user.class", "");
    config.setProperty("JsonRestServlet.user.autocreate", "false");
    config.setProperty("JsonRestServlet.defaultview", PropertyView.Public);
    config.setProperty("JsonRestServlet.outputdepth", "3");

    final Services services = Services.getInstance(config);

    securityContext    = SecurityContext.getSuperUserInstance();
    app      = StructrApp.getInstance(securityContext);
View Full Code Here


  //~--- set methods ----------------------------------------------------

  @Override
  protected void setUp() throws Exception {

    final StructrConf config = Services.getBaseConfiguration();
    final Date now           = new Date();
    final long timestamp     = now.getTime();

    basePath = "/tmp/structr-test-" + timestamp;

    // enable "just testing" flag to avoid JAR resource scanning
    config.setProperty(Services.TESTING, "true");

    config.setProperty(Services.CONFIGURED_SERVICES, "NodeService LogService HttpService");
    config.setProperty(Services.CONFIGURATION, JarConfigurationProvider.class.getName());
    config.setProperty(Services.TMP_PATH, "/tmp/");
    config.setProperty(Services.BASE_PATH, basePath);
    config.setProperty(Services.DATABASE_PATH, basePath + "/db");
    config.setProperty(Services.FILES_PATH, basePath + "/files");
    config.setProperty(Services.LOG_DATABASE_PATH, basePath + "/logDb.dat");
    config.setProperty(Services.TCP_PORT, "13465");
    config.setProperty(Services.UDP_PORT, "13466");
    config.setProperty(Services.SUPERUSER_USERNAME, "superadmin");
    config.setProperty(Services.SUPERUSER_PASSWORD, "sehrgeheim");

    config.setProperty(HttpService.APPLICATION_TITLE, "structr unit test app" + timestamp);
    config.setProperty(HttpService.APPLICATION_HOST, host);
    config.setProperty(HttpService.APPLICATION_HTTP_PORT, Integer.toString(httpPort));

    // configure CsvServlet
    config.setProperty(HttpService.SERVLETS, "JsonRestServlet CsvServlet");
    config.setProperty("JsonRestServlet.class", JsonRestServlet.class.getName());
    config.setProperty("JsonRestServlet.path", restUrl);
    config.setProperty("JsonRestServlet.resourceprovider", DefaultResourceProvider.class.getName());
    config.setProperty("JsonRestServlet.authenticator", SuperUserAuthenticator.class.getName());
    config.setProperty("JsonRestServlet.user.class", "");
    config.setProperty("JsonRestServlet.user.autocreate", "false");
    config.setProperty("JsonRestServlet.defaultview", PropertyView.Public);
    config.setProperty("JsonRestServlet.outputdepth", "3");

    config.setProperty("CsvServlet.class", CsvServlet.class.getName());
    config.setProperty("CsvServlet.path", csvUrl);
    config.setProperty("CsvServlet.resourceprovider", DefaultResourceProvider.class.getName());
    config.setProperty("CsvServlet.authenticator", SuperUserAuthenticator.class.getName());
    config.setProperty("CsvServlet.user.class", "");
    config.setProperty("CsvServlet.user.autocreate", "false");
    config.setProperty("CsvServlet.defaultview", PropertyView.Public);
    config.setProperty("CsvServlet.outputdepth", "3");

    final Services services = Services.getInstance(config);

    securityContext    = SecurityContext.getSuperUserInstance();
    app      = StructrApp.getInstance(securityContext);
View Full Code Here

  }

  @Override
  public void initialize(final StructrConf additionalConfig) {

    final StructrConf finalConfig = new StructrConf();

    // Default configuration
    finalConfig.setProperty(APPLICATION_TITLE, "structr server");
    finalConfig.setProperty(APPLICATION_HOST, "0.0.0.0");
    finalConfig.setProperty(APPLICATION_HTTP_PORT, "8082");
    finalConfig.setProperty(APPLICATION_HTTPS_ENABLED, "false");
    finalConfig.setProperty(APPLICATION_HTTPS_PORT, "8083");
    finalConfig.setProperty(ASYNC, "false");
    finalConfig.setProperty(SERVLETS, "JsonRestServlet");

    finalConfig.setProperty("JsonRestServlet.class", JsonRestServlet.class.getName());
    finalConfig.setProperty("JsonRestServlet.path", "/structr/rest/*");
    finalConfig.setProperty("JsonRestServlet.resourceprovider", DefaultResourceProvider.class.getName());
    finalConfig.setProperty("JsonRestServlet.authenticator", SuperUserAuthenticator.class.getName());
    finalConfig.setProperty("JsonRestServlet.user.class", "org.structr.dynamic.User");
    finalConfig.setProperty("JsonRestServlet.user.autocreate", "false");
    finalConfig.setProperty("JsonRestServlet.defaultview", PropertyView.Public);
    finalConfig.setProperty("JsonRestServlet.outputdepth", "3");

    Services.mergeConfiguration(finalConfig, additionalConfig);

    String mainClassName = (String) finalConfig.get(MAIN_CLASS);

    Class mainClass = null;
    if (mainClassName != null) {

      logger.log(Level.INFO, "Running main class {0}", new Object[]{mainClassName});

      try {
        mainClass = Class.forName(mainClassName);
      } catch (ClassNotFoundException ex) {
        logger.log(Level.WARNING, "Did not find class for main class from config " + mainClassName, ex);
      }

    }

    String sourceJarName = (mainClass != null ? mainClass : getClass()).getProtectionDomain().getCodeSource().getLocation().toString();
    final boolean isTest = Boolean.parseBoolean(finalConfig.getProperty(Services.TESTING, "false"));

    if (!isTest && StringUtils.stripEnd(sourceJarName, System.getProperty("file.separator")).endsWith("classes")) {

      String jarFile = System.getProperty("jarFile");
      if (StringUtils.isEmpty(jarFile)) {
        throw new IllegalArgumentException(getClass().getName() + " was started in an environment where the classloader cannot determine the JAR file containing the main class.\n"
          + "Please specify the path to the JAR file in the parameter -DjarFile.\n"
          + "Example: -DjarFile=${project.build.directory}/${project.artifactId}-${project.version}.jar");
      }
      sourceJarName = jarFile;
    }

    // load configuration from properties file
    applicationName   = finalConfig.getProperty(APPLICATION_TITLE);
    host              = finalConfig.getProperty(APPLICATION_HOST);
    basePath          = finalConfig.getProperty(Services.BASE_PATH);
    httpPort          = parseInt(finalConfig.getProperty(APPLICATION_HTTP_PORT), 8082);
    maxIdleTime       = parseInt(System.getProperty("maxIdleTime"), 30000);
    requestHeaderSize = parseInt(System.getProperty("requestHeaderSize"), 8192);
    async             = parseBoolean(finalConfig.getProperty(ASYNC), false);

    if (async) {
      logger.log(Level.INFO, "Running in asynchronous mode");
    }

    // other properties
    String keyStorePath = finalConfig.getProperty(APPLICATION_KEYSTORE_PATH);
    String keyStorePassword = finalConfig.getProperty(APPLICATION_KEYSTORE_PASSWORD);
    String contextPath = System.getProperty("contextPath", "/");
    String logPrefix = "structr";
    boolean enableRewriteFilter = true; // configurationFile.getProperty(Services.
    boolean enableHttps = parseBoolean(finalConfig.getProperty(APPLICATION_HTTPS_ENABLED), false);
    boolean enableGzipCompression = true; //
    boolean logRequests = false; //
    int httpsPort = parseInt(finalConfig.getProperty(APPLICATION_HTTPS_PORT), 8083);

    // get current base path
    basePath = System.getProperty("home", basePath);
    if (basePath.isEmpty()) {

      // use cwd and, if that fails, /tmp as a fallback
      basePath = System.getProperty("user.dir", "/tmp");
    }

    // create base directory if it does not exist
    File baseDir = new File(basePath);
    if (!baseDir.exists()) {
      baseDir.mkdirs();
    }

    server = new Server(httpPort);
    ContextHandlerCollection contexts = new ContextHandlerCollection();

    contexts.addHandler(new DefaultHandler());

    final ServletContextHandler servletContext = new ServletContextHandler(server, contextPath, true, true);
    final List<Connector> connectors = new LinkedList<>();

    // create resource collection from base path & source JAR
    try {
      servletContext.setBaseResource(new ResourceCollection(Resource.newResource(basePath), JarResource.newJarResource(Resource.newResource(sourceJarName))));

    } catch (Throwable t) {

      logger.log(Level.WARNING, "Base resource {0} not usable: {1}", new Object[]{basePath, t.getMessage()});
    }

    // this is needed for the filters to work on the root context "/"
    servletContext.addServlet("org.eclipse.jetty.servlet.DefaultServlet", "/");
    servletContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");

    if (enableRewriteFilter) {

      FilterHolder rewriteFilter = new FilterHolder(UrlRewriteFilter.class);
      rewriteFilter.setInitParameter("confPath", "urlrewrite.xml");
      servletContext.addFilter(rewriteFilter, "/*", EnumSet.of(DispatcherType.REQUEST, async ? DispatcherType.ASYNC : DispatcherType.FORWARD));
    }

    if (enableGzipCompression) {

      FilterHolder gzipFilter = async ? new FilterHolder(AsyncGzipFilter.class) : new FilterHolder(GzipFilter.class);
      gzipFilter.setInitParameter("mimeTypes", "text/html,text/plain,text/css,text/javascript,application/json");
      gzipFilter.setInitParameter("bufferSize", "32768");
      gzipFilter.setInitParameter("minGzipSize", "256");
      gzipFilter.setInitParameter("deflateCompressionLevel", "9");
      gzipFilter.setInitParameter("methods", "GET,POST");
      servletContext.addFilter(gzipFilter, "/*", EnumSet.of(DispatcherType.REQUEST, async ? DispatcherType.ASYNC : DispatcherType.FORWARD));

    }

    contexts.addHandler(servletContext);

    // enable request logging
    if (logRequests || "true".equals(finalConfig.getProperty("log.requests", "false"))) {

      String etcPath = basePath + "/etc";
      File etcDir = new File(etcPath);

      if (!etcDir.exists()) {
View Full Code Here

  }

  @Override
  public void initialize(final StructrConf config) {

    final StructrConf finalConfig = new StructrConf();

    // Default config
    finalConfig.setProperty(NEO4J_BROWSER_PORT,      "7474");

    Services.mergeConfiguration(finalConfig, config);

    final String configuredPort = finalConfig.getProperty(NEO4J_BROWSER_PORT);
    host = finalConfig.getProperty(NEO4J_BROWSER_HOST);

    try {
      port = Integer.parseInt(configuredPort);

    } catch (Throwable t) {
View Full Code Here

  }

  @Override
  public void initialize(final StructrConf config) {

    final StructrConf finalConfig = new StructrConf();

    // Default config
    finalConfig.setProperty(APPLICATION_FTP_PORT,      "8022");

    Services.mergeConfiguration(finalConfig, config);

    final String configuredPort = finalConfig.getProperty(APPLICATION_FTP_PORT);

    try {
      port = Integer.parseInt(configuredPort);

    } catch (Throwable t) {
View Full Code Here

    return (command);
  }

  private void initialize() {

    final StructrConf config = getBaseConfiguration();

    // read structr.conf
    final String configTemplateFileName = "structr.conf_templ";
    final String configFileName         = "structr.conf";
    final File configTemplateFile       = new File(configTemplateFileName);
View Full Code Here

  public static StructrConf getBaseConfiguration() {

    if (baseConf == null) {

      baseConf = new StructrConf();

      baseConf.setProperty(CONFIGURATION,             JarConfigurationProvider.class.getName());
      baseConf.setProperty(CONFIGURED_SERVICES,       "NodeService AgentService CronService SchemaService");
      baseConf.setProperty(NEO4J_SHELL_ENABLED,       "true");
      baseConf.setProperty(NEO4J_SHELL_PORT,          "1337");
View Full Code Here

TOP

Related Classes of org.structr.common.StructrConf

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.