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:it.smartcommunitylab.aac.oauth.ExtOAuth2SuccessHandler.java

protected void handle(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
        throws IOException, ServletException {

    OAuth2Authentication oauth = (OAuth2Authentication) authentication;
    @SuppressWarnings("unchecked")
    Map<String, Object> details = (Map<String, Object>) oauth.getUserAuthentication().getDetails();
    details = preprocess(details);//w w  w.  j  av a2 s  .  c om
    try {
        URIBuilder builder = new URIBuilder(getDefaultTargetUrl());
        for (String key : details.keySet()) {
            builder.addParameter(key, details.get(key).toString());
            request.setAttribute(key, details.get(key));
        }
        request.getRequestDispatcher(builder.build().toString()).forward(request, response);
        //         response.sendRedirect("forward:"+builder.build().toString());
        //         getRedirectStrategy().sendRedirect(request, response, builder.build().toString());
    } catch (URISyntaxException e) {
        throw new ServletException(e.getMessage());
    }
}

From source file:org.ambraproject.user.action.UserAlertsAction.java

/**
 * Retrieve the alerts for the logged in user
 *
 * @return webwork status//from  w w w  .j  ava 2  s. co  m
 * @throws Exception Exception
 */
@Transactional(readOnly = true)
public String retrieveAlerts() throws Exception {
    final String authId = getUserAuthId();
    if (authId == null) {
        throw new ServletException("Unable to resolve ambra user");
    }

    final UserProfile user = userService.getUserByAuthId(authId);
    final List<String> monthlyAlertsList = user.getMonthlyAlerts();
    final List<String> weeklyAlertsList = user.getWeeklyAlerts();

    monthlyAlerts = monthlyAlertsList.toArray(new String[monthlyAlertsList.size()]);
    weeklyAlerts = weeklyAlertsList.toArray(new String[weeklyAlertsList.size()]);
    displayName = user.getDisplayName();

    return SUCCESS;
}

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

public boolean doesUserHaveChannelRestrictions(HttpServletRequest request) throws ServletException {
    try {/*from  w  w w  . j a  v  a 2 s . c  o m*/
        return authorizationController.doesUserHaveChannelRestrictions(getCurrentUserId(request));
    } catch (ControllerException e) {
        throw new ServletException(e);
    }
}

From source file:edu.umd.cs.submitServer.servlets.UploadProjectStarterFiles.java

/**
 * The doPost method of the servlet. <br>
 * /*from w w  w  .j a  v a  2 s .com*/
 * This method is called when a form has its tag value method equals to
 * post.
 * 
 * @param request
 *            the request send by the client to the server
 * @param response
 *            the response send by the server to the client
 * @throws ServletException
 *             if an error occurred
 * @throws IOException
 *             if an error occurred
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    MultipartRequest multipartRequest = (MultipartRequest) request.getAttribute(MULTIPART_REQUEST);
    Project project = (Project) request.getAttribute(PROJECT);

    Connection conn = null;
    FileItem fileItem = null;
    try {
        conn = getConnection();

        fileItem = multipartRequest.getFileItem();

        long sizeInBytes = fileItem.getSize();
        if (sizeInBytes == 0) {
            throw new ServletException("Trying upload file of size 0");
        }

        // copy the fileItem into a byte array
        InputStream is = fileItem.getInputStream();
        ByteArrayOutputStream bytes = new ByteArrayOutputStream((int) sizeInBytes);
        IO.copyStream(is, bytes);

        byte[] bytesForUpload = bytes.toByteArray();

        // set the byte array as the archive
        project.setArchiveForUpload(bytesForUpload);
        FormatDescription desc = FormatIdentification.identify(bytesForUpload);
        if (desc == null || !desc.getMimeType().equals("application/zip")) {
            response.sendError(HttpServletResponse.SC_BAD_REQUEST,
                    "You MUST submit starter files that are either zipped or jarred");
            return;
        }

        Integer archivePK = project.getArchivePK();
        if (archivePK == null || archivePK.equals(0)) {
            // If there is no archive, then upload and create a new one
            project.uploadCachedArchive(conn);
            project.update(conn);
        } else {
            // Otherwise, update the archive we already have
            project.updateCachedArchive(bytesForUpload, conn);
        }

        String redirectUrl = request.getContextPath() + "/view/instructor/projectUtilities.jsp?projectPK="
                + project.getProjectPK();
        response.sendRedirect(redirectUrl);

    } catch (SQLException e) {
        throw new ServletException(e);
    } finally {
        releaseConnection(conn);
    }
}

From source file:com.collective.celos.servlet.JSONWorkflowServlet.java

protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException {
    String id = req.getParameter(CelosClient.ID_PARAM);
    try {/*ww w.j  a va2 s . c  om*/
        if (id == null) {
            res.sendError(HttpServletResponse.SC_BAD_REQUEST, CelosClient.ID_PARAM + " parameter missing.");
            return;
        }
        Scheduler scheduler = getOrCreateCachedScheduler();
        Workflow wf = scheduler.getWorkflowConfiguration().findWorkflow(new WorkflowID(id));
        if (wf == null) {
            res.sendError(HttpServletResponse.SC_NOT_FOUND, "Workflow not found: " + id);
        } else {
            ScheduledTime time = getRequestTime(req);
            try (StateDatabaseConnection connection = getStateDatabase().openConnection()) {
                List<SlotState> slotStates = scheduler.getSlotStates(wf,
                        scheduler.getWorkflowStartTime(wf, time), time, connection);
                ObjectNode object = createJSONObject(slotStates);
                writer.writeValue(res.getOutputStream(), object);
            }
        }
    } catch (Exception e) {
        throw new ServletException(e);
    }
}

