Example usage for javax.servlet UnavailableException UnavailableException

List of usage examples for javax.servlet UnavailableException UnavailableException

Introduction

In this page you can find the example usage for javax.servlet UnavailableException UnavailableException.

Prototype


public UnavailableException(String msg) 

Source Link

Document

Constructs a new exception with a descriptive message indicating that the servlet is permanently unavailable.

Usage

From source file:com.cws.esolutions.security.filters.SessionAuthenticationFilter.java

public void init(final FilterConfig filterConfig) throws ServletException {
    final String methodName = SessionAuthenticationFilter.CNAME
            + "#init(final FilterConfig filterConfig) throws ServletException";

    if (DEBUG) {/*from  ww  w .  j  a v a2 s  . c om*/
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("FilterConfig: {}", filterConfig);
    }

    ResourceBundle rBundle = null;

    try {
        if (filterConfig.getInitParameter(SessionAuthenticationFilter.FILTER_CONFIG_PARAM_NAME) == null) {
            ERROR_RECORDER.error("Filter configuration not found. Using default !");

            rBundle = ResourceBundle.getBundle(SessionAuthenticationFilter.FILTER_CONFIG_FILE_NAME);
        } else {
            rBundle = ResourceBundle.getBundle(
                    filterConfig.getInitParameter(SessionAuthenticationFilter.FILTER_CONFIG_PARAM_NAME));
        }

        this.loginURI = rBundle.getString(SessionAuthenticationFilter.LOGIN_URI);
        this.passwordURI = rBundle.getString(SessionAuthenticationFilter.PASSWORD_URI);
        this.ignoreURIs = (StringUtils
                .isNotEmpty(rBundle.getString(SessionAuthenticationFilter.IGNORE_URI_LIST)))
                        ? rBundle.getString(SessionAuthenticationFilter.IGNORE_URI_LIST).trim().split(",")
                        : null;

        if (DEBUG) {
            if (this.ignoreURIs != null) {
                for (String str : this.ignoreURIs) {
                    DEBUGGER.debug(str);
                }
            }
        }
    } catch (MissingResourceException mre) {
        ERROR_RECORDER.error(mre.getMessage(), mre);

        throw new UnavailableException(mre.getMessage());
    }
}

From source file:com.zimbra.soap.SoapServlet.java

@Override
public void init() throws ServletException {
    LogFactory.init();//from   www .  jav a2 s.  c  o  m

    String name = getServletName();
    ZimbraLog.soap.info("Servlet " + name + " starting up");
    super.init();

    mEngine = new SoapEngine();

    int i = 0;
    String cname;
    while ((cname = getInitParameter(PARAM_ENGINE_HANDLER + i)) != null) {
        loadHandler(cname);
        i++;
    }

    // See if any extra services were previously added by extensions
    synchronized (sExtraServices) {
        List<DocumentService> services = sExtraServices.get(getServletName());
        for (DocumentService service : services) {
            addService(service);
            i++;
        }
    }

    mEngine.getDocumentDispatcher().clearSoapWhiteList();

    if (i == 0)
        throw new ServletException("Must specify at least one handler " + PARAM_ENGINE_HANDLER + i);

    try {
        Zimbra.startup();
    } catch (OutOfMemoryError e) {
        Zimbra.halt("out of memory", e);
    } catch (Throwable t) {
        ZimbraLog.soap.fatal("Unable to start servlet", t);
        throw new UnavailableException(t.getMessage());
    }
}

From source file:com.cws.esolutions.security.filters.SSLEnforcementFilter.java

