提交 7b7e9259 编写于 作者: Z zhangxin10

完成授权文件下载功能

上级 05738419
...@@ -35,7 +35,7 @@ public class AlarmRuleCtl { ...@@ -35,7 +35,7 @@ public class AlarmRuleCtl {
/*** /***
* 查询用户默认规则 * 查询用户默认规则
* *
* @param root * @param root
* @return * @return
* @throws Exception * @throws Exception
...@@ -74,7 +74,7 @@ public class AlarmRuleCtl { ...@@ -74,7 +74,7 @@ public class AlarmRuleCtl {
/*** /***
* 查询用户默认规则 * 查询用户默认规则
* *
* @param root * @param root
* @return * @return
* @throws Exception * @throws Exception
...@@ -114,7 +114,7 @@ public class AlarmRuleCtl { ...@@ -114,7 +114,7 @@ public class AlarmRuleCtl {
/*** /***
* 创建用户默认规则 * 创建用户默认规则
* *
* @param root * @param root
* @return * @return
* @throws Exception * @throws Exception
...@@ -258,7 +258,7 @@ public class AlarmRuleCtl { ...@@ -258,7 +258,7 @@ public class AlarmRuleCtl {
/*** /***
* 创建用户默认规则 * 创建用户默认规则
* *
* @param root * @param root
* @return * @return
* @throws Exception * @throws Exception
...@@ -333,7 +333,6 @@ public class AlarmRuleCtl { ...@@ -333,7 +333,6 @@ public class AlarmRuleCtl {
ruleMVO.setTodoType(todoType); ruleMVO.setTodoType(todoType);
JSONObject confArgs = new JSONObject(); JSONObject confArgs = new JSONObject();
confArgs.put("period", period); confArgs.put("period", period);
confArgs.put("excludeExceptions", json.get("excludeExceptions"));
if (Constants.TODO_TYPE_0.equals(todoType)) { if (Constants.TODO_TYPE_0.equals(todoType)) {
// 设置邮件相关的信息 // 设置邮件相关的信息
JSONObject mailInfo = new JSONObject(); JSONObject mailInfo = new JSONObject();
......
package com.ai.cloud.controller; package com.ai.cloud.controller;
import java.io.BufferedInputStream; import com.ai.cloud.service.inter.IAuthFileSer;
import java.io.BufferedOutputStream; import com.ai.cloud.service.inter.ISystemConfigSer;
import java.io.OutputStream; import com.ai.cloud.util.Constants;
import java.net.URLDecoder; import com.ai.cloud.util.common.StringUtil;
import java.net.URLEncoder; import com.alibaba.fastjson.JSONObject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import com.ai.cloud.util.Constants; import javax.servlet.http.HttpServletRequest;
import com.ai.cloud.util.common.StringUtil; import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSONObject; import javax.servlet.http.HttpSession;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.OutputStream;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Map;
import java.util.Properties;
@Controller @Controller
public class AuthFileCtl { public class AuthFileCtl {
private static Logger logger = LogManager.getLogger(AlarmRuleCtl.class); private static Logger logger = LogManager.getLogger(AlarmRuleCtl.class);
@RequestMapping("/exportAuth/{appCode}") @Autowired
public void exportApplicationAuthFile(HttpServletRequest request, HttpServletResponse response, private IAuthFileSer authFileSer;
@PathVariable("appCode") String appCode) throws Exception {
HttpSession session = request.getSession(); @Autowired
String uid = (String) session.getAttribute("uid"); private ISystemConfigSer systemConfigSer;
JSONObject reJson = new JSONObject();
@RequestMapping("/exportAuth/{appCode}")
if (StringUtil.isBlank(uid)) { public void exportApplicationAuthFile(HttpServletRequest request, HttpServletResponse response,
reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL); @PathVariable("appCode") String appCode) throws Exception {
reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "用户会话超时"); HttpSession session = request.getSession();
return ; String uid = (String) session.getAttribute("uid");
}
JSONObject reJson = new JSONObject();
String filepath = "sky-walking.auth";
response.reset(); if (StringUtil.isBlank(uid)) {
response.setContentType("application/octet-stream"); reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
String fileName = URLDecoder.decode(filepath, "utf-8"); reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "用户会话超时");
java.net.URLEncoder.encode(fileName, "utf-8"); return;
response.addHeader("Content-Disposition", }
"attachment;" + "filename=\"" + URLEncoder.encode(fileName, "utf-8") + "\"");
String filepath = "sky-walking.auth";
StringBuilder sb = new StringBuilder(""); response.reset();
sb.append("测试魂牵梦萦魂牵梦萦" + "\r\n"); response.setContentType("application/octet-stream");
BufferedOutputStream output = null; String fileName = URLDecoder.decode(filepath, "utf-8");
BufferedInputStream input = null; java.net.URLEncoder.encode(fileName, "utf-8");
OutputStream os = null; response.addHeader("Content-Disposition",
try { "attachment;" + "filename=\"" + URLEncoder.encode(fileName, "utf-8") + "\"");
os = response.getOutputStream(); Properties properties = authFileSer.queryAuthFile();
byte[] byt = sb.toString().getBytes(); String propertyValue;
os.write(byt); for (Map.Entry<Object, Object> value : properties.entrySet()) {
} catch (Exception e) { propertyValue = String.valueOf(value.getValue());
logger.error("导出 {} 应用制空权文件异常", appCode); if (propertyValue.startsWith("#")) {
e.printStackTrace(); value.setValue(systemConfigSer.querySystemConfigByKey(propertyValue.substring(1)).getConfValue());
} finally { continue;
os.flush(); }
os.close();
if (input != null) { if (propertyValue.startsWith("$")){
input.close(); if (request.getParameter((propertyValue.substring(1))) != null ) {
} value.setValue(request.getParameter(propertyValue.substring(1)));
if (output != null) { }
output.close(); }
} }
} properties.setProperty("skywalking.user_id", uid);
return; properties.setProperty("skywalking.application_code", appCode);
} BufferedOutputStream output = null;
BufferedInputStream input = null;
@RequestMapping("/confAuthInfo/{appCode}") OutputStream os = null;
public String confAuthInfo(HttpServletRequest request, HttpServletResponse response, try {
@PathVariable("appCode") String appCode) throws Exception { os = response.getOutputStream();
HttpSession session = request.getSession(); //byte[] byt = sb.toString().getBytes();
String uid = (String) session.getAttribute("uid"); properties.store(os, "test");
// os.write(byt);
JSONObject reJson = new JSONObject(); } catch (Exception e) {
logger.error("导出 {} 应用制空权文件异常", appCode);
if (StringUtil.isBlank(uid)) { e.printStackTrace();
reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL); } finally {
reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "用户会话超时"); os.flush();
return reJson.toJSONString(); os.close();
} if (input != null) {
input.close();
return reJson.toJSONString(); }
} if (output != null) {
output.close();
}
}
return;
}
@RequestMapping("/confAuthInfo/{appCode}")
public String confAuthInfo(HttpServletRequest request, HttpServletResponse response,
@PathVariable("appCode") String appCode) throws Exception {
HttpSession session = request.getSession();
String uid = (String) session.getAttribute("uid");
JSONObject reJson = new JSONObject();
if (StringUtil.isBlank(uid)) {
reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "用户会话超时");
return reJson.toJSONString();
}
return reJson.toJSONString();
}
} }
package com.ai.cloud.dao.impl;
import com.ai.cloud.dao.inter.IAuthConfigMDAO;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.stereotype.Repository;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
@Repository
public class AuthConfigMDAO implements IAuthConfigMDAO {
@Autowired
private JdbcTemplate jdbcTemplate;
private static Logger logger = LogManager.getLogger(AuthConfigMDAO.class);
@Override
public Properties queryAllAuthConfig() {
final Properties properties = new Properties();
String sql = "select auth_file_config.key, auth_file_config.value from auth_file_config where auth_file_config.sts = ? ";
final Object[] params = new Object[]{"A"};
jdbcTemplate.query(sql, params,new RowCallbackHandler() {
@Override
public void processRow(ResultSet resultSet) throws SQLException {
properties.setProperty(resultSet.getString("key"), resultSet.getString("value"));
}
});
return properties;
}
}
package com.ai.cloud.dao.impl;
import com.ai.cloud.dao.inter.ISystemConfigMDAO;
import com.ai.cloud.vo.mvo.SystemConfigMVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.stereotype.Repository;
import java.sql.ResultSet;
import java.sql.SQLException;
@Repository
public class SystemConfigMDAO implements ISystemConfigMDAO {
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public SystemConfigMVO querySystemConfigByKey(String key) {
final SystemConfigMVO systemConfigMVO = new SystemConfigMVO();
String sql = "SELECT config_id, conf_key, conf_value, val_type, val_desc from system_config where conf_key = ? and sts = ?";
final Object[] params = new Object[]{key, "A"};
jdbcTemplate.query(sql, params, new RowCallbackHandler() {
@Override
public void processRow(ResultSet resultSet) throws SQLException {
systemConfigMVO.setConfigId(resultSet.getString("config_id"));
systemConfigMVO.setConfKey(resultSet.getString("conf_key"));
systemConfigMVO.setConfValue(resultSet.getString("conf_value"));
systemConfigMVO.setValueType(resultSet.getString("val_type"));
systemConfigMVO.setValueDesc(resultSet.getString("val_desc"));
}
});
return systemConfigMVO;
}
}
package com.ai.cloud.dao.inter;
import java.util.Properties;
public interface IAuthConfigMDAO {
Properties queryAllAuthConfig();
}
package com.ai.cloud.dao.inter;
import com.ai.cloud.vo.mvo.SystemConfigMVO;
public interface ISystemConfigMDAO {
SystemConfigMVO querySystemConfigByKey(String key);
}
package com.ai.cloud.service.impl;
import com.ai.cloud.dao.inter.IAuthConfigMDAO;
import com.ai.cloud.service.inter.IAuthFileSer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Properties;
@Service
public class AuthFileSerImpl implements IAuthFileSer {
@Autowired
private IAuthConfigMDAO authConfigMDAO;
@Override
public Properties queryAuthFile() {
return authConfigMDAO.queryAllAuthConfig();
}
}
package com.ai.cloud.service.impl;
import com.ai.cloud.dao.inter.ISystemConfigMDAO;
import com.ai.cloud.service.inter.ISystemConfigSer;
import com.ai.cloud.vo.mvo.SystemConfigMVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class SystemConfigSerImpl implements ISystemConfigSer {
@Autowired
private ISystemConfigMDAO iSystemConfigMDAO;
@Override
public SystemConfigMVO querySystemConfigByKey(String key) {
return iSystemConfigMDAO.querySystemConfigByKey(key);
}
}
package com.ai.cloud.service.inter;
import java.util.Properties;
public interface IAuthFileSer {
Properties queryAuthFile();
}
package com.ai.cloud.service.inter;
import com.ai.cloud.vo.mvo.SystemConfigMVO;
public interface ISystemConfigSer {
SystemConfigMVO querySystemConfigByKey(String key);
}
package com.ai.cloud.vo.mvo;
public class SystemConfigMVO {
private String configId;
private String confKey;
private String confValue;
private String valueType;
private String valueDesc;
public String getConfigId() {
return configId;
}
public void setConfigId(String configId) {
this.configId = configId;
}
public String getConfKey() {
return confKey;
}
public void setConfKey(String confKey) {
this.confKey = confKey;
}
public String getConfValue() {
return confValue;
}
public void setConfValue(String confValue) {
this.confValue = confValue;
}
public String getValueType() {
return valueType;
}
public void setValueType(String valueType) {
this.valueType = valueType;
}
public String getValueDesc() {
return valueDesc;
}
public void setValueDesc(String valueDesc) {
this.valueDesc = valueDesc;
}
}
#test
#Wed Dec 23 15:24:10 CST 2015
buriedpoint.businesskey_max_length=300
sender.retry_get_sender_wait_interval=2000
buffer.pool_size=5
senderchecker.check_polling_time=200
sender.is_off=false
sender.max_send_length=20000
consumer.max_consumer=2
consumer.max_wait_time=5
sender.max_copy_num=2
skywalking.application_code=test
consumer.consumer_fail_retry_wait_interval=50
skywalking.user_id=1
buriedpoint.printf=false
buriedpoint.exclusive_exceptions=
buriedpoint.max_exception_stack_length=4000
sender.connect_percent=100
buffer.buffer_max_size=18000
sender.servers_addr=127.0.0.1\:34000;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册