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:net.sourceforge.subsonic.security.RESTRequestParameterProcessingFilter.java

/**
 * {@inheritDoc}// w ww  .  j  a  va2s . c  o  m
 */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    if (!(request instanceof HttpServletRequest)) {
        throw new ServletException("Can only process HttpServletRequest");
    }
    if (!(response instanceof HttpServletResponse)) {
        throw new ServletException("Can only process HttpServletResponse");
    }

    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;

    String username = StringUtils.trimToNull(httpRequest.getParameter("u"));
    String password = decrypt(StringUtils.trimToNull(httpRequest.getParameter("p")));
    String version = StringUtils.trimToNull(httpRequest.getParameter("v"));
    String client = StringUtils.trimToNull(httpRequest.getParameter("c"));

    RESTController.ErrorCode errorCode = null;

    // The username and password parameters are not required if the user
    // was previously authenticated, for example using Basic Auth.
    Authentication previousAuth = SecurityContextHolder.getContext().getAuthentication();
    boolean missingCredentials = previousAuth == null && (username == null || password == null);
    if (missingCredentials || version == null || client == null) {
        errorCode = RESTController.ErrorCode.MISSING_PARAMETER;
    }

    if (errorCode == null) {
        errorCode = checkAPIVersion(version);
    }

    if (errorCode == null) {
        errorCode = authenticate(username, password, previousAuth);
    }

    if (errorCode == null) {
        String restMethod = StringUtils.substringAfterLast(httpRequest.getRequestURI(), "/");
        errorCode = checkLicense(client, restMethod);
    }

    if (errorCode == null) {
        chain.doFilter(request, response);
    } else {
        SecurityContextHolder.getContext().setAuthentication(null);
        sendErrorXml(httpRequest, httpResponse, errorCode);
    }
}

From source file:com.expressui.core.util.SpringApplicationServlet.java

@Override
public void init(ServletConfig servletConfig) throws ServletException {
    super.init(servletConfig);
    log.debug("initializing SpringApplicationServlet");
    try {// w  w  w  . j ava2  s  .  co  m
        webApplicationContext = WebApplicationContextUtils
                .getRequiredWebApplicationContext(servletConfig.getServletContext());
    } catch (IllegalStateException e) {
        throw new ServletException(e);
    }
}

From source file:pl.bristleback.server.bristle.engine.jetty.servlet.JettyServletWebsocketEngine.java

public void handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (!websocketFactory.acceptWebSocket(request, response)) {
        throw new ServletException("Request is not a valid WebSockets handshake.");
    }//from  w w  w  .j  a  v  a2  s  . c o m
}

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

public List<String> getAuthorizedChannelIds(HttpServletRequest request) throws ServletException {
    try {/*from w w  w  . ja  v a 2s . c  o m*/
        return authorizationController.getAuthorizedChannelIds(getCurrentUserId(request));
    } catch (ControllerException e) {
        throw new ServletException(e);
    }
}

From source file:com.adobe.communities.ugc.migration.legacyExport.ScoresExportServlet.java

protected void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response)
        throws ServletException, IOException {

    final JSONWriter writer = new JSONWriter(response.getWriter());
    writer.setTidy(true);/*from w w w . ja  v  a  2 s .co m*/
    final String path = StringUtils.stripEnd(request.getRequestParameter("path").getString(), "/");
    final Resource userRoot = request.getResourceResolver().getResource(path);
    if (null == userRoot) {
        throw new ServletException("Cannot locate a valid resource at " + path);
    }
    final ValueMap vm = userRoot.adaptTo(ValueMap.class);
    if (!vm.get("jcr:primaryType").equals("rep:AuthorizableFolder")) {
        throw new ServletException("Cannot locate a valid resource at " + path);
    }
    //iterate over child resources to get user nodes
    try {
        writer.object();
        exportScores(writer, userRoot, request.getResourceResolver());
        writer.endObject();
    } catch (final JSONException e) {
        throw new ServletException("Encountered a json exception while exporting scores", e);
    }
}

From source file:com.npower.wurfl.WurflServletInit.java

public void init(ServletConfig config) throws ServletException {
    super.init(config);
    wurflSourceClassName = config.getInitParameter("WurflSourceClass");
    if (wurflSourceClassName == null || wurflSourceClassName.trim().length() == 0) {
        throw new ServletException(
                "Missing WURFLSourceClass parameter in web.xml for WurflServletInit servlet.");
    }//from   w  ww  .j a  v  a  2  s.  c  o m
    // To fire up WURFL initialize
    try {
        getObjectsManager();
    } catch (Exception e) {
        log.fatal(e.getMessage(), e);
        throw new ServletException(e.getMessage(), e);
    }
}

