zoukankan      html  css  js  c++  java
  • 加载Properties文件工具类:LoadConfig

    import javax.servlet.http.HttpServletRequest;
    import javax.ws.rs.GET;
    import javax.ws.rs.Path;
    import javax.ws.rs.Produces;
    import javax.ws.rs.QueryParam;
    import javax.ws.rs.core.Context;
    import javax.ws.rs.core.MediaType;
    import javax.ws.rs.core.Response;
    
    import org.apache.commons.lang3.StringUtils;
    import org.apache.logging.log4j.LogManager;
    import org.apache.logging.log4j.Logger;
    
    import com.zzc.bl.util.ConfigMgr;
    import com.zzc.bl.util.StringEncryptUtil;
    
    @Path("/loadConfig")
    @Produces(MediaType.APPLICATION_JSON)
    public class LoadConfig {
    	private static final Logger logger = LogManager.getLogger(LoadConfig.class.getName());
    
    //	private static final String token = UUID.randomUUID().toString() + System.currentTimeMillis();
    //	private static final String token = "c2d4f7e8e001486114862926";
    //	private static final String single = "1fc54ecc9c6f4dfd9799b7baec1b0de6";
    	private static final String salt = "3f73c5fafaf13f160670b59025745889";
    	@GET
    	@Path("/loading")
    	public Response loading(@QueryParam("token") String token,@QueryParam("single") String single,@Context HttpServletRequest request) {
    		final String requestPath = request.getPathInfo();
    		logger.info("[entrance: " + requestPath + "] [params: { "token": "" + token + "", "single": "" + single + "" } ]");
    		// 检测请求合法性
    		if(StringUtils.isEmpty(token)){
    			logger.info("[entrance: " + requestPath + "] [response_status: 400] [response_body: { "errors": "token is empty !!!" } ]");
    			return Response.status(400).entity("{"errors": "token is empty !!!"}").build();
    		}
    		if(StringUtils.isEmpty(single)){
    			logger.info("[entrance: " + requestPath + "] [response_status: 400] [response_body: { "errors": "single is empty !!!" } ]");
    			return Response.status(400).entity("{"errors": "single is empty !!!"}").build();
    		}
    		String content = salt + StringEncryptUtil.md5(token);
    		String mdStr = StringEncryptUtil.md5(content);
    		if(!mdStr.equals(single)){
    			logger.info("[entrance: " + requestPath + "] [response_status: 400] [response_body: { "errors": "single is invalid !!!" } ]");
    			return Response.status(400).entity("{"errors": "single is invalid !!!"}").build();
    		}
    		// 加载Properties属性文件
    		ConfigMgr.init("config.properties");
    		logger.info("[entrance: " + requestPath + "] [response_status: 200] [response_body: {"success": "properties files has been loaded !!!"} ]");
    		return Response.status(200).entity("{"success": "properties files has been loaded !!!"}").build();
    	}
    	
    }

  • 相关阅读:
    ConcurrentHashMap实现原理--转载
    java原子操作的实现原理--转载
    Catch Me If You ... Can't Do Otherwise--转载
    微框架spark--api开发利器
    Exploring Micro-frameworks: Spring Boot--转载
    简约之美jodd--props属性使用
    jodd-cache集锦
    java根据url获取完整域名
    Jodd-vtor验证框架
    倒排列表求交集算法 包括baeza yates的交集算法
  • 原文地址:https://www.cnblogs.com/ason-wxs/p/13386783.html
Copyright © 2011-2022 走看看