Java Code Examples for com.frameworkset.util.SimpleStringUtil#isEmpty()

The following examples show how to use com.frameworkset.util.SimpleStringUtil#isEmpty() . 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: WrapperGetProperties.java    From bboss-elasticsearch with Apache License 2.0 6 votes vote down vote up
/**
 * 如果没有配置http连接池账号和口令,则将es账号和口令转为http协议账号和口令
 * @param namespace
 * @param property
 * @return
 */
@Override
public String getExternalPropertyWithNS(String namespace, String property) {
	String value = null;
	if(property.endsWith(ClientConfiguration.http_authAccount)) {
		value = context.getExternalProperty(property);
		if(SimpleStringUtil.isEmpty(value)){

			value =	ElasticSearchHelper._getStringValue(namespace,"elasticUser",context,null);

		}
	}
	else if(property.endsWith(ClientConfiguration.http_authPassword)) {
		value = context.getExternalProperty(property);
		if(SimpleStringUtil.isEmpty(value)){

			value =	ElasticSearchHelper._getStringValue(namespace,"elasticPassword",context,null);

		}
	}
	else{
		value = context.getExternalProperty(property);
	}
	return value;
}
 
Example 2
Source File: TimeBasedIndexNameBuilder.java    From bboss-elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
 public void configure(Properties elasticsearchPropes) {
   String dateFormatString = elasticsearchPropes.getProperty(DATE_FORMAT);

   String timeZoneString = elasticsearchPropes.getProperty(TIME_ZONE);
   indexPrefix = elasticsearchPropes.getProperty(ElasticSearchSinkConstants.INDEX_NAME);
   logger.info("dateFormatString = "+dateFormatString+",timeZoneString="+timeZoneString+",indexPrefix="+indexPrefix);
//  logger.info(">>>>>>>>>>>>>>>>>>dateFormatString:"+dateFormatString+",timeZoneString:"+timeZoneString);

   if (SimpleStringUtil.isEmpty(dateFormatString) || dateFormatString.startsWith("${")) {

     dateFormatString = DEFAULT_DATE_FORMAT;
   }
   if (SimpleStringUtil.isEmpty(timeZoneString) || timeZoneString.startsWith("${")) {
     timeZoneString = DEFAULT_TIME_ZONE;
   }

   try {
     fastDateFormat = FastDateFormat.getInstance(dateFormatString,
             TimeZone.getTimeZone(timeZoneString));
   }
   catch (Exception e){
       logger.warn("解析时间格式异常[dateFormatString = "+dateFormatString+",timeZoneString="+timeZoneString+"],将采用默认的时间格式和时区[yyyy.MM.dd Etc/UTC]",e);
   }

 }
 
Example 3
Source File: TimestampedEvent.java    From bboss-elasticsearch with Apache License 2.0 6 votes vote down vote up
TimestampedEvent(Event base) {
	  super(base);
//    setBody(base.getBody());

    Map<String, String> headers =base.getHeaders();
    String timestampString = headers != null ?headers.get("timestamp"):null;
    if (SimpleStringUtil.isEmpty(timestampString)) {
      timestampString = headers.get("@timestamp");
    }
    if (SimpleStringUtil.isEmpty(timestampString)) {
      this.timestamp = DateTimeUtils.currentTimeMillis();
      headers.put("timestamp", String.valueOf(timestamp ));
    } else {
      this.timestamp = Long.valueOf(timestampString);
    }
    setHeaders(headers);
  }
 
Example 4
Source File: WrapperGetProperties.java    From bboss-elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * 如果没有配置http连接池账号和口令,则将es账号和口令转为http协议账号和口令
 * @param namespace
 * @param property
 * @param defaultValue
 * @return
 */
@Override
public String getExternalPropertyWithNS(String namespace, String property, String defaultValue) {
	String value = null;
	if(property.endsWith(ClientConfiguration.http_authAccount)) {
		value = context.getExternalProperty(property);
		if(SimpleStringUtil.isEmpty(value)){

			value =	ElasticSearchHelper._getStringValue(namespace,"elasticUser",context,null);

		}
	}
	else if(property.endsWith(ClientConfiguration.http_authPassword)) {
		value = context.getExternalProperty(property);
		if(SimpleStringUtil.isEmpty(value)){

			value =	ElasticSearchHelper._getStringValue(namespace,"elasticPassword",context,null);

		}
	}
	else{
		value = context.getExternalProperty(property);
	}
	if(value != null)
		return value;
	else
		return defaultValue;
}
 
