首页 > 学院 > 开发设计 > 正文

加载Properties文件工具类:LoadConfig

2019-11-14 10:39:47
字体:
来源:转载
供稿:网友
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();	}	}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表