From source file:com.gwtcx.server.servlet.FileUploadServlet.java

public void init(ServletConfig config) throws ServletException {
    super.init(config);

    // DOMConfigurator.configure("log4j.xml");

    Log.debug("FileUpload Servlet - init()");

    tmpDir = new File(((File) getServletContext().getAttribute("javax.servlet.context.tempdir")).toString());

    if (!tmpDir.isDirectory()) {
        throw new ServletException(tmpDir.toString() + " is not a directory");
    }/*from ww w.j  av  a 2 s  .c  o  m*/

    Log.debug("tmpDir: " + tmpDir.toString());

    String realPath = getServletContext().getRealPath(DESTINATION_DIR_PATH);
    destinationDir = new File(realPath);

    if (!destinationDir.isDirectory()) {
        throw new ServletException(DESTINATION_DIR_PATH + " is not a directory");
    }

    Log.debug("destinationDir: " + destinationDir.toString());
}

From source file:fr.aliasource.webmail.server.LoginFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain fc)
        throws IOException, ServletException {
    HttpServletRequest hreq = (HttpServletRequest) req;
    HttpSession session = hreq.getSession();
    hreq.setCharacterEncoding("UTF-8");

    IAccount account = (IAccount) session.getAttribute("account");
    String uri = hreq.getRequestURI();
    uri = uri.replace("/minig", "");

    if (account != null) {
        fc.doFilter(req, resp);//  w  ww . ja  v  a2 s.c o  m
        return;
    } else {

        // pass through ajax calls
        if (ajaxCall.contains(uri)) {
            fc.doFilter(req, resp);
            return;
        }

        if (logger.isDebugEnabled()) {
            logger.debug("loginFilter on uri: " + hreq.getRequestURI());
        }

        /* Not logged in */
        try {
            performLoginProcedure(session, fc, hreq, (HttpServletResponse) resp);
        } catch (Exception e) {
            throw new ServletException(e);
        }
    }
}

From source file:edu.umd.cs.submitServer.MultipartRequest.java

public static MultipartRequest parseRequest(HttpServletRequest request, int maxSize, Logger logger,
        boolean strictChecking, ServletContext servletContext) throws IOException, ServletException {

    DiskFileItemFactory factory = getFactory(servletContext);
    ServletFileUpload upload = new ServletFileUpload(factory);
    upload.setSizeMax(maxSize);//from  www  . j a va  2  s .c o  m
    MultipartRequest multipartRequest = new MultipartRequest(logger, strictChecking);
    try {
        // Parse the request
        List<FileItem> items = upload.parseRequest(request);

        for (FileItem item : items) {

            if (item.isFormField()) {
                multipartRequest.setParameter(item.getFieldName(), item.getString());
            } else {
                multipartRequest.addFileItem(item);
            }
        }
        return multipartRequest;
    } catch (FileUploadBase.SizeLimitExceededException e) {
        Debug.error("File upload is too big " + e.getActualSize() + " > " + e.getPermittedSize());
        Debug.error("upload info: " + multipartRequest);
        throw new ServletException(e);
    } catch (FileUploadException e) {
        Debug.error("FileUploadException: " + e);
        throw new ServletException(e);
    }
}

From source file:com.bluexml.xforms.actions.AbstractWorkflowAction.java

@Override
public void submit() throws ServletException {

    if (controller.isInStandaloneMode()) {
        String msg = "The Alfresco Controller is in standalone mode. Some actions are unavailable";
        navigationPath.setStatusMsg(msg);
        throw new ServletException(msg);
    }/*  ww  w . j  av a  2  s .  co  m*/

    Page currentPage = navigationPath.peekCurrentPage();

    // do the work
    TransitionResultBean resultBean = submitWork();

    // redirect the client to the appropriate next page
    String msg = navigationPath.getStatusMsg();
    String URLsuffix = MsgId.PARAM_STATUS_MSG + "=" + StringUtils.trimToEmpty(msg);
    if (resultBean.isSuccess()) {
        redirectSuccess(currentPage, resultBean, URLsuffix);
    } else {
        redirectFailure(currentPage, URLsuffix);
    }
}