Search in sources :

Example 51 with HongsException

use of app.hongs.HongsException in project HongsCORE by ihongs.

the class SystemCmdlet method runCmd.

private static void runCmd(Date dt, File fo, Logger lg) throws HongsException {
    Document doc;
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder dbn = dbf.newDocumentBuilder();
        doc = dbn.parse(fo);
    } catch (ParserConfigurationException ex) {
        throw new HongsException.Common(ex);
    } catch (SAXException ex) {
        throw new HongsException.Common(ex);
    } catch (IOException ex) {
        throw new HongsException.Common(ex);
    }
    NodeList l = doc.getChildNodes();
    for (int i = 0; i < l.getLength(); i++) {
        Node n = l.item(i);
        if (n.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }
        Element e = (Element) n;
        String t = e.getTagName();
        if ("cmdlet".equals(t)) {
            runCmd(e, dt, lg);
        } else if ("action".equals(t)) {
            runAct(e, dt, lg);
        } else {
            throw new HongsException.Common("Wrong tagName: " + t);
        }
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) HongsException(app.hongs.HongsException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 52 with HongsException

use of app.hongs.HongsException in project HongsCORE by ihongs.

the class TableDeff method syncSlaver.

/**
 * 同步从表结构
 * @param slaver
 * @param delExtraFields 删除多余的字段
 * @throws app.hongs.HongsException
 */
public void syncSlaver(Table slaver, boolean delExtraFields) throws HongsException {
    List<String> sqls = this.deffSlaver(slaver, delExtraFields);
    DB sdb = slaver.db;
    sdb.begin();
    try {
        for (String sql : sqls) {
            sdb.execute(sql);
        }
        sdb.commit();
    } catch (HongsException ex) {
        sdb.revert();
        throw ex;
    }
}
Also used : HongsException(app.hongs.HongsException) DB(app.hongs.db.DB)

Example 53 with HongsException

use of app.hongs.HongsException in project HongsCORE by ihongs.

the class SessFilter method doFilter.

@Override
public void doFilter(ServletRequest req, ServletResponse rsp, FilterChain flt) throws ServletException, IOException {
    HttpServletRequest raq = (HttpServletRequest) req;
    HttpServletResponse rzp = (HttpServletResponse) rsp;
    /**
     * 对于嵌套相同过滤, 不在内部重复执行;
     * 如外部设置了忽略, 则跳过忽略的路径.
     */
    if ((inside != null && Synt.declare(req.getAttribute(inside), false)) || (ignore != null && ignore.ignore(ActionDriver.getRecentPath(raq)))) {
        flt.doFilter(req, rsp);
        return;
    }
    try {
        raq = new SessAccess(raq, rzp, this);
        raq.setAttribute(inside, true);
        flt.doFilter(raq, rzp);
    } finally {
        raq.removeAttribute(inside);
        // 最终任务完成后对会话进行保存
        HttpSession ses = raq.getSession(false);
        if (null != ses && ses instanceof Sesion) {
            try {
                ((Sesion) ses).close();
            } catch (HongsException ex) {
                throw new ServletException(ex);
            }
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) HongsException(app.hongs.HongsException) HttpSession(javax.servlet.http.HttpSession) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 54 with HongsException

use of app.hongs.HongsException in project HongsCORE by ihongs.

the class FileAction method update.

@Override
@Action("update")
public void update(ActionHelper helper) throws HongsException {
    CoreLocale lang = CoreLocale.getInstance("manage");
    String path = helper.getParameter("path");
    String dist = helper.getParameter("dist");
    String text = helper.getParameter("text");
    File file;
    File dizt;
    if (dist != null && dist.equals(path)) {
        dist = null;
    }
    if (path == null) {
        helper.fault(lang.translate("core.manage.file.path.required"));
        return;
    }
    path = realPath(path);
    if (path == null) {
        helper.fault(lang.translate("core.manage.file.path.is.error"));
        return;
    }
    file = new File(path);
    if (!file.exists()) {
        helper.fault(lang.translate("core.manage.file.path.is.not.exist"));
        return;
    }
    if (isDenyFile(file)) {
        helper.fault(lang.translate("core.manage.file.interdicted"));
        return;
    }
    // 改名移动
    if (dist != null) {
        dist = realPath(dist);
        if (dist == null) {
            helper.fault(lang.translate("core.manage.file.path.is.error"));
            return;
        }
        dizt = new File(dist);
        if (dizt.exists()) {
            helper.fault(lang.translate("core.manage.file.dist.is.exist"));
            return;
        }
        if (isDenyFile(file)) {
            helper.fault(lang.translate("core.manage.file.interdicted"));
            return;
        }
        if (!file.renameTo(dizt)) {
            helper.fault(lang.translate("core.manage.file.rename.failed"));
            return;
        }
        if (text == null) {
            return;
        }
        file = dizt;
    }
    // 写入文件
    try {
        saveFile(file, text);
    } catch (Exception ex) {
        CoreLogger.error(ex);
        helper.fault(lang.translate("core.manage.file.update.failed"));
        return;
    }
    helper.reply("");
}
Also used : CoreLocale(app.hongs.CoreLocale) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) HongsException(app.hongs.HongsException) IAction(app.hongs.dh.IAction) Action(app.hongs.action.anno.Action)

Example 55 with HongsException

use of app.hongs.HongsException in project HongsCORE by ihongs.

the class Remote method buildPost.

/**
 * 构建请求实体
 *
 * 采用键值对的数据结构,
 * 当一个键对应多个值时,
 * 值可以是数组或者集合.
 *
 * @param data
 * @return
 * @throws HongsException
 */
public static HttpEntity buildPost(Map<String, Object> data) throws HongsException {
    List<NameValuePair> pair = new ArrayList();
    for (Map.Entry<String, Object> et : data.entrySet()) {
        String n = et.getKey();
        Object o = et.getValue();
        if (o == null) {
        // continue;
        } else if (o instanceof Object[]) {
            // 针对 Servlet 参数格式
            for (Object v : (Object[]) o) {
                String s = String.valueOf(v);
                pair.add(new BasicNameValuePair(n, s));
            }
        } else if (o instanceof Collection) {
            // 针对 WebSocket 的格式
            for (Object v : (Collection) o) {
                String s = String.valueOf(v);
                pair.add(new BasicNameValuePair(n, s));
            }
        } else {
            String s = String.valueOf(o);
            pair.add(new BasicNameValuePair(n, s));
        }
    }
    try {
        return new UrlEncodedFormEntity(pair, HTTP.UTF_8);
    } catch (UnsupportedEncodingException ex) {
        throw new HongsException.Common(ex);
    }
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) HongsException(app.hongs.HongsException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HongsException (app.hongs.HongsException)89 Map (java.util.Map)42 HashMap (java.util.HashMap)34 IOException (java.io.IOException)21 ArrayList (java.util.ArrayList)15 HashSet (java.util.HashSet)15 LinkedHashMap (java.util.LinkedHashMap)15 Set (java.util.Set)15 List (java.util.List)13 File (java.io.File)11 SQLException (java.sql.SQLException)10 FileNotFoundException (java.io.FileNotFoundException)9 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)9 PreparedStatement (java.sql.PreparedStatement)8 Iterator (java.util.Iterator)8 DocumentBuilder (javax.xml.parsers.DocumentBuilder)8 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)8 HongsExpedient (app.hongs.HongsExpedient)7 FormSet (app.hongs.action.FormSet)7 Table (app.hongs.db.Table)7