Search in sources :

Example 1 with ErrorConfig

use of io.leopard.mvc.trynb.model.ErrorConfig in project leopard by tanhaichao.

the class TrynbDaoXmlImpl method parseErrorConfig.

protected ErrorConfig parseErrorConfig(Element element) {
    String url = element.getAttribute("url");
    String page = element.getAttribute("page");
    List<ExceptionConfig> exceptionConfigList = new ArrayList<ExceptionConfig>();
    NodeList nodeList = element.getElementsByTagName("exception");
    int size = nodeList.getLength();
    for (int i = 0; i < size; i++) {
        Node node = nodeList.item(i);
        ExceptionConfig exceptionConfig = this.parseExceptionConfig((Element) node);
        exceptionConfigList.add(exceptionConfig);
    }
    ErrorConfig errorConfig = new ErrorConfig();
    errorConfig.setUrl(url);
    errorConfig.setPage(page);
    errorConfig.setExceptionConfigList(exceptionConfigList);
    return errorConfig;
}
Also used : ErrorConfig(io.leopard.mvc.trynb.model.ErrorConfig) ExceptionConfig(io.leopard.mvc.trynb.model.ExceptionConfig) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList)

Example 2 with ErrorConfig

use of io.leopard.mvc.trynb.model.ErrorConfig in project leopard by tanhaichao.

the class TrynbApiImpl method parse.

@Override
public TrynbInfo parse(TrynbLogger trynbLogger, HttpServletRequest request, String uri, Exception exception) {
    ErrorConfig errorConfig = trynbDao.find(uri);
    if (exception instanceof MethodArgumentTypeMismatchException) {
        MethodArgumentTypeMismatchException e2 = (MethodArgumentTypeMismatchException) exception;
        Exception e = (Exception) e2.getCause().getCause();
        if (e != null) {
            exception = e;
        } else {
            exception = (Exception) e2.getCause();
        }
    }
    ExceptionConfig exceptionConfig = this.find(errorConfig, exception);
    TrynbInfo trynbInfo = new TrynbInfo();
    String message;
    if (exceptionConfig == null || StringUtils.isEmpty(exceptionConfig.getMessage())) {
        message = parseMessage(trynbInfo, exception);
    } else {
        message = exceptionConfig.getMessage();
        trynbInfo.setTrynbMessage(true);
    }
    String statusCode = this.parseStatusCode(trynbLogger, exceptionConfig, request, uri, exception);
    trynbInfo.setPage(errorConfig.getPage());
    trynbInfo.setMessage(message);
    trynbInfo.setException(exception);
    trynbInfo.setStatusCode(statusCode);
    return trynbInfo;
}
Also used : MethodArgumentTypeMismatchException(org.springframework.web.method.annotation.MethodArgumentTypeMismatchException) TrynbInfo(io.leopard.mvc.trynb.model.TrynbInfo) ErrorConfig(io.leopard.mvc.trynb.model.ErrorConfig) ExceptionConfig(io.leopard.mvc.trynb.model.ExceptionConfig) ApiException(io.leopard.core.exception.ApiException) MethodArgumentTypeMismatchException(org.springframework.web.method.annotation.MethodArgumentTypeMismatchException)

Example 3 with ErrorConfig

use of io.leopard.mvc.trynb.model.ErrorConfig in project leopard by tanhaichao.

the class TrynbDaoXmlImpl method parse.

protected List<ErrorConfig> parse(InputStream input) throws IOException, ParserConfigurationException, SAXException {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document document = db.parse(input);
    NodeList nodeList = document.getElementsByTagName("error");
    // System.out.println("nodeList:" + nodeList.getLength());
    List<ErrorConfig> list = new ArrayList<ErrorConfig>();
    int size = nodeList.getLength();
    for (int i = 0; i < size; i++) {
        Node node = nodeList.item(i);
        ErrorConfig errorConfig = this.parseErrorConfig((Element) node);
        list.add(errorConfig);
    }
    input.close();
    return list;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ErrorConfig(io.leopard.mvc.trynb.model.ErrorConfig) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document)

Example 4 with ErrorConfig

use of io.leopard.mvc.trynb.model.ErrorConfig in project leopard by tanhaichao.

the class ErrorConfigTest method ErrorConfig.

@Test
public void ErrorConfig() {
    ErrorConfig config = new ErrorConfig();
    config.setUrl("url");
    config.setPage("page");
    config.setExceptionConfigList(null);
    config.getUrl();
    config.getPage();
    config.getExceptionConfigList();
}
Also used : ErrorConfig(io.leopard.mvc.trynb.model.ErrorConfig) Test(org.junit.Test)

Example 5 with ErrorConfig

use of io.leopard.mvc.trynb.model.ErrorConfig in project leopard by tanhaichao.

the class TrynbDaoXmlImplTest method parse.

@Test
public void parse() throws IOException, ParserConfigurationException, SAXException {
    InputStream input = this.getClass().getResourceAsStream("trynb.xml");
    List<ErrorConfig> list = errorPageDaoXmlImpl.parse(input);
    // Json.printList(list, "list");
    for (ErrorConfig config : list) {
        System.out.println("config:" + config);
    }
}
Also used : ErrorConfig(io.leopard.mvc.trynb.model.ErrorConfig) InputStream(java.io.InputStream) Test(org.junit.Test)

Aggregations

ErrorConfig (io.leopard.mvc.trynb.model.ErrorConfig)5 ExceptionConfig (io.leopard.mvc.trynb.model.ExceptionConfig)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 ApiException (io.leopard.core.exception.ApiException)1 TrynbInfo (io.leopard.mvc.trynb.model.TrynbInfo)1 InputStream (java.io.InputStream)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 MethodArgumentTypeMismatchException (org.springframework.web.method.annotation.MethodArgumentTypeMismatchException)1 Document (org.w3c.dom.Document)1