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

完成授权文件下载功能

上级 05738419
......@@ -333,7 +333,6 @@ public class AlarmRuleCtl {
ruleMVO.setTodoType(todoType);
JSONObject confArgs = new JSONObject();
confArgs.put("period", period);
confArgs.put("excludeExceptions", json.get("excludeExceptions"));
if (Constants.TODO_TYPE_0.equals(todoType)) {
// 设置邮件相关的信息
JSONObject mailInfo = new JSONObject();
......
package com.ai.cloud.controller;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.OutputStream;
import java.net.URLDecoder;
import java.net.URLEncoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.ai.cloud.service.inter.IAuthFileSer;
import com.ai.cloud.service.inter.ISystemConfigSer;
import com.ai.cloud.util.Constants;
import com.ai.cloud.util.common.StringUtil;
import com.alibaba.fastjson.JSONObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import com.ai.cloud.util.Constants;
import com.ai.cloud.util.common.StringUtil;
import com.alibaba.fastjson.JSONObject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
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
public class AuthFileCtl {
private static Logger logger = LogManager.getLogger(AlarmRuleCtl.class);
@Autowired
private IAuthFileSer authFileSer;
@Autowired
private ISystemConfigSer systemConfigSer;
@RequestMapping("/exportAuth/{appCode}")
public void exportApplicationAuthFile(HttpServletRequest request, HttpServletResponse response,
@PathVariable("appCode") String appCode) throws Exception {
......@@ -36,7 +46,7 @@ public class AuthFileCtl {
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 ;
return;
}
String filepath = "sky-walking.auth";
......@@ -46,16 +56,31 @@ public class AuthFileCtl {
java.net.URLEncoder.encode(fileName, "utf-8");
response.addHeader("Content-Disposition",
"attachment;" + "filename=\"" + URLEncoder.encode(fileName, "utf-8") + "\"");
Properties properties = authFileSer.queryAuthFile();
String propertyValue;
for (Map.Entry<Object, Object> value : properties.entrySet()) {
propertyValue = String.valueOf(value.getValue());
if (propertyValue.startsWith("#")) {
value.setValue(systemConfigSer.querySystemConfigByKey(propertyValue.substring(1)).getConfValue());
continue;
}
StringBuilder sb = new StringBuilder("");
sb.append("测试魂牵梦萦魂牵梦萦" + "\r\n");
if (propertyValue.startsWith("$")){
if (request.getParameter((propertyValue.substring(1))) != null ) {
value.setValue(request.getParameter(propertyValue.substring(1)));
}
}
}
properties.setProperty("skywalking.user_id", uid);
properties.setProperty("skywalking.application_code", appCode);
BufferedOutputStream output = null;
BufferedInputStream input = null;
OutputStream os = null;
try {
os = response.getOutputStream();
byte[] byt = sb.toString().getBytes();
os.write(byt);
//byte[] byt = sb.toString().getBytes();
properties.store(os, "test");
// os.write(byt);
} catch (Exception e) {
logger.error("导出 {} 应用制空权文件异常", appCode);
e.printStackTrace();
......
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.
先完成此消息的编辑!
想要评论请 注册