use of com.qlangtech.tis.lang.TisException in project plugins by qlangtech.
the class DorisSourceFactory method getConnection.
@Override
public Connection getConnection(String jdbcUrl) throws SQLException {
Properties props = new Properties();
props.put("user", StringUtils.trimToEmpty(this.userName));
props.put("password", StringUtils.trimToEmpty(password));
try {
return mysql5Driver.connect(jdbcUrl, props);
} catch (SQLException e) {
throw new TisException(e.getMessage() + ",jdbcUrl:" + jdbcUrl + ",props:" + props.toString(), e);
}
// return DriverManager.getConnection(jdbcUrl, StringUtils.trimToNull(this.userName), StringUtils.trimToNull(this.password));
}
use of com.qlangtech.tis.lang.TisException in project tis by qlangtech.
the class TisExceptionInterceptor method doIntercept.
@Override
protected String doIntercept(ActionInvocation invocation) throws Exception {
HttpServletResponse response = ServletActionContext.getResponse();
HttpServletRequest request = ServletActionContext.getRequest();
boolean disableTransaction = Boolean.parseBoolean(request.getParameter(IParamContext.KEY_REQUEST_DISABLE_TRANSACTION));
TransactionStatus status = null;
if (!disableTransaction) {
status = transactionManager.getTransaction(new DefaultTransactionDefinition());
}
ActionProxy proxy = invocation.getProxy();
AjaxValve.ActionExecResult execResult = null;
try {
if (disableTransaction) {
return invocation.invoke();
} else {
invocation.getInvocationContext().put(TransactionStatus.class.getSimpleName(), status);
final String result = invocation.invoke();
execResult = MockContext.getActionExecResult();
// 一定要invoke之后再执行
if (!execResult.isSuccess()) {
// 业务失败也要回滚
transactionManager.rollback(status);
return result;
}
if (!status.isCompleted()) {
transactionManager.commit(status);
}
return result;
}
} catch (Throwable e) {
logger.error(e.getMessage(), e);
if (!disableTransaction && !status.isCompleted()) {
transactionManager.rollback(status);
}
// if (TisActionMapper.REQUEST_EXTENDSION_AJAX.equals(mapping.getExtension())) {
if (StringUtils.endsWith(proxy.getNamespace(), TisActionMapper.ACTION_TOKEN)) {
// logger.error(e.getMessage(), e);
List<String> errors = new ArrayList<String>();
errors.add("服务端发生异常,请联系系统管理员");
TisException tisExcept = TisException.find(e);
// }
if (tisExcept == null) {
errors.add(ExceptionUtils.getRootCauseMessage(e));
} else {
errors.add(tisExcept.getMessage());
}
// execResult = MockContext.getActionExecResult();
// execResult.addErrorMsg(errors);
AjaxValve.writeInfo2Client(() -> false, response, false, errors, Collections.emptyList(), Collections.emptyList(), null);
return Action.NONE;
} else {
throw e;
}
}
}
use of com.qlangtech.tis.lang.TisException in project tis by qlangtech.
the class DataSourceFactory method validateConnection.
protected void validateConnection(String jdbcUrl, BasicDataSourceFactory.IConnProcessor p) {
Connection conn = null;
try {
conn = getConnection(jdbcUrl);
p.vist(conn);
} catch (Exception e) {
throw new TisException(e.getMessage() + ",jdbcUrl:" + jdbcUrl, e);
} finally {
if (conn != null) {
try {
conn.close();
} catch (Throwable e) {
}
}
}
}
use of com.qlangtech.tis.lang.TisException in project tis by qlangtech.
the class ConfigFileContext method processContent.
public static <T> T processContent(URL url, StreamProcess<T> process, HTTPMethod method, byte[] content, final int maxRetry) {
InputStream reader = null;
int retryCount = 0;
while (true) {
try {
HttpURLConnection conn = getNetInputStream(url, process.getHeaders(), method, content);
try {
reader = conn.getInputStream();
} catch (IOException e) {
InputStream errStream = null;
try {
errStream = conn.getErrorStream();
process.error(conn.getResponseCode(), errStream, e);
return null;
} finally {
IOUtils.closeQuietly(errStream);
}
}
return process.p(conn, reader);
} catch (Exception e) {
if (++retryCount >= maxRetry) {
throw new TisException("maxRetry:" + maxRetry + ",url:" + url.toString(), e);
} else {
try {
Thread.sleep(3000);
} catch (InterruptedException e1) {
throw new RuntimeException(e1);
}
logger.warn(e.getMessage(), e);
}
} finally {
try {
reader.close();
} catch (Throwable e) {
}
}
}
}
use of com.qlangtech.tis.lang.TisException in project tis by qlangtech.
the class SysInitializeAction method initializeZkPath.
// 初始化ZK内容
public boolean initializeZkPath(String zkHost) {
Matcher matcher = PATTERN_ZK_ADDRESS.matcher(zkHost);
if (!matcher.matches()) {
throw new IllegalStateException("zk address " + zkHost + " is not match " + PATTERN_ZK_ADDRESS);
}
final String zkServer = matcher.group(1);
String zkSubDir = StringUtils.trimToEmpty(matcher.group(2));
logger.info("zkServer:{},zkSubDir:{}", zkServer, zkSubDir);
if (StringUtils.endsWith(zkSubDir, "/")) {
zkSubDir = StringUtils.substring(zkSubDir, 0, zkSubDir.length() - 1);
}
ZooKeeper zk = null;
StringBuffer buildLog = new StringBuffer();
String createPath = null;
List<String> createPaths = Lists.newArrayList();
try {
// final Watcher watcher = new Watcher() {
// @Override
// public void process(WatchedEvent event) {
// logger.info(event.getType() + "," + event.getState() + "," + event.getPath());
// }
// };
// new ZooKeeper(zkServer, 50000, watcher);
zk = this.createZK(zkServer);
zk.getChildren("/", false);
buildLog.append("create zkServer ").append(zkServer);
createPath = zkSubDir + "/tis";
ITISCoordinator coordinator = getCoordinator(zk);
logger.info("guaranteeExist:{}", createPath);
createPaths.add(createPath);
ZkUtils.guaranteeExist(coordinator, createPath);
buildLog.append(",path1:").append(createPath);
createPath = zkSubDir + "/tis-lock/dumpindex";
createPaths.add(createPath);
ZkUtils.guaranteeExist(coordinator, createPath);
buildLog.append(",path2:").append(createPath);
// createPath = zkSubDir + "/configs/" + CoreAction.DEFAULT_SOLR_CONFIG;
// createPaths.add(createPath);
// ZkUtils.guaranteeExist(coordinator, createPath);
// buildLog.append(",path3:").append(createPath);
logger.info(buildLog.toString());
} catch (Throwable e) {
throw new IllegalStateException("zk address:" + zkServer + " can not connect Zookeeper server", e);
} finally {
try {
zk.close();
} catch (Throwable e) {
}
}
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
}
try {
zk = this.createZK(zkServer);
for (String p : createPaths) {
if (zk.exists(p, false) == null) {
throw new TisException("create path:" + p + " must be exist");
}
}
} catch (TisException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
try {
zk.close();
} catch (InterruptedException e) {
}
}
// }
return true;
}
Aggregations