Example usage for java.lang SecurityException printStackTrace

List of usage examples for java.lang SecurityException printStackTrace

Introduction

In this page you can find the example usage for java.lang SecurityException printStackTrace.

Prototype

public void printStackTrace(PrintStream s) 

Source Link

Document

Prints this throwable and its backtrace to the specified print stream.

Usage

From source file:jp.go.nict.langrid.servicecontainer.handler.jsonrpc.servlet.JsonRpcServlet.java

/**
 * /* w  ww . j  a  v a  2  s. com*/
 * 
 */
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    ServiceContext sc = new ServletConfigServiceContext(getServletConfig());
    HttpServletRequestParameterContext param = new HttpServletRequestParameterContext(req);
    if (param.getValue("sample") == null && param.getValue("method") != null && getMethodEnabled) {
        doProcess(req, resp);
        return;
    }
    ServiceLoader loader = new ServiceLoader(sc, defaultLoaders);
    String sample = param.getValue("sample");
    if (sample != null) {
        resp.setContentType("text/plain");
        resp.setCharacterEncoding("UTF-8");
        PrintWriter os = resp.getWriter();
        String serviceName = getServiceName(req);
        String method = req.getParameter("method");
        os.println("request:");
        printSampleRequest(loader, serviceName, method, os);
        os.println("");
        os.println("");
        os.println("response:");
        printSampleResponse(loader, serviceName, method, os);
        os.flush();
        return;
    }
    String uri = req.getRequestURI();
    String cp = getServletContext().getContextPath();
    int idx = uri.indexOf(cp);
    if (idx == -1) {
        super.doGet(req, resp);
        return;
    }
    int sidx = uri.indexOf('/', idx + cp.length() + 1);
    if (sidx != -1) {
        resp.sendRedirect(uri.substring(idx, sidx));
        return;
    }

    resp.setContentType("text/html");
    resp.setCharacterEncoding("UTF-8");
    PrintWriter w = resp.getWriter();
    w.println("<html><head>");
    w.println(css);
    w.println(js);
    w.println("</head><body>");
    w.println("<h2>And now... Some JsonRpc Services</h2>");
    w.println("<ul>");
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Set<String> names = new TreeSet<String>();
    try {
        for (String s : loader.listServiceNames()) {
            names.add(s);
        }
        int id = 0;
        for (String s : names) {
            w.print("<li><b>" + s);
            ServiceFactory f = loader.loadServiceFactory(cl, s);
            if (f == null) {
                w.println("<font color=\"red\">(Failed to load service factory(null))</font></b></li>");
                continue;
            }
            Object service = f.getService();
            if (service instanceof StreamingNotifier) {
                w.print("(Streaming ready!)");
            }
            String sdesc = RpcAnnotationUtil.getServiceDescriptions(Service.class, "en");
            if (sdesc != null && sdesc.length() > 0) {
                w.print(" - " + StringEscapeUtils.escapeHtml(sdesc));
            }
            w.print("</b><ul>");
            w.print("<li>interfaces<ul>");
            try {
                Set<Class<?>> visited = new HashSet<Class<?>>();
                for (Class<?> intf : f.getInterfaces()) {
                    if (visited.contains(intf))
                        continue;
                    visited.add(intf);
                    if (StreamingNotifier.class.isAssignableFrom(intf))
                        continue;
                    w.print("<li>" + prettyName(intf));
                    String desc = RpcAnnotationUtil.getServiceDescriptions(intf, "en");
                    if (desc != null && desc.length() > 0) {
                        w.print(" - " + StringEscapeUtils.escapeHtml(desc));
                    }
                    w.print("<ul>");
                    try {
                        Set<Method> methods = new TreeSet<Method>(new Comparator<Method>() {
                            public int compare(Method o1, Method o2) {
                                int r = o1.getName().compareTo(o2.getName());
                                if (r != 0)
                                    return r;
                                return o1.getParameterTypes().length - o2.getParameterTypes().length;
                            }
                        });
                        methods.addAll(Arrays.asList(intf.getMethods()));
                        for (Method m : methods) {
                            if (m.isSynthetic())
                                continue;
                            if ((m.getModifiers() & Modifier.PUBLIC) == 0)
                                continue;
                            printMethod(s, m, getImplementedMethod(service, m), id++, w);
                        }
                    } finally {
                        w.println("</ul></li>");
                    }
                }
            } catch (SecurityException e) {
            } finally {
                w.println("</ul></li>");
            }
            w.print("<li>implementation<ul>");
            if (service != null) {
                w.println("<li>" + prettyName(service.getClass()) + "</li>");
                if (service instanceof AbstractCompositeService) {
                    boolean first = true;
                    for (Pair<Invocation, Class<?>> v : ((AbstractCompositeService) service).invocations()) {
                        if (first) {
                            w.println("<li>invocations<ul>");
                            first = false;
                        }
                        w.println(
                                "<li><b>" + v.getFirst().name() + (v.getFirst().required() ? "(required)" : "")
                                        + "</b>: " + prettyName(v.getSecond()) + "</li>");
                    }
                    if (!first) {
                        w.println("</ul></li>");
                    }
                }
            } else {
                w.println("<li><font color=\"red\"><b>failed to load implementation class.</b></font></li>");
            }
            w.println("</ul></li>");
            w.println("</ul></li>");
            w.println("<br/>");
        }
    } catch (IOException e) {
        w.println("<pre><font color=\"red\">");
        e.printStackTrace(w);
        w.println("</font></pre>");
    }
    w.println("</ul>");
    w.println("</body></html>");
}