use of app.hongs.HongsException in project HongsCORE by ihongs.
the class Common method file.
public static String file(String path) throws HongsException {
try (BufferedReader br = new BufferedReader(new FileReader(new File(path)))) {
int bn;
char[] bs;
StringBuilder sb = new StringBuilder();
while (true) {
bs = new char[1024];
if ((bn = br.read(bs)) < 0) {
break;
}
sb.append(bs, 0, bn);
}
return sb.toString();
} catch (FileNotFoundException ex) {
throw new HongsException.Common("Can not find " + path, ex);
} catch (IOException ex) {
throw new HongsException.Common("Can not read " + path, ex);
}
}
use of app.hongs.HongsException in project HongsCORE by ihongs.
the class Common method callAction.
@Cmdlet("call-action")
public static void callAction(String[] args) throws HongsException {
Map<String, Object> opts;
opts = CmdletHelper.getOpts(args, "request:s", "cookies:s");
args = (String[]) opts.get("");
String act = args[0];
String req = text((String) opts.get("request"));
Map<String, String> cok = data((String) opts.get("cookies"));
String hst = System.getProperty("server.host", "localhost");
String pot = System.getProperty("server.port", "8080");
String url = "http://" + hst + ":" + pot + Core.BASE_HREF + "/" + act + Cnst.ACT_EXT;
try {
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setConnectTimeout(0);
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json,text/html,*/*;q=0.8");
conn.setRequestProperty("X-Requested-With", "HongsCORE/0.4");
// 放入 cookie
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, String> et : cok.entrySet()) {
sb.append(URLEncoder.encode(et.getKey(), "UTF-8"));
sb.append("=");
sb.append(URLEncoder.encode(et.getValue(), "UTF-8"));
sb.append(";");
}
conn.setRequestProperty("Cookie", sb.toString());
PrintWriter out = new PrintWriter(conn.getOutputStream());
out.print(req);
out.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.print(line);
}
} catch (UnsupportedEncodingException ex) {
throw new HongsException.Common(ex);
} catch (MalformedURLException ex) {
throw new HongsException.Common(ex);
} catch (IOException ex) {
throw new HongsException.Common(ex);
}
}
use of app.hongs.HongsException in project HongsCORE by ihongs.
the class DBAction method acting.
@Override
public void acting(ActionHelper helper, ActionRunner runner) throws HongsException {
String act = runner.getHandle();
String ent = runner.getEntity();
String mod = runner.getModule();
try {
// 下划线开头的为内部资源, 不直接对外开放
if (ent.startsWith("_")) {
throw new HongsException(0x1100, "Unsupported Request!");
}
// 判断是否禁用了当前动作, 忽略表单不存在
Map fa = FormSet.getInstance(mod).getForm(ent);
Set ca = Synt.toSet(Dict.getDepth(fa, "@", "callable"));
if (ca != null && !ca.contains(act)) {
throw new HongsException(0x1100, "Unsupported Request.");
}
} catch (HongsException | HongsExpedient ex) {
int ec = ex.getErrno();
if (ec != 0x10e8 && ec != 0x10ea) {
throw ex;
}
}
}
use of app.hongs.HongsException in project HongsCORE by ihongs.
the class DBConfig method parseBySource.
/**
* 根据输入流解析配置
*
* @param ds
* @return 配置对象
* @throws app.hongs.HongsException
*/
public static DBConfig parseBySource(InputSource ds) throws HongsException {
Document doc;
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder dbn = dbf.newDocumentBuilder();
doc = dbn.parse(ds);
} catch (ParserConfigurationException ex) {
throw new app.hongs.HongsException(0x1063, ex);
} catch (SAXException ex) {
throw new app.hongs.HongsException(0x1063, ex);
} catch (IOException ex) {
throw new app.hongs.HongsException(0x1069, ex);
}
return new DBConfig(doc);
}
use of app.hongs.HongsException in project HongsCORE by ihongs.
the class DBFields method imports.
@Override
protected final void imports() throws HongsException {
fields = new LinkedHashMap();
Loop rs = db.query("SELECT * FROM `" + tn + "`", 0, 1);
try {
ResultSetMetaData md = rs.getMetaData();
for (int i = 1; i <= md.getColumnCount(); i++) {
Map field = new HashMap();
field.put("type", md.getColumnType(i));
field.put("size", md.getPrecision(i));
field.put("scale", md.getScale(i));
field.put("unsigned", !md.isSigned(i));
field.put("required", md.isNullable(i) == ResultSetMetaData.columnNoNulls);
field.put("autoIncrement", md.isAutoIncrement(i));
field.put("caseSensitive", md.isCaseSensitive(i));
// 用处不大的的属性:
/*
field.put("currency", md.isCurrency(i));
field.put("readOnly", md.isReadOnly(i));
field.put("writable", md.isWritable(i));
field.put("searchable", md.isSearchable(i));
field.put("tableName", md.getTableName(i));
field.put("schemaName", md.getSchemaName(i));
field.put("catalogName", md.getCatalogName(i));
field.put("label", md.getColumnLable(i));
field.put("typeName", md.getColumnTypeName(i));
field.put("className", md.getColumnClassName(i));
field.put("displaySize", md.getColumnDisplaySize(i));
*/
this.fields.put(md.getColumnName(i), field);
}
} catch (SQLException ex) {
throw new HongsException(0x1071, ex);
} finally {
rs.close();
}
}
Aggregations