Package play

Examples of play.Configuration


    return REDIRECT_URL;
  }

  protected UntappdAuthInfo getAccessToken(final String code,
      final Request request) throws AccessTokenException, ResolverMissingException {
    final Configuration c = getConfiguration();

    final String url = c.getString(SettingKeys.ACCESS_TOKEN_URL);

    final WSResponse r = WS
        .url(url)
        .setQueryParameter(Constants.CLIENT_ID,
            c.getString(SettingKeys.CLIENT_ID))
        .setQueryParameter(Constants.CLIENT_SECRET,
            c.getString(SettingKeys.CLIENT_SECRET))
        .setQueryParameter(Constants.RESPONSE_TYPE, Constants.CODE)
        .setQueryParameter(Constants.CODE, code)
        .setQueryParameter(getRedirectUriKey(), getRedirectUrl(request))
        // we use GET here
        .get().get(getTimeout());
View Full Code Here


    return URLEncodedUtils.format(params, "UTF-8");
  }

  private String getRequestToken(final Request request) throws AuthException {
    final Configuration c = getConfiguration();
    final List<NameValuePair> params = getRequestTokenParams(request, c);
    final WSResponse r = WS.url(c.getString(SettingKeys.REQUEST_TOKEN_URL))
        .setHeader("Content-Type", "application/json")
        .setHeader("X-Accept", "application/json")
        .post(encodeParamsAsJson(params)).get(getTimeout());

    if (r.getStatus() >= 400) {
View Full Code Here

    protected Mailer(final Configuration config) {
        plugin = play.Play.application().plugin(MailerPlugin.class);
        delay = Duration.create(config.getLong(SettingKeys.DELAY, 1L), TimeUnit.SECONDS);

        final Configuration fromConfig = config.getConfig(SettingKeys.FROM);
        sender = getEmailName(fromConfig.getString(SettingKeys.FROM_EMAIL),
                fromConfig.getString(SettingKeys.FROM_NAME));

        includeXMailerHeader = config.getBoolean(SettingKeys.INCLUDE_XMAILER_HEADER, true);
    }
View Full Code Here

        // @see http://nesbot.com/2011/11/28/play-2-morphia-logging-error
        MorphiaLoggerFactory.reset();
        MorphiaLoggerFactory.registerLogger(SLF4JLogrImplFactory.class);

        try {
            Configuration morphiaConf = Configuration.root().getConfig(ConfigKey.PREFIX);
            if (morphiaConf == null) {
                throw Configuration.root().reportError(ConfigKey.PREFIX, "Missing Morphia configuration", null);
            }

            MorphiaLogger.debug(morphiaConf);

            String mongoURIstr = morphiaConf.getString(ConfigKey.DB_MONGOURI.getKey());
            String seeds = morphiaConf.getString(ConfigKey.DB_SEEDS.getKey());

            String dbName = null;
            String username = null;
            String password = null;
           
            if(StringUtils.isNotBlank(mongoURIstr)) {
                MongoURI mongoURI = new MongoURI(mongoURIstr);
                mongo = connect(mongoURI);
                dbName = mongoURI.getDatabase();
                username = mongoURI.getUsername();
                if(mongoURI.getPassword() != null) {
                    password = new String(mongoURI.getPassword());   
                }
            } else if (StringUtils.isNotBlank(seeds)) {
                mongo = connect(seeds);
            } else {
                mongo = connect(
                        morphiaConf.getString(ConfigKey.DB_HOST.getKey()),
                        morphiaConf.getString(ConfigKey.DB_PORT.getKey()));
            }

            if (StringUtils.isBlank(dbName)) {
                dbName = morphiaConf.getString(ConfigKey.DB_NAME.getKey());
                if (StringUtils.isBlank(dbName)) {
                    throw morphiaConf.reportError(ConfigKey.DB_NAME.getKey(), "Missing Morphia configuration", null);
                }
            }

            morphia = new Morphia();
            // To prevent problem during hot-reload
            if (application.isDev()) {
                morphia.getMapper().getOptions().objectFactory = new PlayCreator();
            }
            // Configure validator
            new ValidationExtension(morphia);

            //Check if credentials parameters are present
            if (StringUtils.isBlank(username)) {
                username = morphiaConf.getString(ConfigKey.DB_USERNAME.getKey());
            }
            if (StringUtils.isBlank(password)) {
                password = morphiaConf.getString(ConfigKey.DB_PASSWORD.getKey());
            }

            if (StringUtils.isNotBlank(username) ^ StringUtils.isNotBlank(password)) {
                throw morphiaConf.reportError(ConfigKey.DB_NAME.getKey(), "Missing username or password", null);
            }

            // Create datastore
            if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)) {
                ds = morphia.createDatastore(mongo, dbName, username, password.toCharArray());
            } else {
                ds = morphia.createDatastore(mongo, dbName);
            }


            MorphiaLogger.debug("Datastore [%s] created", dbName);
            // Create GridFS
            String uploadCollection = morphiaConf.getString(ConfigKey.COLLECTION_UPLOADS.getKey());
            if (StringUtils.isBlank(dbName)) {
                uploadCollection = "uploads";
                MorphiaLogger.warn("Missing Morphia configuration key [%s]. Use default value instead [%s]", ConfigKey.COLLECTION_UPLOADS, "uploads");
            }
            gridfs = new GridFS(ds.getDB(), uploadCollection);
View Full Code Here

    }

  private void overrideSettings() {
    info ("Override settings...");
      //takes only the settings that begin with baasbox.settings
      Configuration bbSettingsToOverride=BBConfiguration.configuration.getConfig("baasbox.settings");
      //if there is at least one of them
      if (bbSettingsToOverride!=null) {
        //takes the part after the "baasbox.settings" of the key names
        Set<String> keys = bbSettingsToOverride.keys();
        Iterator<String> keysIt = keys.iterator();
        //for each setting to override
        while (keysIt.hasNext()){
          String key = keysIt.next();
          //is it a value to override?
          if (key.endsWith(".value")){
            //sets the overridden value
            String value = "";
            try {
               value = bbSettingsToOverride.getString(key);
              key = key.substring(0, key.lastIndexOf(".value"));
            PropertiesConfigurationHelper.override(key,value);
          } catch (Exception e) {
                        error ("Error overriding the setting " + key + " with the value " + value + ": " +e.getMessage());
          }
          }else if (key.endsWith(".visible")){ //or maybe we have to hide it when a REST API is called
            //sets the visibility
            Boolean value;
            try {
               value = bbSettingsToOverride.getBoolean(key);
              key = key.substring(0, key.lastIndexOf(".visible"));
            PropertiesConfigurationHelper.setVisible(key,value);
          } catch (Exception e) {
            error ("Error overriding the visible attribute for setting " + key + ": " +e.getMessage());
          }
          }else if (key.endsWith(".editable")){ //or maybe we have to
            //sets the possibility to edit the value via REST API by the admin
            Boolean value;
            try {
               value = bbSettingsToOverride.getBoolean(key);
              key = key.substring(0, key.lastIndexOf(".editable"));
            PropertiesConfigurationHelper.setEditable(key,value);
          } catch (Exception e) {
            error ("Error overriding the editable attribute setting " + key + ": " +e.getMessage());
          }
View Full Code Here

            return scheme;
        }
    }

    public static String getEmailFromSmtp() {
        Configuration config = Configuration.root();
        String user = config.getString("smtp.user");

        if (user == null) {
            return null;
        }

        if (user.contains("@")) {
            return user;
        } else {
            return user + "@" + config.getString("smtp.domain");
        }
    }
View Full Code Here

        return writeMail(errorMessage, sended);
    }

    public static Result writeMail(String errorMessage, boolean sended) {

        Configuration config = play.Play.application().configuration();
        List<String> notConfiguredItems = new ArrayList<>();
        String[] requiredItems = {"smtp.host", "smtp.user", "smtp.password"};
        for(String key : requiredItems) {
            if (config.getString(key) == null) {
                notConfiguredItems.add(key);
            }
        }

        String sender = utils.Config.getEmailFromSmtp();
View Full Code Here

        }
        return ok(lostPassword.render("site.resetPasswordEmail.title", emailAddress, errorMessage, isMailSent));
    }

    private static boolean sendPasswordResetMail(User user, String hashString) {
        Configuration config = play.Play.application().configuration();
        String sender = config.getString("smtp.user") + "@" + config.getString("smtp.domain");
        String resetPasswordUrl = getResetPasswordUrl(hashString);

        try {
            SimpleEmail email = new SimpleEmail();
            email.setFrom(sender)
View Full Code Here

            return false;
        }
    }

    private static String getResetPasswordUrl(String hashString) {
        Configuration config = play.Play.application().configuration();
        String hostname = config.getString("application.hostname");
        if(hostname == null) hostname = request().host();

        return "http://" + hostname + "/resetPassword?s=" + hashString;
    }
View Full Code Here

        }
        return User.anonymous;
    }

    private static boolean isUseSignUpConfirm(){
        Configuration config = play.Play.application().configuration();
        String useSignUpConfirm = config.getString("signup.require.confirm");
        return useSignUpConfirm != null && useSignUpConfirm.equals("true");
    }
View Full Code Here

TOP

Related Classes of play.Configuration

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.