Search in sources :

Example 1 with ParseException

use of com.floreysoft.jmte.message.ParseException in project service-proxy by membrane.

the class OAuth2ResourceInterceptor method showPage.

private void showPage(Exchange exc, String state, Object... params) throws Exception {
    String target = StringUtils.defaultString(URLParamUtil.getParams(router.getUriFactory(), exc).get("target"));
    exc.getDestinations().set(0, "/index.html");
    wsi.handleRequest(exc);
    Engine engine = new Engine();
    engine.setErrorHandler(new ErrorHandler() {

        @Override
        public void error(String arg0, Token arg1, Map<String, Object> arg2) throws ParseException {
            log.error(arg0);
        }

        @Override
        public void error(String arg0, Token arg1) throws ParseException {
            log.error(arg0);
        }
    });
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("loginPath", StringEscapeUtils.escapeXml(loginPath));
    // TODO: save original request and restore it when authorized
    String pathQuery = "/";
    String url = auth.getLoginURL(state, publicURL, pathQuery);
    model.put("loginURL", url);
    model.put("target", StringEscapeUtils.escapeXml(target));
    model.put("authid", state);
    for (int i = 0; i < params.length; i += 2) model.put((String) params[i], params[i + 1]);
    exc.getResponse().setBodyContent(engine.transform(exc.getResponse().getBodyAsStringDecoded(), model).getBytes(Constants.UTF_8_CHARSET));
}
Also used : ErrorHandler(com.floreysoft.jmte.ErrorHandler) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Token(com.floreysoft.jmte.token.Token) ParseException(com.floreysoft.jmte.message.ParseException) Engine(com.floreysoft.jmte.Engine)

Example 2 with ParseException

use of com.floreysoft.jmte.message.ParseException in project service-proxy by membrane.

the class LoginDialog method showPage.

private void showPage(Exchange exc, int page, Object... params) throws Exception {
    String target = StringUtils.defaultString(URLParamUtil.getParams(uriFactory, exc).get("target"));
    exc.getDestinations().set(0, "/index.html");
    wsi.handleRequest(exc);
    Engine engine = new Engine();
    engine.setErrorHandler(new ErrorHandler() {

        @Override
        public void error(String arg0, Token arg1, Map<String, Object> arg2) throws ParseException {
            log.error(arg0);
        }

        @Override
        public void error(String arg0, Token arg1) throws ParseException {
            log.error(arg0);
        }
    });
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("action", StringEscapeUtils.escapeXml(path));
    model.put("target", StringEscapeUtils.escapeXml(target));
    if (page == 0)
        model.put("login", true);
    if (page == 1)
        model.put("token", true);
    if (page == 2) {
        model.put("consent", true);
        model.put("action", StringEscapeUtils.escapeXml(path) + "consent");
    }
    for (int i = 0; i < params.length; i += 2) model.put((String) params[i], params[i + 1]);
    exc.getResponse().setBodyContent(engine.transform(exc.getResponse().getBodyAsStringDecoded(), model).getBytes(Constants.UTF_8_CHARSET));
}
Also used : ErrorHandler(com.floreysoft.jmte.ErrorHandler) Token(com.floreysoft.jmte.token.Token) ParseException(com.floreysoft.jmte.message.ParseException) Engine(com.floreysoft.jmte.Engine)

Aggregations

Engine (com.floreysoft.jmte.Engine)2 ErrorHandler (com.floreysoft.jmte.ErrorHandler)2 ParseException (com.floreysoft.jmte.message.ParseException)2 Token (com.floreysoft.jmte.token.Token)2 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1