Example usage for javax.servlet ServletException ServletException

List of usage examples for javax.servlet ServletException ServletException

Introduction

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

Prototype


public ServletException(Throwable rootCause) 

Source Link

Document

Constructs a new servlet exception when the servlet needs to throw an exception and include a message about the "root cause" exception that interfered with its normal operation.

Usage

From source file:sk.openhouse.web.VelocityTilesView.java

@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    /* add spring macro helpers */
    if (this.exposeSpringMacroHelpers) {
        if (model.containsKey(SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE)) {
            throw new ServletException(
                    "Cannot expose bind macro helper '" + SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE
                            + "' because of an existing model object of the same name");
        }//from  ww w  .j ava 2 s .c om
        // Expose RequestContext instance for Spring macros.
        model.put(SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE,
                new RequestContext(request, response, getServletContext(), model));
    }

    super.renderMergedOutputModel(model, request, response);
}

From source file:com.predic8.membrane.servlet.embedded.MembraneServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    try {/*from w  w w .  ja  v  a2s  .co m*/
        appCtx = new BaseLocationXmlWebApplicationContext();

        log.debug("loading beans configuration from: " + getProxiesXmlLocation(config));
        router = RouterUtil.initializeRoutersFromSpringWebContext(appCtx, config.getServletContext(),
                getProxiesXmlLocation(config));
        if (router == null)
            throw new RuntimeException(
                    "No <router> with a <servletTransport> was found. To use <router> with <transport>, use MembraneServletContextListener instead of MembraneServlet.");

    } catch (Exception e) {
        throw new ServletException(e);
    }
}

From source file:com.voa.weixin.filter.AuthorFilter.java

@Override
public void init() throws ServletException {
    token = getInitParameter("TOKEN");
    logger.debug("token : " + token);
    Carp.ROOTPATH = getServletContext().getRealPath("/") + File.separator + "WEB-INF" + File.separator;

    HandlerManager.getInstance();//ww  w.j  av a2  s. co m
    SessionManager.getInstance();
    try {
        System.out.println("1");
        WeixinSessionFactory.getInstanc().init();
        System.out.println("2");
        Carp.getInstance().init();
        System.out.println("3");
    } catch (Exception e) {
        throw new ServletException(e);
    }
}

From source file:hudson.util.MultipartFormDataParser.java

public MultipartFormDataParser(HttpServletRequest request) throws ServletException {
    try {/* w ww  .  ja va2  s  .  c  om*/
        for (FileItem fi : (List<FileItem>) upload.parseRequest(request))
            byName.put(fi.getFieldName(), fi);
    } catch (FileUploadException e) {
        throw new ServletException(e);
    }
}

From source file:com.vaadin.terminal.gwt.server.SpringApplicationOSGiServlet.java

@Override
public void init(ServletConfig servletConfig) throws ServletException {
    // TODO Auto-generated method stub
    super.init(servletConfig);

    applicationParam = servletConfig.getInitParameter("application");

    if (applicationParam == null) {
        throw new ServletException("Application not specified in servlet parameters");
    }//from  w  w  w .  j av  a 2  s  . c o m

    versionParam = getInitParameter("version");

    if (versionParam == null) {
        throw new ServletException("Bundle Version not specified in servlet parameters");
    }

    beanParam = getInitParameter("bean");

    if (beanParam == null) {
        throw new ServletException("Bean Name not specified in servlet parameters");
    }
}

From source file:com.mirth.connect.server.servlets.UsageServlet.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {/*from   w w w .  j  a v a 2s  .  co m*/
        if (!isUserLoggedIn(request)) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
        } else {
            PrintWriter out = response.getWriter();
            ObjectXMLSerializer serializer = ObjectXMLSerializer.getInstance();
            Operation operation = Operations.getOperation(request.getParameter("op"));
            UsageController usageController = ControllerFactory.getFactory().createUsageController();

            if (operation.equals(Operations.USAGE_DATA_GET)) {
                response.setContentType(TEXT_PLAIN);
                if (isUserAuthorized(request, null)) {
                    serializer.serialize(usageController.createUsageStats(true), out);
                } else {
                    response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
                }
            }
        }
    } catch (RuntimeIOException rio) {
        logger.debug(rio);
    } catch (Throwable t) {
        logger.debug(ExceptionUtils.getStackTrace(t));
        throw new ServletException(t);
    }
}