public void init(final FilterConfig filterConfig) throws ServletException {
    final String methodName = SSLEnforcementFilter.CNAME
            + "#init(FilterConfig filterConfig) throws ServletException";

    if (DEBUG) {//from w  ww.  j  a v  a 2 s.co  m
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("FilterConfig: {}", filterConfig);
    }

    ResourceBundle rBundle = null;

    try {
        if (filterConfig.getInitParameter(SSLEnforcementFilter.FILTER_CONFIG_PARAM_NAME) == null) {
            ERROR_RECORDER.error("Filter configuration not found. Using default !");

            rBundle = ResourceBundle.getBundle(SSLEnforcementFilter.FILTER_CONFIG_FILE_NAME);
        } else {
            rBundle = ResourceBundle
                    .getBundle(filterConfig.getInitParameter(SSLEnforcementFilter.FILTER_CONFIG_PARAM_NAME));
        }

        this.ignoreHosts = (StringUtils.isNotEmpty(rBundle.getString(SSLEnforcementFilter.IGNORE_HOST_LIST)))
                ? rBundle.getString(SSLEnforcementFilter.IGNORE_HOST_LIST).trim().split(",")
                : null;
        this.ignoreURIs = (StringUtils.isNotEmpty(rBundle.getString(SSLEnforcementFilter.IGNORE_URI_LIST)))
                ? rBundle.getString(SSLEnforcementFilter.IGNORE_HOST_LIST).trim().split(",")
                : null;

        if (DEBUG) {
            if (this.ignoreHosts != null) {
                for (String str : this.ignoreHosts) {
                    DEBUGGER.debug(str);
                }
            }

            if (this.ignoreURIs != null) {
                for (String str : this.ignoreURIs) {
                    DEBUGGER.debug(str);
                }
            }
        }
    } catch (MissingResourceException mre) {
        ERROR_RECORDER.error(mre.getMessage(), mre);

        throw new UnavailableException(mre.getMessage());
    }
}

From source file:com.boylesoftware.web.impl.AbstractRouterConfiguration.java

/**
 * Create new router configuration object.
 *
 * @param sc Servlet context./*from   ww  w.  ja va  2s.  c  o m*/
 * @param appServices The application services.
 * @param argHandlerProvider Controller method argument handler provider.
 * @param viewSender View sender.
 *
 * @throws UnavailableException If configuration is incorrect.
 */
public AbstractRouterConfiguration(final ServletContext sc, final ApplicationServices appServices,
        final ControllerMethodArgHandlerProvider argHandlerProvider, final ViewSender viewSender)
        throws UnavailableException {

    this.webapp = appServices.getApplication();

    final RoutesBuilder routesBuilder = new RoutesBuilder(sc, argHandlerProvider, viewSender);
    this.buildRoutes(sc, routesBuilder);
    this.mappings = routesBuilder.getRoutes();

    this.loginPageURI = routesBuilder.getLoginPageURI();

    final Pattern protectedURIPattern = routesBuilder.getProtectedURIPattern();
    final Pattern publicURIPattern = routesBuilder.getPublicURIPattern();
    this.protectedURIPattern = (protectedURIPattern != null ? protectedURIPattern
            : (publicURIPattern != null ? ANY_URI : NO_URI));
    this.publicURIPattern = (publicURIPattern != null ? publicURIPattern
            : (protectedURIPattern != null ? NO_URI : ANY_URI));
    final String fullLoginPageURI = (this.loginPageURI != null
            ? StringUtils.emptyIfNull(sc.getContextPath()) + this.loginPageURI
            : null);
    if (fullLoginPageURI != null) {
        if (this.protectedURIPattern.matcher(fullLoginPageURI).matches()
                && !this.publicURIPattern.matcher(fullLoginPageURI).matches())
            throw new UnavailableException("Provided login page URI"
                    + " requires an authenticated user. Check the protected and" + " public URI patterns.");
    }

    final int numMappings = this.mappings.length;
    this.mappingsById = new HashMap<>(numMappings);
    for (int i = 0; i < numMappings; i++) {
        RouteImpl mapping = this.mappings[i];
        if ((fullLoginPageURI != null) && mapping.getURIPattern().matcher(fullLoginPageURI).matches()) {
            switch (mapping.getSecurityMode()) {
            case DEFAULT:
                this.mappings[i] = mapping = new RouteImpl(mapping, SecurityMode.FORCE_SSL);
                break;
            case FORCE_SSL:
                break;
            case FORCE_REQUIRE_AUTH:
                throw new UnavailableException("Provided login page URI"
                        + " requires an authenticated user. Check the mapping's" + " security mode.");
            }
        }
        if (this.mappingsById.put(mapping.getId(), mapping) != null)
            throw new UnavailableException("More than one mapping share route id " + mapping.getId() + ".");
    }

    this.routerRequestPool = new FastPool<>(new PoolableObjectFactory<RouterRequestImpl>() {

        @Override
        public RouterRequestImpl makeNew(final FastPool<RouterRequestImpl> pool, final int pooledObjectId) {

            return new RouterRequestImpl(pool, pooledObjectId, appServices);
        }
    }, "RouterRequestsPool");
}

From source file:de.ecw.zabos.Globals.java

