Java Code Examples for com.jeesuite.common.util.ResourceUtils#getProperty()

The following examples show how to use com.jeesuite.common.util.ResourceUtils#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: Swagger2.java    From oneplatform with Apache License 2.0 6 votes vote down vote up
@Bean
public Docket createRestApi(@Value("${swagger.enable:false}") boolean enable) {
	String basePackage = ResourceUtils.getProperty("controller.base-package","com.oneplatform");
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .enable(enable)
            .groupName("oneplatform")  
            .genericModelSubstitutes(DeferredResult.class)  
            .useDefaultResponseMessages(false)  
            //.globalResponseMessage(RequestMethod.GET,customerResponseMessage())  
            .forCodeGeneration(true)  
            .select()
            .apis(RequestHandlerSelectors.basePackage(basePackage))
            .paths(PathSelectors.any())
            .build();
}
 
Example 2
Source File: ServerEnvUtils.java    From jeesuite-config with Apache License 2.0 6 votes vote down vote up
public static String getServerIpAddr()  {  
	if(ResourceUtils.containsProperty("spring.cloud.client.ipAddress")){
		return ResourceUtils.getProperty("spring.cloud.client.ipAddress");
	}
	if(serverIpAddr != null)return serverIpAddr;
	try {
		Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();  
		outter:while (en.hasMoreElements()) {  
			NetworkInterface i = en.nextElement();  
			for (Enumeration<InetAddress> en2 = i.getInetAddresses(); en2.hasMoreElements();) {  
				InetAddress addr = en2.nextElement();  
				if (!addr.isLoopbackAddress()) {  
					if (addr instanceof Inet4Address) {    
						serverIpAddr = addr.getHostAddress();  
						break outter;
					}  
				}  
			}  
		}  
	} catch (Exception e) {
		serverIpAddr = UNKNOW;
	}
    return serverIpAddr;  
}
 
Example 3
Source File: ConsumerContext.java    From jeesuite-libs with Apache License 2.0 6 votes vote down vote up
public void propertiesSetIfAbsent(Properties configs, String groupId, String consumerId,
		Map<String, MessageHandler> messageHandlers, int maxProcessThreads,
		OffsetLogHanlder offsetLogHanlder,ErrorMessageProcessor errorMessageProcessor) {
	if(this.configs != null)return;
	this.configs = configs;
	this.groupId = groupId;
	this.consumerId = consumerId;
	this.messageHandlers = messageHandlers;
	this.maxProcessThreads = maxProcessThreads;
	this.offsetLogHanlder = offsetLogHanlder;
	this.errorMessageProcessor = errorMessageProcessor;
	
	String zkServers = ResourceUtils.getProperty("kafka.zkServers");
	if(StringUtils.isNotBlank(zkServers)){
       	zkClient = new ZkClient(zkServers, 10000, 5000, new ZKStringSerializer());
	}
}
 
Example 4
Source File: ScheduleAdminController.java    From oneplatform with Apache License 2.0 5 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
	if("zookeeper".equals(ResourceUtils.getProperty("jeesuite.task.registryType")) && 
			ResourceUtils.containsProperty("jeesuite.task.registryServers")){
		monitor = new SchedulerMonitor("zookeeper", ResourceUtils.getProperty("jeesuite.task.registryServers"));
	}else{
		monitor = new SchedulerMonitor(null, null);
	}
}
 
Example 5
Source File: ServerEnvUtils.java    From jeesuite-config with Apache License 2.0 5 votes vote down vote up
public static String getServerPort(){
	if(serverPort != null && !UNKNOW.equals(serverPort)){
		return serverPort;
	}
	serverPort = ResourceUtils.getProperty("server.port");
	if(StringUtils.isBlank(serverPort)){
		serverPort = ResourceUtils.getProperty("dubbo.port");
	}
	if(StringUtils.isBlank(serverPort)){
		serverPort = getTomcatServerPortByMBean();
	}
	
	return serverPort;
}
 
Example 6
Source File: SnowflakeGenerator.java    From jeesuite-libs with Apache License 2.0 5 votes vote down vote up
/**
 * 需要zookeeper保存节点信息
 */