From source file:XsltDomServlet.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    Document doc = dom.createDocument("", "parameters", null);
    Element parameters = doc.getDocumentElement();

    parameters.setAttribute("title", "XSLT DOM Servlet");
    Enumeration parameterNames = request.getParameterNames();
    while (parameterNames.hasMoreElements()) {
        String parameterName = parameterNames.nextElement().toString();
        Element parameter = doc.createElement("parameter");
        parameters.appendChild(parameter);
        parameter.setAttribute("name", parameterName);
        parameter.appendChild(doc.createTextNode(request.getParameter(parameterName)));
    }//  w  w  w . j a v  a2s  . c om

    DOMSource domSource = new DOMSource(doc);
    StreamResult streamResult = new StreamResult(response.getWriter());

    try {
        transformer.transform(domSource, streamResult);
    } catch (TransformerException te) {
        throw new ServletException(te);
    }
}

From source file:com.legstar.host.servlet.InitiatorServlet.java

/**
 * Initialization of the servlet. Loads configuration file and creates an
 * instance of the engine handler.//  ww w .  ja v  a2s .  com
 *
 * @param config the complete configuration hierarchy
 * @throws ServletException if an error occurs
 */
public void init(final ServletConfig config) throws ServletException {
    String configFileName = config.getInitParameter(CONFIG_PARAM);
    if (configFileName == null || configFileName.length() == 0) {
        throw new ServletException("Web.xml does not contain the " + CONFIG_PARAM + " parameter.");
    }

    LOG.info("Initializing with " + configFileName + " configuration file.");

    try {
        LegStarConfigCommons legStarConfig = new LegStarConfigCommons(configFileName);
        EngineHandler serverHandler = new EngineHandler(legStarConfig.getPoolingEngineConfig());

        serverHandler.init();
        ServletContext servletContext = config.getServletContext();
        servletContext.setAttribute(ENGINE_HANDLER_ID, serverHandler);

    } catch (EngineStartupException e) {
        LOG.error("Failed to start engine.", e);
        throw new ServletException(e);
    } catch (LegStarConfigurationException e) {
        LOG.error("Failed to start engine.", e);
        throw new ServletException(e);
    }
}

From source file:com.sri.save.florahttp.FloraHttpServlet.java

@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    if (request.getMethod().equals("OPTIONS")) {
        baseRequest.setHandled(true);/*w w w  . jav  a2 s  .  c  o  m*/
        HttpUtil.corsOptions(request, response, true);
        return;
    }

    baseRequest.setHandled(true);
    PrintWriter out = response.getWriter();
    response.setContentType("application/json");
    response.setHeader("Access-Control-Allow-Origin", "*"); // allows CORS

    // Dispatch the call to the Flora JSON server
    String method = request.getParameter("method");
    if (method == null) {
        throw new ServletException("Missing method parameter");
    } else if (method.equals("loadFile")) { // perhaps this should be done using POST
        String filename = request.getParameter("filename");
        try {
            florajson.loadFile(filename);
            out.print("true");
        } catch (FloraJsonServerException ex) {
            throw new ServletException(ex.getMessage());
        }
    } else if (method.equals("getTaxonomyRoots")) {
        try {
            ArrayNode result = florajson.getRootClasses();
            out.print(result.toString());
        } catch (FloraJsonServerException ex) {
            throw new ServletException(ex.getMessage());
        }
    } else if (method.equals("getSubClasses")) {
        String id = request.getParameter("id");
        try {
            ObjectNode result = florajson.getSubClasses(id);
            out.print(result.toString());
        } catch (FloraJsonServerException ex) {
            throw new ServletException(ex.getMessage());
        }
    } else if (method.equals("getClassDetails")) {
        String id = request.getParameter("id");
        try {
            ObjectNode result = florajson.getClassDetails(id);
            out.print(result.toString());
        } catch (FloraJsonServerException ex) {
            throw new ServletException(ex.getMessage());
        }
    } else if (method.equals("query")) {
        String qstring = request.getParameter("queryString");
        try {
            ObjectNode result = florajson.query(qstring);
            out.print(result.toString());
        } catch (FloraJsonServerException ex) {
            throw new ServletException(ex.getMessage());
        }
    } else
        throw new ServletException("Unrecognized method: " + method);
}

From source file:org.fosstrak.ale.server.persistence.impl.PersistenceInitImpl.java

@Override
public void init(ServletContext servletContext) throws ServletException {
    try {//  w  w  w .j a v a2  s.  c  o  m
        LOG.info("ALE Persistence => start");
        String path = servletContext.getRealPath("/");
        LOG.debug("ALE Persistence real path of the webapp: " + path);
        persistenceConfig.setRealPathWebapp(path);

        LOG.info("ALE Persistence initialize configuration");
        persistenceReadConfig.init();

        LOG.info("ALE Persistence => end");
    } catch (Exception ex) {
        LOG.error("could not initialize the persistence API.", ex);
        throw new ServletException(ex);
    }
}