/**
 * Lizenz-Datei einlesen//from w w  w . ja va  2  s.co m
 * 
 * @throws UnavailableException
 *             Wenn das Lizenz-Bean {@link SpringContext#BEAN_LICENSE} nicht
 *             definiert ist
 * @throws UnavailableException
 *             Wenn die Lizenz-Datei ungltig oder nicht vorhanden ist
 * @throws UnavailableException
 *             Wenn die Lizenz abgelaufen ist
 */
private static void readLicense() throws UnavailableException {
    License license = (License) SpringContext.getInstance().getBean(SpringContext.BEAN_LICENSE, License.class);

    if (license == null) {
        System.err.println("[---] Es wurde kein Lizenz-Bean definiert!");
        throw new UnavailableException("Es wurde kein Lizenz-Bean definiert!");
    }

    if (!license.readLicense()) {
        // 2007-05-31 CKL: Informationen auf stderr ausgeben
        System.err.println("[---] Die Lizenzdatei ist ungueltig oder nicht vorhanden!");

        throw new UnavailableException("Die Lizenzdatei ist ungueltig oder nicht vorhanden!");
    } else {
        if (!license.isStillValid()) {
            // 2007-05-31 CKL: Informationen auf stderr ausgeben
            System.err.println(
                    "[---] Die Lizenz im Verzeichnis " + System.getProperty("user.dir") + " ist abgelaufen!");

            throw new UnavailableException(
                    "Die Lizenz im Verzeichnis " + System.getProperty("user.dir") + "ist abgelaufen!");
        }
    }
}