Example 5
Source File: ElasticSearchJSONEventSerializer.java    From bboss-elasticsearch with Apache License 2.0 4 votes vote down vote up
private   void appendHeaders(Map<String,Object> builder, Event event)
      throws IOException {
//    Map<String, String> headers = Maps.newHashMap(event.getHeaders());
	  MapBuilder mapBuilder = MapBuilder.newMapBuilder();
//	  mapBuilder.putAll(event.getHeaders());
//	  Map<String, String> headers = mapBuilder.map();
    Map<String, String> headers = event.getHeaders();
    if(headers == null || headers.size() == 0){
      return;
    }
    String timestamp = headers.remove("timestamp");
    if (!SimpleStringUtil.isEmpty(timestamp)
        && SimpleStringUtil.isEmpty(headers.get("@timestamp"))) {
      long timestampMs = Long.parseLong(timestamp);
      builder.put("@timestamp", new Date(timestampMs));
    }

    String source = headers.remove("source");
    if (!SimpleStringUtil.isEmpty(source)
        && SimpleStringUtil.isEmpty(headers.get("@source"))) {
      builder.put( "@source",
          source);
    }

    String type = headers.remove("type");
    if (!SimpleStringUtil.isEmpty(type)
        && SimpleStringUtil.isEmpty(headers.get("@type"))) {
      builder.put("@type", type);
    }

    String host = headers.remove("host");
    if (!SimpleStringUtil.isEmpty(host)
        && SimpleStringUtil.isEmpty(headers.get("@source_host"))) {

      builder.put( "beat.host",
          host);
    }

    String srcPath = headers.remove("src_path");
    if (!SimpleStringUtil.isEmpty(srcPath)
        && SimpleStringUtil.isEmpty(headers.get("@source_path"))) {
      builder.put( "@source_path",
          srcPath);
    }


    for (String key : headers.keySet()) {
      String val = headers.get(key);
      builder.put(key, val);
    }

  }
 
Example 6
Source File: ElasticSearchLogStashEventSerializer.java    From bboss-elasticsearch with Apache License 2.0 4 votes vote down vote up
private  void appendHeaders(XContentBuilder builder, Event event)
      throws IOException {
//    Map<String, String> headers = Maps.newHashMap(event.getHeaders());
	  MapBuilder mapBuilder = MapBuilder.newMapBuilder();
//	  mapBuilder.putAll(event.getHeaders());
//	  Map<String, String> headers = mapBuilder.map();
    Map<String, String> headers = event.getHeaders();
    if(headers == null || headers.size() == 0){
      return;
    }
    String timestamp = headers.remove("timestamp");
    if (!SimpleStringUtil.isEmpty(timestamp)
        && SimpleStringUtil.isEmpty(headers.get("@timestamp"))) {
      long timestampMs = Long.parseLong(timestamp);
      builder.field("@timestamp", new Date(timestampMs));
    }

    String source = headers.remove("source");
    if (!SimpleStringUtil.isEmpty(source)
        && SimpleStringUtil.isEmpty(headers.get("@source"))) {
      ContentBuilderUtil.appendField(builder, "@source",
          source.getBytes(charset));
    }

    String type = headers.remove("type");
    if (!SimpleStringUtil.isEmpty(type)
        && SimpleStringUtil.isEmpty(headers.get("@type"))) {
      ContentBuilderUtil.appendField(builder, "@type", type.getBytes(charset));
    }

    String host = headers.remove("host");
    if (!SimpleStringUtil.isEmpty(host)
        && SimpleStringUtil.isEmpty(headers.get("@source_host"))) {
      ContentBuilderUtil.appendField(builder, "@source_host",
          host.getBytes(charset));
    }

    String srcPath = headers.remove("src_path");
    if (!SimpleStringUtil.isEmpty(srcPath)
        && SimpleStringUtil.isEmpty(headers.get("@source_path"))) {
      ContentBuilderUtil.appendField(builder, "@source_path",
          srcPath.getBytes(charset));
    }

    builder.startObject("@fields");
    for (String key : headers.keySet()) {
      byte[] val = headers.get(key).getBytes(charset);
      ContentBuilderUtil.appendField(builder, key, val);
    }
    builder.endObject();
  }