Java Code Examples for com.frameworkset.util.SimpleStringUtil

The following examples show how to use com.frameworkset.util.SimpleStringUtil. These examples are extracted from open source projects. 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 Project: bboss-elasticsearch   Source File: WrapperGetProperties.java    License: 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
@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 Project: bboss-elasticsearch   Source File: TimestampedEvent.java    License: 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 Project: bboss-elasticsearch   Source File: WrapperGetProperties.java    License: 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 Project: bboss-elasticsearch   Source File: ElasticSearch.java    License: Apache License 2.0 5 votes vote down vote up
protected String getIndexNameBuilderClass(){
	String indexNameBuilderClass = DEFAULT_INDEX_NAME_BUILDER_CLASS;
	if (SimpleStringUtil.isNotEmpty(elasticsearchPropes.getProperty(INDEX_NAME_BUILDER))) {
		indexNameBuilderClass = elasticsearchPropes.getProperty(INDEX_NAME_BUILDER);
	}
	return indexNameBuilderClass;
}
 
Example 6
private   void appendBody(Map<String,Object> builder, Event event)
    throws IOException, UnsupportedEncodingException {
  String data = String.valueOf(event.getBody());
  if(data.startsWith("{") && data.endsWith("}")){
    Map<String,Object> body_ = SimpleStringUtil.json2Object(data,Map.class);
    builder.putAll(body_);
  }
  else{
    builder.put("@message",data);

  }



}
 
Example 7
Source Project: bboss-elasticsearch   Source File: JavaElasticSearch.java    License: Apache License 2.0 5 votes vote down vote up
protected String getIndexNameBuilderClass(){
	String indexNameBuilderClass = EventTimeBasedIndexNameBuilderClass;
	if (SimpleStringUtil.isNotEmpty(elasticsearchPropes.getProperty(INDEX_NAME_BUILDER))) {
		indexNameBuilderClass = elasticsearchPropes.getProperty(INDEX_NAME_BUILDER);
	}
	return indexNameBuilderClass;
}
 
Example 8
Source Project: bboss-elasticsearch   Source File: ESTemplateCache.java    License: Apache License 2.0 4 votes vote down vote up
public void after(){
			super.after();
			if(this.attributes != null) {
//				int pos = this.attributes.indexOf(",");
				String[] ts = attributes.split(",");

				for (int i = 0; i < ts.length; i ++) {
					String t = ts[i];
					if (t.startsWith("quoted=")) {
						String q = t.substring("quoted=".length()).trim();
						if(q.equals("false"))
							quoted = false;
					}
					else if(t.startsWith("dateformat=")){
						dateFormat= t.substring("dateformat=".length()).trim();
					}
					else if(t.startsWith("locale=")){
						locale= t.substring("locale=".length()).trim();
					}
					else if(t.startsWith("timezone=")){
						timeZone = t.substring("timezone=".length()).trim();
					}
					else if(t.startsWith("lpad=")){
						String lpad_= t.substring("lpad=".length()).trim();
						this.lpad = handlePad(lpad_);

					}
					else if(t.startsWith("rpad=")){
						String rpad_ = t.substring("rpad=".length()).trim();
						this.rpad = handlePad(rpad_);
					}
					else if(t.startsWith("escape=")){
						String escape_ = t.substring("escape=".length()).trim();
						if(escape_.equals("false"))
							escape = new Boolean(false);
						else if(escape_.equals("true"))
							escape = new Boolean(true);

					}
					else if(t.startsWith("serialJson=")){
						String serialJson_ = t.substring("serialJson=".length()).trim();
						if(serialJson_.equals("false"))
							serialJson = new Boolean(false);
						else if(serialJson_.equals("true"))
							serialJson = new Boolean(true);

					}else if(t.startsWith("escapeCount=")){
						String escapeCount_ = t.substring("escapeCount=".length()).trim();
						if(SimpleStringUtil.isNotEmpty(escapeCount_)) {
							try {
								escapeCount = Integer.parseInt(escapeCount_);
							}
							catch (Exception e){
								logger.error("escapeCount must be a nummber:"+escapeCount_,e);
							}
						}
					}

				}

				if(this.dateFormat != null){
					this.dateFormateMeta = DateFormateMeta.buildDateFormateMeta(this.dateFormat,this.locale);
				}

			}

		}
 
Example 9
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 10
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();
  }
 
Example 11
@Test
public void testJsonNull(){
	TestVO testVO = new TestVO();
	System.out.println(SimpleStringUtil.object2json(testVO));
}
 
Example 12
Source Project: bboss-elasticsearch   Source File: JavaElasticSearch.java    License: Apache License 2.0 2 votes vote down vote up
@Override
	public void configure() {
	
		 
		if (SimpleStringUtil.isNotEmpty(elasticsearchPropes.getProperty(TRANSPORT_HOSTNAMES))) {
			transportServerAddresses =
					elasticsearchPropes.getProperty(TRANSPORT_HOSTNAMES).trim().split(",");
		}
//		Preconditions.checkState(serverAddresses != null
//				&& serverAddresses.length > 0, "Missing Param:" + HOSTNAMES);


		 

		if (SimpleStringUtil.isNotEmpty(elasticsearchPropes.getProperty(CLUSTER_NAME))) {
			this.clusterName = elasticsearchPropes.getProperty(CLUSTER_NAME);
		}

		  

		if (SimpleStringUtil.isNotEmpty(elasticsearchPropes.getProperty(CLIENT_TYPE))) {
			clientType = elasticsearchPropes.getProperty(CLIENT_TYPE);
		}

		 

		String serializerClazz = null;//DEFAULT_SERIALIZER_CLASS;
		if (SimpleStringUtil.isNotEmpty(elasticsearchPropes.getProperty(SERIALIZER))) {
			serializerClazz = elasticsearchPropes.getProperty(SERIALIZER);
		}



		try {

			if (serializerClazz != null && !serializerClazz.equals("")) {
				Class<? extends ElasticSearchEventSerializer> clazz = (Class<? extends ElasticSearchEventSerializer>) Class
						.forName(serializerClazz);
				ElasticSearchEventSerializer serializer = clazz.newInstance();

				if (serializer instanceof ElasticSearchIndexRequestBuilderFactory) {
					indexRequestFactory
							= (ElasticSearchIndexRequestBuilderFactory) serializer;
					indexRequestFactory.configure(elasticsearchPropes);
				} else if (serializer instanceof ElasticSearchEventSerializer) {
					eventSerializer = (ElasticSearchEventSerializer) serializer;
					eventSerializer.configure(elasticsearchPropes);
				} else {
					throw new IllegalArgumentException(serializerClazz
							+ " is not an ElasticSearchEventSerializer");
				}
			}
		} catch (Exception e) {
			logger.error("Could not instantiate event serializer.", e);
			Throwables.propagate(e);
		}
		
		super.configure();


	 
	}