From source file:net.lightbody.bmp.proxy.jetty.servlet.Dump.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    request.setAttribute("Dump", this);
    request.setCharacterEncoding("ISO_8859_1");
    getServletContext().setAttribute("Dump", this);

    String info = request.getPathInfo();
    if (info != null && info.endsWith("Exception")) {
        try {/*from w  w  w. ja  v  a 2 s . c  o m*/
            throw (Throwable) (Loader.loadClass(this.getClass(), info.substring(1)).newInstance());
        } catch (Throwable th) {
            throw new ServletException(th);
        }
    }

    String redirect = request.getParameter("redirect");
    if (redirect != null && redirect.length() > 0) {
        response.getOutputStream().println("THIS SHOULD NOT BE SEEN!");
        response.sendRedirect(redirect);
        response.getOutputStream().println("THIS SHOULD NOT BE SEEN!");
        return;
    }

    String error = request.getParameter("error");
    if (error != null && error.length() > 0) {
        response.getOutputStream().println("THIS SHOULD NOT BE SEEN!");
        response.sendError(Integer.parseInt(error));
        response.getOutputStream().println("THIS SHOULD NOT BE SEEN!");
        return;
    }

    String length = request.getParameter("length");
    if (length != null && length.length() > 0) {
        response.setContentLength(Integer.parseInt(length));
    }

    String buffer = request.getParameter("buffer");
    if (buffer != null && buffer.length() > 0)
        response.setBufferSize(Integer.parseInt(buffer));

    request.setCharacterEncoding("UTF-8");
    response.setContentType("text/html");

    if (info != null && info.indexOf("Locale/") >= 0) {
        try {
            String locale_name = info.substring(info.indexOf("Locale/") + 7);
            Field f = java.util.Locale.class.getField(locale_name);
            response.setLocale((Locale) f.get(null));
        } catch (Exception e) {
            LogSupport.ignore(log, e);
            response.setLocale(Locale.getDefault());
        }
    }

    String cn = request.getParameter("cookie");
    String cv = request.getParameter("value");
    String v = request.getParameter("version");
    if (cn != null && cv != null) {
        Cookie cookie = new Cookie(cn, cv);
        cookie.setComment("Cookie from dump servlet");
        if (v != null) {
            cookie.setMaxAge(300);
            cookie.setPath("/");
            cookie.setVersion(Integer.parseInt(v));
        }
        response.addCookie(cookie);
    }

    String pi = request.getPathInfo();
    if (pi != null && pi.startsWith("/ex")) {
        OutputStream out = response.getOutputStream();
        out.write("</H1>This text should be reset</H1>".getBytes());
        if ("/ex0".equals(pi))
            throw new ServletException("test ex0", new Throwable());
        if ("/ex1".equals(pi))
            throw new IOException("test ex1");
        if ("/ex2".equals(pi))
            throw new UnavailableException("test ex2");
        if ("/ex3".equals(pi))
            throw new HttpException(501);
    }

    PrintWriter pout = response.getWriter();
    Page page = null;

    try {
        page = new Page();
        page.title("Dump Servlet");

        page.add(new Heading(1, "Dump Servlet"));
        Table table = new Table(0).cellPadding(0).cellSpacing(0);
        page.add(table);
        table.newRow();
        table.addHeading("getMethod:&nbsp;").cell().right();
        table.addCell("" + request.getMethod());
        table.newRow();
        table.addHeading("getContentLength:&nbsp;").cell().right();
        table.addCell(Integer.toString(request.getContentLength()));
        table.newRow();
        table.addHeading("getContentType:&nbsp;").cell().right();
        table.addCell("" + request.getContentType());
        table.newRow();
        table.addHeading("getCharacterEncoding:&nbsp;").cell().right();
        table.addCell("" + request.getCharacterEncoding());
        table.newRow();
        table.addHeading("getRequestURI:&nbsp;").cell().right();
        table.addCell("" + request.getRequestURI());
        table.newRow();
        table.addHeading("getRequestURL:&nbsp;").cell().right();
        table.addCell("" + request.getRequestURL());
        table.newRow();
        table.addHeading("getContextPath:&nbsp;").cell().right();
        table.addCell("" + request.getContextPath());
        table.newRow();
        table.addHeading("getServletPath:&nbsp;").cell().right();
        table.addCell("" + request.getServletPath());
        table.newRow();
        table.addHeading("getPathInfo:&nbsp;").cell().right();
        table.addCell("" + request.getPathInfo());
        table.newRow();
        table.addHeading("getPathTranslated:&nbsp;").cell().right();
        table.addCell("" + request.getPathTranslated());
        table.newRow();
        table.addHeading("getQueryString:&nbsp;").cell().right();
        table.addCell("" + request.getQueryString());

        table.newRow();
        table.addHeading("getProtocol:&nbsp;").cell().right();
        table.addCell("" + request.getProtocol());
        table.newRow();
        table.addHeading("getScheme:&nbsp;").cell().right();
        table.addCell("" + request.getScheme());
        table.newRow();
        table.addHeading("getServerName:&nbsp;").cell().right();
        table.addCell("" + request.getServerName());
        table.newRow();
        table.addHeading("getServerPort:&nbsp;").cell().right();
        table.addCell("" + Integer.toString(request.getServerPort()));
        table.newRow();
        table.addHeading("getLocalName:&nbsp;").cell().right();
        table.addCell("" + request.getLocalName());
        table.newRow();
        table.addHeading("getLocalAddr:&nbsp;").cell().right();
        table.addCell("" + request.getLocalAddr());
        table.newRow();
        table.addHeading("getLocalPort:&nbsp;").cell().right();
        table.addCell("" + Integer.toString(request.getLocalPort()));
        table.newRow();
        table.addHeading("getRemoteUser:&nbsp;").cell().right();
        table.addCell("" + request.getRemoteUser());
        table.newRow();
        table.addHeading("getRemoteAddr:&nbsp;").cell().right();
        table.addCell("" + request.getRemoteAddr());
        table.newRow();
        table.addHeading("getRemoteHost:&nbsp;").cell().right();
        table.addCell("" + request.getRemoteHost());
        table.newRow();
        table.addHeading("getRemotePort:&nbsp;").cell().right();
        table.addCell("" + request.getRemotePort());
        table.newRow();
        table.addHeading("getRequestedSessionId:&nbsp;").cell().right();
        table.addCell("" + request.getRequestedSessionId());
        table.newRow();
        table.addHeading("isSecure():&nbsp;").cell().right();
        table.addCell("" + request.isSecure());

        table.newRow();
        table.addHeading("isUserInRole(admin):&nbsp;").cell().right();
        table.addCell("" + request.isUserInRole("admin"));

        table.newRow();
        table.addHeading("getLocale:&nbsp;").cell().right();
        table.addCell("" + request.getLocale());

        Enumeration locales = request.getLocales();
        while (locales.hasMoreElements()) {
            table.newRow();
            table.addHeading("getLocales:&nbsp;").cell().right();
            table.addCell(locales.nextElement());
        }

        table.newRow();
        table.newHeading().cell().nest(new Font(2, true)).add("<BR>Other HTTP Headers")
                .attribute("COLSPAN", "2").left();
        Enumeration h = request.getHeaderNames();
        String name;
        while (h.hasMoreElements()) {
            name = (String) h.nextElement();

            Enumeration h2 = request.getHeaders(name);
            while (h2.hasMoreElements()) {
                String hv = (String) h2.nextElement();
                table.newRow();
                table.addHeading(name + ":&nbsp;").cell().right();
                table.addCell(hv);
            }
        }

        table.newRow();
        table.newHeading().cell().nest(new Font(2, true)).add("<BR>Request Parameters")
                .attribute("COLSPAN", "2").left();
        h = request.getParameterNames();
        while (h.hasMoreElements()) {
            name = (String) h.nextElement();
            table.newRow();
            table.addHeading(name + ":&nbsp;").cell().right();
            table.addCell(request.getParameter(name));
            String[] values = request.getParameterValues(name);
            if (values == null) {
                table.newRow();
                table.addHeading(name + " Values:&nbsp;").cell().right();
                table.addCell("NULL!!!!!!!!!");
            } else if (values.length > 1) {
                for (int i = 0; i < values.length; i++) {
                    table.newRow();
                    table.addHeading(name + "[" + i + "]:&nbsp;").cell().right();
                    table.addCell(values[i]);
                }
            }
        }

        table.newRow();
        table.newHeading().cell().nest(new Font(2, true)).add("<BR>Cookies").attribute("COLSPAN", "2").left();
        Cookie[] cookies = request.getCookies();
        for (int i = 0; cookies != null && i < cookies.length; i++) {
            Cookie cookie = cookies[i];

            table.newRow();
            table.addHeading(cookie.getName() + ":&nbsp;").cell().attribute("VALIGN", "TOP").right();
            table.addCell(cookie.getValue());
        }

        /* ------------------------------------------------------------ */
        table.newRow();
        table.newHeading().cell().nest(new Font(2, true)).add("<BR>Request Attributes")
                .attribute("COLSPAN", "2").left();
        Enumeration a = request.getAttributeNames();
        while (a.hasMoreElements()) {
            name = (String) a.nextElement();
            table.newRow();
            table.addHeading(name + ":&nbsp;").cell().attribute("VALIGN", "TOP").right();
            table.addCell("<pre>" + toString(request.getAttribute(name)) + "</pre>");
        }

        /* ------------------------------------------------------------ */
        table.newRow();
        table.newHeading().cell().nest(new Font(2, true)).add("<BR>Servlet InitParameters")
                .attribute("COLSPAN", "2").left();
        a = getInitParameterNames();
        while (a.hasMoreElements()) {
            name = (String) a.nextElement();
            table.newRow();
            table.addHeading(name + ":&nbsp;").cell().attribute("VALIGN", "TOP").right();
            table.addCell("<pre>" + toString(getInitParameter(name)) + "</pre>");
        }

        table.newRow();
        table.newHeading().cell().nest(new Font(2, true)).add("<BR>Context InitParameters")
                .attribute("COLSPAN", "2").left();
        a = getServletContext().getInitParameterNames();
        while (a.hasMoreElements()) {
            name = (String) a.nextElement();
            table.newRow();
            table.addHeading(name + ":&nbsp;").cell().attribute("VALIGN", "TOP").right();
            table.addCell("<pre>" + toString(getServletContext().getInitParameter(name)) + "</pre>");
        }

        table.newRow();
        table.newHeading().cell().nest(new Font(2, true)).add("<BR>Context Attributes")
                .attribute("COLSPAN", "2").left();
        a = getServletContext().getAttributeNames();
        while (a.hasMoreElements()) {
            name = (String) a.nextElement();
            table.newRow();
            table.addHeading(name + ":&nbsp;").cell().attribute("VALIGN", "TOP").right();
            table.addCell("<pre>" + toString(getServletContext().getAttribute(name)) + "</pre>");
        }

        if (request.getContentType() != null && request.getContentType().startsWith("multipart/form-data")
                && request.getContentLength() < 1000000) {
            MultiPartRequest multi = new MultiPartRequest(request);
            String[] parts = multi.getPartNames();

            table.newRow();
            table.newHeading().cell().nest(new Font(2, true)).add("<BR>Multi-part content")
                    .attribute("COLSPAN", "2").left();
            for (int p = 0; p < parts.length; p++) {
                name = parts[p];
                table.newRow();
                table.addHeading(name + ":&nbsp;").cell().attribute("VALIGN", "TOP").right();
                table.addCell("<pre>" + multi.getString(parts[p]) + "</pre>");
            }
        }

        String res = request.getParameter("resource");
        if (res != null && res.length() > 0) {
            table.newRow();
            table.newHeading().cell().nest(new Font(2, true)).add("<BR>Get Resource: " + res)
                    .attribute("COLSPAN", "2").left();

            table.newRow();
            table.addHeading("this.getClass():&nbsp;").cell().right();
            table.addCell("" + this.getClass().getResource(res));

            table.newRow();
            table.addHeading("this.getClass().getClassLoader():&nbsp;").cell().right();
            table.addCell("" + this.getClass().getClassLoader().getResource(res));

            table.newRow();
            table.addHeading("Thread.currentThread().getContextClassLoader():&nbsp;").cell().right();
            table.addCell("" + Thread.currentThread().getContextClassLoader().getResource(res));

            table.newRow();
            table.addHeading("getServletContext():&nbsp;").cell().right();
            try {
                table.addCell("" + getServletContext().getResource(res));
            } catch (Exception e) {
                table.addCell("" + e);
            }
        }

        /* ------------------------------------------------------------ */
        page.add(Break.para);
        page.add(new Heading(1, "Request Wrappers"));
        ServletRequest rw = request;
        int w = 0;
        while (rw != null) {
            page.add((w++) + ": " + rw.getClass().getName() + "<br/>");
            if (rw instanceof HttpServletRequestWrapper)
                rw = ((HttpServletRequestWrapper) rw).getRequest();
            else if (rw instanceof ServletRequestWrapper)
                rw = ((ServletRequestWrapper) rw).getRequest();
            else
                rw = null;
        }

        page.add(Break.para);
        page.add(new Heading(1, "International Characters"));
        page.add("Directly encoced:  Drst<br/>");
        page.add("HTML reference: D&uuml;rst<br/>");
        page.add("Decimal (252) 8859-1: D&#252;rst<br/>");
        page.add("Hex (xFC) 8859-1: D&#xFC;rst<br/>");
        page.add(
                "Javascript unicode (00FC) : <script language='javascript'>document.write(\"D\u00FCrst\");</script><br/>");
        page.add(Break.para);
        page.add(new Heading(1, "Form to generate GET content"));
        TableForm tf = new TableForm(response.encodeURL(getURI(request)));
        tf.method("GET");
        tf.addTextField("TextField", "TextField", 20, "value");
        tf.addButton("Action", "Submit");
        page.add(tf);

        page.add(Break.para);
        page.add(new Heading(1, "Form to generate POST content"));
        tf = new TableForm(response.encodeURL(getURI(request)));
        tf.method("POST");
        tf.addTextField("TextField", "TextField", 20, "value");
        Select select = tf.addSelect("Select", "Select", true, 3);
        select.add("ValueA");
        select.add("ValueB1,ValueB2");
        select.add("ValueC");
        tf.addButton("Action", "Submit");
        page.add(tf);

        page.add(new Heading(1, "Form to upload content"));
        tf = new TableForm(response.encodeURL(getURI(request)));
        tf.method("POST");
        tf.attribute("enctype", "multipart/form-data");
        tf.addFileField("file", "file");
        tf.addButton("Upload", "Upload");
        page.add(tf);

        page.add(new Heading(1, "Form to get Resource"));
        tf = new TableForm(response.encodeURL(getURI(request)));
        tf.method("POST");
        tf.addTextField("resource", "resource", 20, "");
        tf.addButton("Action", "getResource");
        page.add(tf);

    } catch (Exception e) {
        log.warn(LogSupport.EXCEPTION, e);
    }

    page.write(pout);

    String data = request.getParameter("data");
    if (data != null && data.length() > 0) {
        int d = Integer.parseInt(data);
        while (d > 0) {
            pout.println("1234567890123456789012345678901234567890123456789\n");
            d = d - 50;

        }
    }

    pout.close();

    if (pi != null) {
        if ("/ex4".equals(pi))
            throw new ServletException("test ex4", new Throwable());
        if ("/ex5".equals(pi))
            throw new IOException("test ex5");
        if ("/ex6".equals(pi))
            throw new UnavailableException("test ex6");
        if ("/ex7".equals(pi))
            throw new HttpException(501);
    }

    request.getInputStream().close();

}