From source file:com.curl.orb.servlet.DefaultInstanceManagementFilter.java

@SuppressWarnings("unchecked")
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    // accept just HTTP.
    if (!((request instanceof HttpServletRequest) && (response instanceof HttpServletResponse)))
        throw new ServletException("The request is not HTTP protocol.");

    HttpServletRequest httpRequest = (HttpServletRequest) request;
    InstanceManagementRequest instanceManagementRequest = null;
    // serialize the request object and set to the attribute
    try {// www  .  ja v a2  s  .  c o m
        if (request.getContentLength() == -1) {
            // forward to requested page.
            request.getRequestDispatcher(httpRequest.getServletPath()).forward(request, response);
            return;
        }
        instanceManagementRequest = (InstanceManagementRequest) serializer
                .deserialize(httpRequest.getInputStream());
        // debug request object (instanceManagementRequest.toString())
        log.debug("Curl ORB Request object [" + instanceManagementRequest + "]");
        httpRequest.setAttribute(InstanceManagementServlet.REQUEST_OBJECT, instanceManagementRequest);
    } catch (SerializerException e) {
        // NOTE: 
        //  Cannot handle the exception when "stream response" mode. 
        //  Clients cannot receive the error.
        setResponse((HttpServletResponse) response,
                new InstanceManagementException("Could not deserialize the object from Curl.", e), null);
        return;
    }

    try {
        // do filters and servlets
        chain.doFilter(httpRequest, response);
        // deserialize the object and return the response
        setResponse((HttpServletResponse) response,
                httpRequest.getAttribute(InstanceManagementServlet.RESPONSE_OBJECT),
                (Map<String, Object>) httpRequest
                        .getAttribute(InstanceManagementServlet.RESPONSE_SUBORDINATE_OBJECT));
    } catch (Exception e) {
        setResponse((HttpServletResponse) response, e, null);
    }
}

From source file:org.cee.highlighter.impl.ContentHighlightHandler.java

@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {/* w ww . ja  v  a 2  s . c o  m*/
        ArticleKey articleKey = getArticleKey(request);
        Article article = articleStore.getArticle(articleKey, false);

        WebResponse webResponse = this.webClient.openWebResponse(new URL(article.getLocation()), true);
        String contentEncoding = webResponse.getContentEncoding();
        response.setCharacterEncoding(contentEncoding);

        Settings settings = DefaultSettings.createDefaultSettings(new URL(article.getLocation()));
        contentHighlighter.highlightContent(response.getWriter(), webResponse, article, settings);
    } catch (StoreException e) {
        throw new ServletException(e);
    } catch (ParserException e) {
        throw new ServletException(e);
    }
}

From source file:com.adobe.acs.commons.analysis.jcrchecksum.impl.servlets.ChecksumGeneratorServlet.java

@Override
public final void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
        throws ServletException {
    try {/*from  w  ww  . j  av  a  2  s .c  o m*/
        this.handleCORS(request, response);
        this.handleRequest(request, response);
    } catch (IOException e) {
        throw new ServletException(e);
    } catch (RepositoryException e) {
        throw new ServletException(e);
    }
}

From source file:com.adobe.acs.commons.analysis.jcrchecksum.impl.servlets.JSONDumpServlet.java

@Override
public final void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
        throws ServletException, IOException {
    try {//from  w w w .  j  a va  2  s.c  o m
        this.handleCORS(request, response);
        this.handleRequest(request, response);
    } catch (RepositoryException e) {
        throw new ServletException(e);
    }
}

From source file:org.openmeetings.servlet.outputhandler.AbstractUploadController.java

protected UploadInfo validate(HttpServletRequest request, boolean admin) throws ServletException {
    UploadInfo info = new UploadInfo();
    log.debug("Starting validate");
    try {//from   w  w w  .java2 s . c om
        String sid = request.getParameter("sid");
        if (sid == null) {
            throw new ServletException("SID Missing");
        }
        info.sid = sid;
        log.debug("sid: " + sid);

        Long userId = sessionManagement.checkSession(sid);
        Long userLevel = userManagement.getUserLevelByID(userId);
        log.debug("userId = " + userId + ", userLevel = " + userLevel);
        info.userId = userId;

        if ((admin && !authLevelManagement.checkAdminLevel(userLevel)) || (!admin && userLevel <= 0)) {
            throw new ServletException("Insufficient permissions " + userLevel);
        }

        String publicSID = request.getParameter("publicSID");
        if (publicSID == null) {
            // Always ask for Public SID
            throw new ServletException("Missing publicSID");
        }
        log.debug("publicSID: " + publicSID);
        info.publicSID = publicSID;

        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        MultipartFile multipartFile = multipartRequest.getFile("Filedata");
        //FIXME encoding HACK
        info.filename = new String(multipartFile.getOriginalFilename().getBytes("iso-8859-1"), "UTF-8");
        long fileSize = multipartFile.getSize();
        long maxSize = ImportHelper.getMaxUploadSize(cfgManagement);
        log.debug("uploading " + fileSize + " bytes");
        if (fileSize > maxSize) {
            throw new ServletException("Maximum upload size: " + maxSize + " exceeded: " + fileSize);
        }
        info.file = multipartFile;
    } catch (ServletException e) {
        throw e;
    } catch (Exception e) {
        log.error("Exception during upload: ", e);
        throw new ServletException(e);
    }
    return info;
}