public SnowflakeGenerator() {
	try {
		String appName = ResourceUtils.getProperty("spring.application.name", ResourceUtils.getProperty("jeesuite.configcenter.appName"));
		Validate.notBlank(appName, "config[spring.application.name] not found");
		String zkServer = ResourceUtils.getAndValidateProperty("zookeeper.servers");
		
		zk = new ZooKeeper(zkServer, 10000, this);
		String path = String.format(ROOT_PATH, appName);
		
		String[] parts = StringUtils.split(path, "/");
		String tmpParent = "";
		Stat stat;
		for (int i = 0; i < parts.length; i++) {
			tmpParent = tmpParent + "/" + parts[i];
			stat = zk.exists(tmpParent, false);
			if (stat == null) {
				zk.create(tmpParent, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
			}
		}
		String nodePath = path + "/" + NodeNameHolder.getNodeId();
		zk.create(nodePath, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
		int workerId = zk.getChildren(path, false).size();
		if (workerId > maxWorkerId || workerId < 0) {
			throw new IllegalArgumentException(
					String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
		}
		this.workerId = workerId;
	} catch (Exception e) {
		this.workerId = RandomUtils.nextInt(1, 31);
	}
	this.datacenterId = 1;
}
 
Example 7
Source File: KafkaProducerProperties.java    From jeesuite-libs with Apache License 2.0 5 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
	String kafkaServers = ResourceUtils.getProperty("kafka.bootstrap.servers");
	configs.put("bootstrap.servers", kafkaServers);
	Properties properties = ResourceUtils.getAllProperties("kafka.producer.");
	Iterator<Entry<Object, Object>> iterator = properties.entrySet().iterator();
	while(iterator.hasNext()){
		Entry<Object, Object> entry = iterator.next();
		configs.put(entry.getKey().toString().replace("kafka.producer.", ""), entry.getValue());
	}
}
 
Example 8
Source File: KafkaConsumerProperties.java    From jeesuite-libs with Apache License 2.0 5 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
	String kafkaServers = ResourceUtils.getProperty("kafka.bootstrap.servers");
	String zkServers = ResourceUtils.getProperty("kafka.zkServers");
	configs.put("bootstrap.servers", kafkaServers);
	if(useNewAPI == false && zkServers != null){
		configs.put("zookeeper.connect", zkServers);
	}
	Properties properties = ResourceUtils.getAllProperties("kafka.consumer.");
	Iterator<Entry<Object, Object>> iterator = properties.entrySet().iterator();
	while(iterator.hasNext()){
		Entry<Object, Object> entry = iterator.next();
		configs.put(entry.getKey().toString().replace("kafka.consumer.", ""), entry.getValue());
	}
}
 
Example 9
Source File: KafkaAdminController.java    From oneplatform with Apache License 2.0 4 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
	if(ResourceUtils.containsProperty("zookeeper.servers") && ResourceUtils.containsProperty("kafka.bootstrap.servers")){
		 monitor = new KafkaMonitor(ResourceUtils.getProperty("zookeeper.servers"), ResourceUtils.getProperty("kafka.bootstrap.servers"), 1000);
	}
}
 
Example 10
Source File: OnePlatformSecurityDecisionProvider.java    From oneplatform with Apache License 2.0 4 votes vote down vote up
@Override
public String contextPath() {
	return ResourceUtils.getProperty("server.servlet.context-path", "");
}
 