From source file:com.boylesoftware.web.impl.RouteImpl.java

/**
 * Create new mapping./*  w w  w .  j  a v a2 s  . c o m*/
 *
 * @param sc Servlet context.
 * @param id Route id, or {@code null} to auto-generate based on the URI
 * pattern.
 * @param uriPattern Request URI pattern, which is a server root relative
 * URI that can optionally contain URI parameter placeholders. Each
 * placeholder is an expression surrounded by curly braces. Inside curly
 * braces there is the parameter name and optionally, separated by a colon,
 * the value regular expression. The regular expression must not contain any
 * capturing groups and if the expression contains curly braces, they must
 * be balanced. If the parameter name is empty, the value is not converted
 * to a request parameter. If the regular expression is unspecified, regular
 * expression that matches anything except "/" is used. Each URI parameter
 * is converted to a regular request parameter with the specified name.
 * @param securityMode Security mode.
 * @param commonScript Additional logic associated with the mapping, or
 * {@code null} if none. If specified, the script is executed each time for
 * the matched request before the controller is called and the view is sent
 * back to the client.
 * @param controller Controller, or {@code null} if no controller is
 * associated with the mapped resource.
 * @param argHandlerProvider Controller method argument handler provider to
 * use.
 * @param viewIdPattern Mapped resource view id. The id may contain
 * placeholders for request attributes and parameters in curly braces with
 * the attribute or parameter name inside. Attributes take precedence over
 * parameters.
 * @param viewSender View sender to use to send the view to the client.
 * @param viewScript Additional logic associated with the view, or
 * {@code null} if none. If specified, the script is executed each time
 * before the view is sent to the client. The script's purpose it to prepare
 * data used by the view.
 *
 * @throws UnavailableException If an error happens.
 */
