List of usage examples for javax.servlet ServletException ServletException
public ServletException(Throwable rootCause)
From source file:org.inspektr.error.web.ErrorLoggingFilter.java
protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain) throws ServletException, IOException { try {/*from w ww . j ava 2 s . c o m*/ filterChain.doFilter(request, response); } catch (ServletException e) { this.errorLogManager.recordError(e); throw e; } catch (IOException e) { this.errorLogManager.recordError(e); throw e; } catch (Throwable t) { this.errorLogManager.recordError(t); throw new ServletException(t); } }
From source file:com.amazonaws.services.kinesis.aggregators.app.ShowConfigFileServlet.java
@Override protected void doAction(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {// w ww .ja v a2 s .c o m String configUrl = System.getProperty(AggregatorsConstants.CONFIG_URL_PARAM); String url = null; if (configUrl == null) { response.setStatus(404); } else { url = ConfigFileUtils.makeConfigFileURL(configUrl); LOG.info(String.format("Sending Redirect for Config File to S3 Temporary URL %s", url)); response.setHeader("Access-Control-Allow-Origin", "*"); response.sendRedirect(url); } } catch (Exception e) { throw new ServletException(e); } }
From source file:DatabaseServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { String sql = "select * from atable"; Connection conn = null;/*from w w w.ja va 2s . c o m*/ Statement stmt = null; ResultSet rs = null; ResultSetMetaData rsm = null; response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); out.println("<html><head><title>Typical Database Access</title></head><body>"); out.println("<h2>Database info</h2>"); out.println("<table border='1'><tr>"); try { //load the database driver Class.forName("oracle.jdbc.driver.OracleDriver"); //The JDBC URL for this Oracle database String url = "jdbc:oracle:thin:@142.3.169.178:1521:ORCL"; //Create the java.sql.Connection to the database conn = DriverManager.getConnection(url, "usr", "pass"); //Create a statement for executing some SQL stmt = conn.createStatement(); rs = stmt.executeQuery(sql); rsm = rs.getMetaData(); int colCount = rsm.getColumnCount(); //print column names for (int i = 1; i <= colCount; ++i) { out.println("<th>" + rsm.getColumnName(i) + "</th>"); } out.println("</tr>"); while (rs.next()) { out.println("<tr>"); for (int i = 1; i <= colCount; ++i) out.println("<td>" + rs.getString(i) + "</td>"); out.println("</tr>"); } } catch (Exception e) { throw new ServletException(e.getMessage()); } finally { try { stmt.close(); conn.close(); } catch (SQLException sqle) { } } out.println("</table><br><br>"); out.println("</body>"); out.println("</html>"); out.close(); }
From source file:flex.webtier.server.j2ee.MxmlServlet.java
public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); serviceImpl = ServiceUtil.setupFlexService(getServletContext(), servletConfig); LicenseService license = ServiceFactory.getLicenseService(); if (license.isBetaExpired()) { log(license.expiredMessage());/*from w w w .j a v a2 s .c om*/ throw new ServletException(license.expiredMessage()); } // print version and beta days left message, if applicable String message = "Starting Adobe Flex Web Tier Compiler"; if (license.getBetaRemainingMessage() != null) { message += license.getBetaRemainingMessage(); } log(message); log(VersionInfo.buildMessage()); initializeExtensions(); filterChain = createFilterChain(); objectFilterChain = createObjectFilterChain(); logCompilerErrors = ServiceFactory.getConfigurator().getServerConfiguration().getDebuggingConfiguration() .logCompilerErrors(); }
From source file:com.amalto.core.servlet.ExportServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse resp) throws ServletException { XmlServer server = Util.getXmlServerCtrlLocal(); String clusterName = getParameter(request, PARAMETER_CLUSTER, true); int start = Integer.parseInt(getParameter(request, PARAMETER_START, true)); int end = Integer.parseInt(getParameter(request, PARAMETER_END, true)); boolean includeMetadata = Boolean .parseBoolean(getParameter(request, PARAMETER_INCLUDE_METADATA, false, "false")); //$NON-NLS-1$ ServletOutputStream outputStream;//from www . ja v a2 s.c om try { outputStream = resp.getOutputStream(); } catch (IOException e) { throw new ServletException(e); } try { resp.setContentType("text/xml"); server.exportDocuments(clusterName, start, end, includeMetadata, outputStream); } catch (XtentisException e) { throw new ServletException(e); } finally { try { outputStream.flush(); } catch (IOException e) { LOGGER.error("Error during flush", e); } } }
From source file:edu.cornell.mannlib.vitro.webapp.controller.json.GetEntitiesByVClass.java
@Override protected JSONArray process() throws ServletException { log.debug("in getEntitiesByVClass()"); String vclassURI = vreq.getParameter("vclassURI"); WebappDaoFactory daos = vreq.getUnfilteredWebappDaoFactory(); if (vclassURI == null) { throw new ServletException("getEntitiesByVClass(): no value for 'vclassURI' found in the HTTP request"); }/* w ww . j a v a2 s . c o m*/ VClass vclass = daos.getVClassDao().getVClassByURI(vclassURI); if (vclass == null) { throw new ServletException("getEntitiesByVClass(): could not find vclass for uri '" + vclassURI + "'"); } List<Individual> entsInVClass = daos.getIndividualDao().getIndividualsByVClass(vclass); if (entsInVClass == null) { throw new ServletException( "getEntitiesByVClass(): null List<Individual> retruned by getIndividualsByVClass() for " + vclassURI); } int numberOfEntsInVClass = entsInVClass.size(); List<Individual> entsToReturn = new ArrayList<Individual>(REPLY_SIZE); String requestHash = null; int count = 0; boolean more = false; /* we have a large number of items to send back so we need to stash the list in the session scope */ if (entsInVClass.size() > REPLY_SIZE) { more = true; HttpSession session = vreq.getSession(true); requestHash = Integer.toString((vclassURI + System.currentTimeMillis()).hashCode()); session.setAttribute(requestHash, entsInVClass); ListIterator<Individual> entsFromVclass = entsInVClass.listIterator(); while (entsFromVclass.hasNext() && count < REPLY_SIZE) { entsToReturn.add(entsFromVclass.next()); entsFromVclass.remove(); count++; } if (log.isDebugEnabled()) { log.debug("getEntitiesByVClass(): Creating reply with continue token, found " + numberOfEntsInVClass + " Individuals"); } } else { if (log.isDebugEnabled()) log.debug("getEntitiesByVClass(): sending " + numberOfEntsInVClass + " Individuals without continue token"); entsToReturn = entsInVClass; count = entsToReturn.size(); } //put all the entities on the JSON array JSONArray ja = individualsToJson(entsToReturn); //put the responseGroup number on the end of the JSON array if (more) { try { JSONObject obj = new JSONObject(); obj.put("resultGroup", "true"); obj.put("size", count); obj.put("total", numberOfEntsInVClass); StringBuffer nextUrlStr = vreq.getRequestURL(); nextUrlStr.append("?").append("getEntitiesByVClass").append("=1&").append("resultKey=") .append(requestHash); obj.put("nextUrl", nextUrlStr.toString()); ja.put(obj); } catch (JSONException je) { throw new ServletException("unable to create continuation as JSON: " + je.getMessage()); } } log.debug("done with getEntitiesByVClass()"); return ja; }
From source file:br.bireme.prvtrm.PreviousTermServlet.java
/** * INDEX_DIR diretorio contendo o indice Lucene * MAX_TERMS numero maximo de termos a serem retornados * DOC_FIELDS nomes dos campos cujos termos serao retornados * (separados por ',' ';' ou '-' )/*www . j a v a 2s . c o m*/ * @param servletConfig * @throws ServletException */ @Override public void init(final ServletConfig servletConfig) throws ServletException { final String sdir = servletConfig.getInitParameter("INDEX_DIR"); if (sdir == null) { throw new ServletException("missing index directory (INDEX_DIR) " + "parameter."); } final String maxTerms = servletConfig.getInitParameter("MAX_TERMS"); if (maxTerms == null) { throw new ServletException("missing maximum number of returned " + "terms (MAX_TERMS) parameter."); } final String fields = servletConfig.getInitParameter("DOC_FIELDS"); if (fields == null) { throw new ServletException("missing document fields (DOC_FIELDS) " + "parameter."); } try { previous = new PreviousTerm(new File(sdir), Arrays.asList(fields.split("[,;\\-]")), Integer.parseInt(maxTerms)); } catch (Exception ex) { throw new ServletException(ex); } }
From source file:dk.clarin.tools.userhandle.java
@SuppressWarnings("unchecked") public static List<FileItem> getParmList(HttpServletRequest request) throws ServletException { List<FileItem> items = null; boolean is_multipart_formData = ServletFileUpload.isMultipartContent(request); if (is_multipart_formData) { DiskFileItemFactory fileItemFactory = new DiskFileItemFactory(); /*// w w w . ja v a 2 s . c o m *Set the size threshold, above which content will be stored on disk. */ fileItemFactory.setSizeThreshold(1 * 1024 * 1024); //1 MB /* * Set the temporary directory to store the uploaded files of size above threshold. */ File tmpDir = new File(ToolsProperties.tempdir); if (!tmpDir.isDirectory()) { throw new ServletException("Trying to set \"" + ToolsProperties.tempdir + "\" as temporary directory, but this is not a valid directory."); } fileItemFactory.setRepository(tmpDir); ServletFileUpload uploadHandler = new ServletFileUpload(fileItemFactory); try { items = (List<FileItem>) uploadHandler.parseRequest(request); } catch (FileUploadException ex) { logger.error("Error encountered while parsing the request: " + ex.getMessage()); } } return items; }
From source file:org.ambraproject.user.action.UserAlertsAction.java
/** * Save the alerts.// www.j ava 2s. c om * * @return webwork status * @throws Exception Exception */ @Transactional(rollbackFor = { Throwable.class }) public String saveAlerts() throws Exception { final String authId = getUserAuthId(); if (authId == null) { throw new ServletException("Unable to resolve ambra user"); } userService.setAlerts(authId, Arrays.asList(monthlyAlerts), Arrays.asList(weeklyAlerts)); return SUCCESS; }
From source file:com.bluexml.side.Framework.alfresco.shareLanguagePicker.CustomWebScriptServlet.java
@Override protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { if (logger.isDebugEnabled()) { logger.debug("Processing request (" + req.getMethod() + ") " + req.getRequestURL() + (req.getQueryString() != null ? "?" + req.getQueryString() : "")); }//from w w w .j a v a 2 s . co m if (req.getCharacterEncoding() == null) { req.setCharacterEncoding("UTF-8"); } // initialize the request context RequestContext context = null; try { context = FrameworkHelper.initRequestContext(req); } catch (Exception ex) { throw new ServletException(ex); } LanguageSetter.setLanguageFromLayoutParam(req, context); WebScriptServletRuntime runtime = new WebScriptServletRuntime(container, authenticatorFactory, req, res, serverProperties); runtime.executeScript(); }