Example 11
Source File: TopicProducerSpringProvider.java    From jeesuite-libs with Apache License 2.0 4 votes vote down vote up
@Override
  public void afterPropertiesSet() throws Exception {

      Validate.notEmpty(this.configs, "configs is required");
      
      routeEnv = StringUtils.trimToNull(ResourceUtils.getProperty(KafkaConst.PROP_ENV_ROUTE));
      
      if(routeEnv != null)log.info("current route Env value is:",routeEnv);
    //移除错误的或者未定义变量的配置
      Set<String> propertyNames = configs.stringPropertyNames();
      for (String propertyName : propertyNames) {
	String value = configs.getProperty(propertyName);
	if(StringUtils.isBlank(value) || value.trim().startsWith("$")){
		configs.remove(propertyName);
		log.warn("remove prop[{}],value is:{}",propertyName,value);
	}
}
      
      if(!configs.containsKey(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG)){
      	configs.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName()); // key serializer
      }
      
      if(!configs.containsKey(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG)){
      	configs.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, KyroMessageSerializer.class.getName());
      }
      
      if(!configs.containsKey(ProducerConfig.PARTITIONER_CLASS_CONFIG)){
      	configs.put(ProducerConfig.PARTITIONER_CLASS_CONFIG, DefaultPartitioner.class.getName()); 
      }
      
      //默认重试一次
      if(!configs.containsKey(ProducerConfig.RETRIES_CONFIG)){
      	configs.put(ProducerConfig.RETRIES_CONFIG, "1"); 
      }
      
      if(!configs.containsKey(ProducerConfig.COMPRESSION_TYPE_CONFIG)){
      	configs.put(ProducerConfig.COMPRESSION_TYPE_CONFIG, "snappy"); 
      }
      
      if(!configs.containsKey("client.id")){
	configs.put("client.id", (producerGroup == null ? "" : "_"+producerGroup) + NodeNameHolder.getNodeId());
}

      KafkaProducer<String, Object> kafkaProducer = new KafkaProducer<String, Object>(configs);

      String monitorZkServers = ResourceUtils.getProperty("kafka.zkServers");
      if(StringUtils.isNotBlank(monitorZkServers)){
      	zkClient = new ZkClient(monitorZkServers, 10000, 5000, new ZKStringSerializer());
      }
      this.producer = new DefaultTopicProducer(kafkaProducer,zkClient,consumerAckEnabled);

      //hanlder
      if(monitorEnabled){    
	Validate.notBlank(producerGroup,"enable producer monitor property[producerGroup] is required");
	Validate.notNull(zkClient, "enable producer monitor property[kafka.zkServers] is required");
	
	this.producer.addEventHandler(new SendCounterHandler(producerGroup,zkClient));
}
      if(delayRetries > 0){
      	this.producer.addEventHandler(new SendErrorDelayRetryHandler(producerGroup,kafkaProducer, delayRetries));
      }
  }
 
Example 12
Source File: LogConfigLookup.java    From jeesuite-libs with Apache License 2.0 4 votes vote down vote up
@Override
public String lookup(LogEvent event, String key) {
	return ResourceUtils.getProperty(key);
}
 
Example 13
Source File: FilterConfig.java    From jeesuite-libs with Apache License 2.0 4 votes vote down vote up
public static String getCorsAllowOrgin(){
	return ResourceUtils.getProperty("cors.allow.origin", "*");
}
 
Example 14
Source File: ConfigcenterContext.java    From jeesuite-config with Apache License 2.0 3 votes vote down vote up
public synchronized void init(Properties properties,boolean isSpringboot) {
	if(processed || !isRemoteEnabled())return;
	ResourceUtils.merge(properties);
	
	System.setProperty("client.nodeId", nodeId);
	System.setProperty("springboot", String.valueOf(isSpringboot));
	this.isSpringboot = isSpringboot;
	String defaultAppName = ResourceUtils.getProperty("spring.application.name");
	app = ResourceUtils.getProperty("jeesuite.configcenter.appName",defaultAppName);
	if(remoteEnabled == null)remoteEnabled = ResourceUtils.getBoolean("jeesuite.configcenter.enabled",true);
	
	if(!isRemoteEnabled())return;
	
	env = ResourceUtils.getProperty("jeesuite.configcenter.profile","dev");
	
	Validate.notBlank(env,"[jeesuite.configcenter.profile] is required");
	
	setApiBaseUrl(ResourceUtils.getProperty("jeesuite.configcenter.base.url"));
	
	version = ResourceUtils.getProperty("jeesuite.configcenter.version","0.0.0");
	
	syncIntervalSeconds = ResourceUtils.getInt("jeesuite.configcenter.sync-interval-seconds", 30);
	
	tokenCryptKey = ResourceUtils.getProperty("jeesuite.configcenter.cryptKey");
	
	System.out.println(String.format("\n=====Configcenter config=====\nappName:%s\nenv:%s\nversion:%s\nremoteEnabled:%s\napiBaseUrls:%s\n=====Configcenter config=====", app,env,version,isRemoteEnabled(),JsonUtils.toJson(apiBaseUrls)));
	
}