RouteImpl(final ServletContext sc, final String id, final String uriPattern, final SecurityMode securityMode,
        final Script commonScript, final Object controller,
        final ControllerMethodArgHandlerProvider argHandlerProvider, final String viewIdPattern,
        final ViewSender viewSender, final Script viewScript) throws UnavailableException {

    // parse URI pattern and template
    final StringBuilder uriTemplateSB = new StringBuilder();
    final StringBuilder uriPatternSB = new StringBuilder();
    final List<String> uriParamNamesList = new ArrayList<>();
    final StringBuilder paramNameSB = new StringBuilder();
    final StringBuilder paramPatternSB = new StringBuilder();
    final int patternLen = uriPattern.length();
    uriPatternSB.append("\\Q");
    for (int cInd = 0; cInd < patternLen; cInd++) {
        final char c = uriPattern.charAt(cInd);
        if (c == '{') {

            try {
                paramNameSB.setLength(0);
                paramPatternSB.setLength(0);
                StringBuilder curSB = paramNameSB;
                int balance = 1;
                while (balance > 0) {
                    final char c1 = uriPattern.charAt(++cInd);
                    switch (c1) {
                    case '{':
                        balance++;
                        curSB.append(c1);
                        break;
                    case '}':
                        if (--balance > 0)
                            curSB.append(c1);
                        break;
                    case ':':
                        if (curSB != paramPatternSB)
                            curSB = paramPatternSB;
                        else
                            curSB.append(c1);
                        break;
                    default:
                        curSB.append(c1);
                    }
                }
            } catch (final IndexOutOfBoundsException e) {
                LogFactory.getLog(this.getClass()).error("error parsing mapping URI pattern", e);
                throw new UnavailableException("Unbalanced curly braces in URI pattern \"" + uriPattern
                        + "\" at position " + cInd + ".");
            }

            uriParamNamesList.add(paramNameSB.length() > 0 ? paramNameSB.toString() : null);

            uriPatternSB.append("\\E(").append(paramPatternSB.length() > 0 ? paramPatternSB : "[^/]+")
                    .append(")\\Q");

            uriTemplateSB.append("%");

        } else { // character outside parameter placeholder
            uriPatternSB.append(c);
            uriTemplateSB.append(c);
        }
    }
    uriPatternSB.append("\\E");
    this.uriPattern = Pattern.compile(uriPatternSB.toString());
    this.uriParamNames = uriParamNamesList.toArray(new String[uriParamNamesList.size()]);
    this.uriTemplate = uriTemplateSB.toString();

    // route id
    this.id = (id != null ? id
            : this.uriTemplate.substring(StringUtils.emptyIfNull(sc.getContextPath()).length()));

    // save security mode
    this.securityMode = securityMode;

    // save the script
    this.script = commonScript;

    // create controller handler
    this.controllerHandler = (controller != null ? new ControllerHandlerImpl(sc, controller, argHandlerProvider)
            : null);

    // create view handler
    this.viewHandler = new ViewHandlerImpl(viewIdPattern, viewScript, viewSender);

    // initially the mapping has not been matched
    this.numMatched = new AtomicLong();
}

