Java Code Examples for com.ctrip.framework.apollo.Config#getProperty()

The following examples show how to use com.ctrip.framework.apollo.Config#getProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ItemController.java    From mini-platform with MIT License 5 votes vote down vote up
/**
 * 测试高可用
 * @param request
 * @return
 */
@GetMapping("url")
public String get(HttpServletRequest request) {
    //config instance is singleton for each namespace and is never null
    Config config = ConfigService.getAppConfig();
    String someKey = "timeout";
    String someDefaultValue = "100";
    String value = config.getProperty(someKey, someDefaultValue);

    return ">>>>>" + "Host:" + request.getRemoteHost() + "  Port: 【" + request.getServerPort()
            + "】 Path:" + request.getRequestURI()
            + " Timeout: " + value;
}
 
Example 2
Source File: UserController.java    From mini-platform with MIT License 5 votes vote down vote up
/**
 * @param request
 * @return
 */
@GetMapping("/demo")
public String demo(HttpServletRequest request) {

    //Apollo配置中心示例
    //config instance is singleton for each namespace and is never null
    Config config = ConfigService.getAppConfig();
    String timeoutKey = "timeout";
    String timeoutDefaultValue = "100";
    String value = config.getProperty(timeoutKey, timeoutDefaultValue);

    //OAuth Client示例
    Boolean isLogin = isLogin();
    Long loginUserId = getUserId();
    UserInfo userInfo = getUserInfo();

    //高可用测试
    String path = request.getRemoteHost() + ":" + request.getServerPort();

    return " Path:" + path + System.getProperty("line.separator", "\n")
            + " Timeout: " + value + System.getProperty("line.separator", "\n")
            + " is login: " + isLogin + System.getProperty("line.separator", "\n")
            + " userId: " + loginUserId + System.getProperty("line.separator", "\n")
            + " userName: " + (userInfo == null ? "Null" : userInfo.getUserName()) + System.getProperty("line.separator", "\n")
            + " clientId: " + (userInfo == null ? "Null" : userInfo.getClientId()) + System.getProperty("line.separator", "\n")
            ;
}
 
Example 3
Source File: ApolloConfigManager.java    From jboot with Apache License 2.0 5 votes vote down vote up
public void init(JbootConfigManager configManager) {

        ApolloServerConfig apolloServerConfig = configManager.get(ApolloServerConfig.class);
        if (!apolloServerConfig.isEnable() || !apolloServerConfig.isConfigOk()){
            return;
        }

        Config config = getDefaultConfig();

        Set<String> propNames = config.getPropertyNames();
        if (propNames != null && !propNames.isEmpty()) {
            for (String name : propNames) {
                String value = config.getProperty(name, null);
                configManager.setRemoteProperty(name, value);
            }
        }

        config.addChangeListener(changeEvent -> {
            for (String key : changeEvent.changedKeys()) {
                ConfigChange change = changeEvent.getChange(key);
                configManager.setRemoteProperty(change.getPropertyName(), change.getNewValue());
            }

            configManager.notifyChangeListeners(changeEvent.changedKeys());
        });

    }
 
Example 4
Source File: PasswordPBKDF2.java    From mini-platform with MIT License 4 votes vote down vote up
protected PasswordPBKDF2() {
    Config config = ConfigService.getAppConfig();
    this.algorithm = config.getProperty("oauth.user.password.pbkdf2.algorithm", "PBKDF2WithHmacSHA1");
    this.keyLength = config.getIntProperty("oauth.user.password.pbkdf2.keyLength", 128);
    this.iterationCount = config.getIntProperty("oauth.user.password.pbkdf2.iterationCount", 1024);
}
 
Example 5
Source File: PasswordMD5.java    From mini-platform with MIT License 4 votes vote down vote up
protected PasswordMD5() {
    Config config = ConfigService.getAppConfig();
    this.algorithm = config.getProperty("oauth.user.password.md5.algorithm", "MD5");
}