List of usage examples for javax.servlet ServletException ServletException
public ServletException(Throwable rootCause)
From source file:org.ambraproject.user.action.AdminUserAlertsAction.java
/** * Retrieve the alerts for the logged in user * * @return webwork status//from w w w . ja v a 2 s . co m * @throws Exception Exception */ 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.groupdocs.ui.servlets.ViewDocument.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.addHeader("Content-Type", "application/json"); ViewDocumentParameters params = new ObjectMapper().readValue(request.getInputStream(), ViewDocumentParameters.class); ViewDocumentResponse result = new ViewDocumentResponse(); FileData fileData = ViewerUtils.factoryFileData(params.getPath()); DocumentInfoContainer docInfo = null; try {// www . ja v a 2s . c o m result.setDocumentDescription( (new FileDataJsonSerializer(fileData, new FileDataOptions())).Serialize(false)); } catch (ParseException x) { throw new ServletException(x); } if (params.getUseHtmlBasedEngine()) { try { docInfo = ViewerUtils.getViewerHtmlHandler() .getDocumentInfo(new DocumentInfoOptions(params.getPath())); } catch (Exception x) { throw new ServletException(x); } result.setPageCss(new String[0]); result.setLic(true); result.setPdfDownloadUrl(GetPdfDownloadUrl(params)); result.setPdfPrintUrl(GetPdfPrintUrl(params)); result.setUrl(GetFileUrl(params)); result.setPath(params.getPath()); result.setName(params.getPath()); result.setDocType(docInfo.getDocumentType()); result.setFileType(docInfo.getFileType()); HtmlOptions htmlOptions = new HtmlOptions(); htmlOptions.setResourcesEmbedded(true); htmlOptions.setHtmlResourcePrefix("/GetResourceForHtml?documentPath=" + params.getPath() + "&pageNumber={page-number}&resourceName="); if (!DotNetToJavaStringHelper.isNullOrEmpty(params.getPreloadPagesCount().toString()) && params.getPreloadPagesCount().intValue() > 0) { htmlOptions.setPageNumber(1); htmlOptions.setCountPagesToConvert(params.getPreloadPagesCount().intValue()); } String[] cssList = null; RefObject<ArrayList<String>> tempRef_cssList = new RefObject<ArrayList<String>>(cssList); List<PageHtml> htmlPages = GetHtmlPages(params.getPath(), htmlOptions); cssList = tempRef_cssList.argValue; ArrayList<String> pagesContent = new ArrayList<String>(); for (PageHtml page : htmlPages) { pagesContent.add(page.getHtmlContent()); } String[] htmlContent = pagesContent.toArray(new String[0]); result.setPageHtml(htmlContent); result.setPageCss(new String[] { String.join(" ", temp_cssList) }); for (int i = 0; i < result.getPageHtml().length; i++) { String html = result.getPageHtml()[i]; int indexOfScript = html.indexOf("script"); if (indexOfScript > 0) { result.getPageHtml()[i] = html.substring(0, indexOfScript); } } } else { try { docInfo = ViewerUtils.getViewerImageHandler() .getDocumentInfo(new DocumentInfoOptions(params.getPath())); } catch (Exception x) { throw new ServletException(x); } int maxWidth = 0; int maxHeight = 0; for (PageData pageData : docInfo.getPages()) { if (pageData.getHeight() > maxHeight) { maxHeight = pageData.getHeight(); maxWidth = pageData.getWidth(); } } fileData.setDateCreated(new Date()); fileData.setDateModified(docInfo.getLastModificationDate()); fileData.setPageCount(docInfo.getPages().size()); fileData.setPages(docInfo.getPages()); fileData.setMaxWidth(maxWidth); fileData.setMaxHeight(maxHeight); result.setPageCss(new String[0]); result.setLic(true); result.setPdfDownloadUrl(GetPdfDownloadUrl(params)); result.setPdfPrintUrl(GetPdfPrintUrl(params)); result.setUrl(GetFileUrl(params.getPath(), true, false, params.getFileDisplayName(), params.getWatermarkText(), params.getWatermarkColor(), params.getWatermarkPostion(), params.getWatermarkWidth(), params.getIgnoreDocumentAbsence(), params.getUseHtmlBasedEngine(), params.getSupportPageRotation())); result.setPath(params.getPath()); result.setName(params.getPath()); result.setDocType(docInfo.getDocumentType()); result.setFileType(docInfo.getFileType()); int[] pageNumbers = new int[docInfo.getPages().size()]; int count = 0; for (PageData page : docInfo.getPages()) { pageNumbers[count] = page.getNumber(); count++; } String applicationHost = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort(); String[] imageUrls = ImageUrlHelper.GetImageUrls(applicationHost, pageNumbers, params); result.setImageUrls(imageUrls); } new ObjectMapper().writeValue(response.getOutputStream(), result); }
From source file:edu.umn.msi.tropix.transfer.http.server.HttpTransferControllerImpl.java
private void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException { LOG.info("doGet called"); final String downloadKey = request.getParameter(ServerConstants.KEY_PARAMETER_NAME); LOG.info("Key is " + downloadKey); try {// w w w .j a v a2 s . co m response.setStatus(HttpServletResponse.SC_OK); response.flushBuffer(); fileKeyResolver.handleDownload(downloadKey, response.getOutputStream()); } catch (final Exception e) { LOG.info("handleDownload threw exception", e); throw new ServletException(e); } }
From source file:edu.morgan.server.UploadFile.java
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { // Check that we have a file upload request RequestDispatcher rd;//ww w .j a va 2 s . com response.setContentType("text/html"); isMultipart = ServletFileUpload.isMultipartContent(request); if (!isMultipart) { rd = request.getRequestDispatcher("fail.jsp"); rd.forward(request, response); } try { ServletFileUpload upload = new ServletFileUpload(); response.setContentType("text/plain"); FileItemIterator iterator = upload.getItemIterator(request); while (iterator.hasNext()) { FileItemStream item = iterator.next(); InputStream stream = item.openStream(); this.read(stream); } request.removeAttribute("incompleteStudents"); request.setAttribute("incompleteStudents", studentList); rd = request.getRequestDispatcher("Success"); rd.forward(request, response); } catch (Exception ex) { throw new ServletException(ex); } }
From source file:com.bluexml.xforms.servlets.UpdateServlet.java
/** * Update.//from w ww.j a v a2 s . co m * * @param req * the req * @throws ServletException * the servlet exception */ protected void update(HttpServletRequest req) throws ServletException { AlfrescoController controller = AlfrescoController.getInstance(); try { Node node = getDocumentReq(req); String skipIdStr = StringUtils.trimToNull(req.getParameter(ID_AS_SERVLET)); boolean idAsServlet = !StringUtils.equals(skipIdStr, "false"); String userName = req.getParameter(MsgId.PARAM_USER_NAME.getText()); AlfrescoTransaction transaction = createTransaction(controller, userName); controller.persistClass(transaction, node, idAsServlet, null); transaction.executeBatch(); } catch (Exception e) { throw new ServletException(e); } }
From source file:com.amalto.core.servlet.UploadFile.java
private void uploadFile(HttpServletRequest req, Writer writer) throws ServletException, IOException { // upload file if (!ServletFileUpload.isMultipartContent(req)) { throw new ServletException("Upload File Error: the request is not multipart!"); //$NON-NLS-1$ }//from w w w.j a v a 2s.co m // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(); // Set upload parameters DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setSizeThreshold(0); upload.setFileItemFactory(factory); upload.setSizeMax(-1); // Parse the request List<FileItem> items; try { items = upload.parseRequest(req); } catch (Exception e) { throw new ServletException(e.getMessage(), e); } // Process the uploaded items if (items != null && items.size() > 0) { // Only one file Iterator<FileItem> iter = items.iterator(); FileItem item = iter.next(); if (LOG.isDebugEnabled()) { LOG.debug(item.getFieldName()); } File file = null; if (!item.isFormField()) { try { String filename = item.getName(); if (req.getParameter(PARAMETER_DEPLOY_JOB) != null) { String contextStr = req.getParameter(PARAMETER_CONTEXT); file = writeJobFile(item, filename, contextStr); } else if (filename.endsWith(".bar")) { //$NON-NLS-1$ file = writeWorkflowFile(item, filename); } else { throw new IllegalArgumentException("Unknown deployment for file '" + filename + "'"); //$NON-NLS-1$ //$NON-NLS-2$ } } catch (Exception e) { throw new ServletException(e.getMessage(), e); } } else { throw new ServletException("Couldn't process request"); //$NON-NLS-1$); } String urlRedirect = req.getParameter("urlRedirect"); //$NON-NLS-1$ if (Boolean.valueOf(urlRedirect)) { String redirectUrl = req.getContextPath() + "?mimeFile=" + file.getName(); //$NON-NLS-1$ writer.write(redirectUrl); } else { writer.write(file.getAbsolutePath()); } } writer.close(); }
From source file:com.liferay.portal.servlet.SharedServletWrapper.java
public void init(ServletConfig sc) throws ServletException { super.init(sc); ServletContext ctx = getServletContext(); _servletContextName = StringUtil.replace(ctx.getServletContextName(), StringPool.SPACE, StringPool.UNDERLINE);/*from w w w . j a v a 2 s. co m*/ _servletClass = sc.getInitParameter("servlet-class"); ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); try { _servletInstance = (Servlet) contextClassLoader.loadClass(_servletClass).newInstance(); } catch (ClassNotFoundException cnfe) { throw new ServletException(cnfe.getMessage()); } catch (IllegalAccessException iae) { throw new ServletException(iae.getMessage()); } catch (InstantiationException ie) { throw new ServletException(ie.getMessage()); } if (_servletInstance instanceof HttpServlet) { _httpServletInstance = (HttpServlet) _servletInstance; _httpServletInstance.init(sc); } else { _servletInstance.init(sc); } }
From source file:net.sourceforge.jwebunit.tests.util.ParamsServlet.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.write(HtmlHelper.getStart("Submitted parameters")); out.write("<h1>Submitted parameters</h1>\n<p>Params are:<br/>"); /*// w w w.ja v a 2 s . co m * Prints POST and GET parameters as name=[value1[,value2...]] separated * by <BR/> */ // Check that we have a file upload request boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (isMultipart) { // Create a factory for disk-based file items FileItemFactory factory = new DiskFileItemFactory(); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); // Parse the request List /* FileItem */ items = null; try { items = upload.parseRequest(request); } catch (FileUploadException e) { throw new ServletException(e); } String ref = null; // Process the uploaded items Iterator iter = items.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (item.isFormField()) { out.write(" " + item.getFieldName() + "=[" + item.getString()); if (item.getFieldName().equals("myReferer")) { ref = item.getString(); } } else { String fieldName = item.getFieldName(); String fileName = item.getName(); out.write(" " + fieldName + "=[" + fileName + "{" + new String(item.get()) + "}"); } if (iter.hasNext()) { out.write("]<br/>\n"); } } out.write("]</p>\n"); out.write(HtmlHelper.getLinkParagraph("return", ref)); } else { java.util.Enumeration params = request.getParameterNames(); for (; params.hasMoreElements();) { String p = params.nextElement().toString(); String[] v = request.getParameterValues(p); out.write(p + "=["); int n = v.length; if (n > 0) { out.write(v[0] != null ? v[0] : ""); for (int i = 1; i < n; i++) { out.write("," + (v[i] != null ? v[i] : "")); } } if (params.hasMoreElements()) { out.write("]<br/>\n"); } } out.write("]</p>\n"); String ref = request.getHeader("Referer"); if (ref == null) { if (request.getParameterValues("myReferer") != null) { ref = request.getParameterValues("myReferer")[0]; } } out.write(HtmlHelper.getLinkParagraph("return", ref)); } out.write(HtmlHelper.getEnd()); }
From source file:edu.mayo.cts2.framework.webapp.rest.osgi.ProxyServlet.java
private BundleContext getBundleContext() throws ServletException { Object context = getServletContext().getAttribute(BundleContext.class.getName()); if (context instanceof BundleContext) { return (BundleContext) context; }// www . j a v a 2 s.c o m throw new ServletException( "Bundle context attribute [" + BundleContext.class.getName() + "] not set in servlet context"); }
From source file:de.berlios.jedi.presentation.StxxTransformSelectionFilter.java
/** * Sets the selected stxx transform in every request.<br> * The transform set is taken from a request parameter or, if there's no * transform set in request parameter, from a session attribute. If no * interface can be taken, stxx uses default output, which is html. * // w w w . j av a 2s . co m * @throws IOException * If an IOException occurs when filtering. * @throws ServletException * If a ServletException occurs when filtering. * * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, * javax.servlet.ServletResponse, javax.servlet.FilterChain) */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (!(request instanceof HttpServletRequest)) { LogFactory.getLog(StxxTransformSelectionFilter.class).error( "Unexpected error: request in StxxTransformSelectionFilter" + "isn't a HttpServletRequest"); throw new ServletException( "Unexpected error: request in StxxTransformSelectionFilter" + "isn't a HttpServletRequest"); } HttpServletRequest httpRequest = (HttpServletRequest) request; try { String transform = httpRequest.getParameter("transform"); if (transform != null) { httpRequest.getSession().setAttribute("transform", transform); } if ((transform = (String) httpRequest.getSession().getAttribute("transform")) != null) { httpRequest.setAttribute("transform", transform); } chain.doFilter(request, response); } catch (IOException e) { LogFactory.getLog(LoginFilter.class).error("IOException in StxxTransformSelectionFilter", e); throw e; } catch (ServletException e) { LogFactory.getLog(LoginFilter.class).error("ServletException in StxxTransformSelectionFilter", e); throw e; } }