From source file:de.ecw.zabos.Globals.java

/**
 * Initialisierung das Bean {@link SpringContext#BEAN_DB_RESOURCE}, Klasse
 * {@link DBResource}//from ww  w.  ja v  a2s .c  o m
 * 
 * @throws UnavailableException
 *             Falls das Bean nicht definierte wurde
 */
private static void initDatabase() throws UnavailableException {
    if ((dbresource = (DBResource) SpringContext.getInstance().getBean(SpringContext.BEAN_DB_RESOURCE,
            DBResource.class)) == null) {
        throw new UnavailableException("Haupt-Datenbankverbindung wurde nicht definiert");
    }
}

From source file:net.lightbody.bmp.proxy.jetty.jetty.servlet.Invoker.java

protected void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // Get the requested path and info
    boolean included = false;
    String servlet_path = (String) request.getAttribute(Dispatcher.__INCLUDE_SERVLET_PATH);
    if (servlet_path == null)
        servlet_path = request.getServletPath();
    else//from w w w.  j  a va  2s . c  o  m
        included = true;
    String path_info = (String) request.getAttribute(Dispatcher.__INCLUDE_PATH_INFO);
    if (path_info == null)
        path_info = request.getPathInfo();

    // Get the servlet class
    String servlet = path_info;
    if (servlet == null || servlet.length() <= 1) {
        response.sendError(404);
        return;
    }

    int i0 = servlet.charAt(0) == '/' ? 1 : 0;
    int i1 = servlet.indexOf('/', i0);
    servlet = i1 < 0 ? servlet.substring(i0) : servlet.substring(i0, i1);

    // look for a named holder
    ServletHolder holder = _servletHandler.getServletHolder(servlet);
    if (holder != null) {
        // Add named servlet mapping
        _servletHandler.addServletHolder(holder);
        _servletHandler.mapPathToServlet(URI.addPaths(servlet_path, servlet) + "/*", holder.getName());
    } else {
        // look for a class mapping
        if (servlet.endsWith(".class"))
            servlet = servlet.substring(0, servlet.length() - 6);
        if (servlet == null || servlet.length() == 0) {
            response.sendError(404);
            return;
        }

        synchronized (_servletHandler) {
            // find the entry for the invoker
            if (_invokerEntry == null)
                _invokerEntry = _servletHandler.getHolderEntry(servlet_path);

            // Check for existing mapping (avoid threaded race).
            String path = URI.addPaths(servlet_path, servlet);
            Map.Entry entry = _servletHandler.getHolderEntry(path);

            if (entry != null && entry != _invokerEntry) {
                // Use the holder
                holder = (ServletHolder) entry.getValue();
            } else {
                // Make a holder
                holder = new ServletHolder(_servletHandler, servlet, servlet);

                if (_parameters != null)
                    holder.putAll(_parameters);

                try {
                    holder.start();
                } catch (Exception e) {
                    log.debug(LogSupport.EXCEPTION, e);
                    throw new UnavailableException(e.toString());
                }

                // Check it is from an allowable classloader
                if (!_nonContextServlets) {
                    Object s = holder.getServlet();

                    if (_servletHandler.getClassLoader() != s.getClass().getClassLoader()) {
                        holder.stop();
                        log.warn("Dynamic servlet " + s + " not loaded from context "
                                + request.getContextPath());
                        throw new UnavailableException("Not in context");
                    }
                }

                // Add the holder for all the possible paths
                if (_verbose)
                    log("Dynamic load '" + servlet + "' at " + path);
                _servletHandler.addServletHolder(holder);
                _servletHandler.mapPathToServlet(path + "/*", holder.getName());
                _servletHandler.mapPathToServlet(path + ".class/*", holder.getName());
            }
        }

    }

    if (holder != null)
        holder.handle(new Request(request, included, servlet, servlet_path, path_info), response);
    else
        response.sendError(404);

}

From source file:de.ecw.zabos.license.License.java

public License(Resource _licensePath) throws UnavailableException {
    setLicensePath(_licensePath);// ww  w .ja v  a 2  s . c om

    if (!readLicense()) {
        throw new UnavailableException("Die Lizenz-Datei konnte nicht geladen werden");
    }
}