List of usage examples for javax.servlet ServletException ServletException
public ServletException(Throwable rootCause)
From source file:jp.rough_diamond.framework.web.struts.BaseAction.java
protected ActionForward hasRole(ActionForm form, HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) throws ServletException { //_nformpopulate\?? try {//from w w w . j av a 2s .c om String parameter = mapping.getParameter(); if (parameter == null) { String message = messages.getMessage("dispatch.handler", mapping.getPath()); log.error(message); throw new ServletException(message); } String name = getMethodName(mapping, form, request, response, parameter); Method method = getMethod(name); return hasRole(method) ? null : mapping.findForward("forbiddenAccess"); } catch (Exception e) { throw new ServletException(e); } }
From source file:net.big_oh.hibernate.web.filter.HibernateOpenSessionInViewFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { try {//from w ww . ja v a 2s . c o m log.info("Starting a database transaction"); sf.getCurrentSession().beginTransaction(); // Call the next filter (continue request processing) chain.doFilter(request, response); // Commit and cleanup log.info("Committing the database transaction"); sf.getCurrentSession().getTransaction().commit(); } catch (Throwable ex) { HibernateUtil.rollback(ex, sf, log); // Let others handle it... maybe another interceptor for exceptions? throw new ServletException(ex); } }
From source file:azkaban.web.JobManagerServlet.java
@Override protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (!ServletFileUpload.isMultipartContent(request)) throw new ServletException("No job file found!"); Map<String, Object> params = this._multipartParser.parseMultipart(request); try {/*from ww w . jav a 2 s . co m*/ final AzkabanApplication app = getApplication(); final JobManager jobManager = app.getJobManager(); FileItem item = (FileItem) params.get("file"); String deployPath = (String) params.get("path"); File jobDir = extractFile(item); jobManager.deployJobDir(jobDir.getAbsolutePath(), deployPath); } catch (Exception e) { log.info("Installation Failed.", e); String redirectError = (String) params.get("redirect_error"); setMessagedUrl(response, redirectError, "Installation Failed: " + e.getLocalizedMessage()); return; } String redirectSuccess = (String) params.get("redirect_success"); setMessagedUrl(response, redirectSuccess, "Installation Succeeded"); }
From source file:AllEmployeesServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head><title>All Employees</title></head>"); out.println("<body>"); out.println("<center><h1>All Employees</h1>"); Connection conn = null;//from w w w. ja v a2s. c o m Statement stmt = null; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn = DriverManager.getConnection("jdbc:odbc:Employees"); stmt = conn.createStatement(); String orderBy = request.getParameter("sort"); if ((orderBy == null) || orderBy.equals("")) { orderBy = "SSN"; } String orderByDir = request.getParameter("sortdir"); if ((orderByDir == null) || orderByDir.equals("")) { orderByDir = "asc"; } String query = "SELECT Employees.SSN, Employees.Name, " + "Employees.Salary, " + "Employees.Hiredate, Location.Location " + "FROM Location " + "INNER JOIN Employees " + "ON Location.Loc_Id = Employees.Loc_Id " + "ORDER BY " + orderBy + " " + orderByDir + ";"; ResultSet rs = stmt.executeQuery(query); while (rs.next()) { long employeeSSN = rs.getLong("SSN"); String employeeName = rs.getString("Name"); long employeeSalary = rs.getLong("Salary"); Date employeeHiredate = rs.getDate("Hiredate"); String employeeLocation = rs.getString("Location"); out.print(employeeSSN + "::"); out.print(employeeName + "::"); out.print(employeeSalary + "::"); out.print(employeeHiredate + "::"); out.print(employeeLocation + "::"); } } catch (SQLException e) { out.println("An error occured while retrieving " + "all employees: " + e.toString()); } catch (ClassNotFoundException e) { throw (new ServletException(e.toString())); } finally { try { if (stmt != null) { stmt.close(); } if (conn != null) { conn.close(); } } catch (SQLException ex) { } } out.println("</center>"); out.println("</body>"); out.println("</html>"); out.close(); }
From source file:br.com.caelum.vraptor.config.BasicConfiguration.java
public ContainerProvider getProvider() throws ServletException { Class<? extends ContainerProvider> providerType = getProviderType(); logger.info("Using {} as Container Provider", providerType); try {//from w w w . j a v a2s . co m return providerType.getDeclaredConstructor().newInstance(); } catch (InvocationTargetException e) { throw new ServletException(e.getCause()); } catch (Exception e) { throw new ServletException(e); } }
From source file:de.xwic.appkit.webbase.modules.ModuleProviderServlet.java
@Override public void init() throws ServletException { //create the module factory try {/*from w w w . j av a2s . c om*/ this.moduleFactory = createFactory(this.getInitParameter(MODULE_FACTORY_INIT_PARAM)); this.baseUrl = this.getInitParameter(BASE_URL); this.applicationName = this.getInitParameter("app-name"); } catch (FactoryInstantiationException e) { throw new ServletException(e); } }
From source file:net.sourceforge.ajaxtags.servlets.AjaxActionHelper.java
/** * Invoke the AJAX action and setup the request and response. * * @param action//from ww w . j av a 2s. c o m * the BaseAjaxXmlAction implementation * @param request * the request * @param response * the response * @return the XML content from action * @throws ServletException * for any errors */ public static String invoke(final BaseAjaxXmlAction action, final HttpServletRequest request, final HttpServletResponse response) throws ServletException { // prepare CALL try { request.setCharacterEncoding(action.getXMLEncoding()); // we will use UTF-8 } catch (UnsupportedEncodingException e) { throw new ServletException(e); } // Set content to XML response.setContentType("text/xml; charset=" + action.getXMLEncoding()); // enable the ajaxheaders for (HTMLAjaxHeader header : HTMLAjaxHeader.values()) { header.enable(response); } try { return action.getXmlContent(request, response); } catch (IOException e) { throw new ServletException(e); } }
From source file:com.github.jrialland.ajpclient.servlet.TestServletProxy.java
public TestServletProxy() { super(Protocol.Ajp); addStaticResource("/dizzy.mp4", DIZZY_MP4); addServlet("/test_post", new HttpServlet() { private static final long serialVersionUID = 168417L; @Override//from w w w .j a v a 2 s . c om protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { final int nParams = Collections.list(req.getParameterNames()).size(); resp.getWriter().print(nParams); } }); addServlet("/long_request", new HttpServlet() { private static final long serialVersionUID = 168411L; @Override protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { try { final int time = Integer.parseInt(req.getParameter("duration")); Thread.sleep(time); } catch (final Exception e) { throw new ServletException(e); } } }); }
From source file:com.bluexml.xforms.servlets.DeleteServlet.java
/** * Delete./*from w ww. jav a2s .c o m*/ * * @param req * the req * @throws ServletException * the servlet exception */ protected void delete(HttpServletRequest req) throws ServletException { AlfrescoController controller = AlfrescoController.getInstance(); try { String dataId = StringUtils.trimToNull(req.getParameter(DATA_ID)); dataId = controller.patchDataId(dataId); String userName = req.getParameter(MsgId.PARAM_USER_NAME.getText()); AlfrescoTransaction transaction = createTransaction(controller, userName); controller.delete(transaction, dataId); transaction.executeBatch(); } catch (Exception e) { throw new ServletException(e); } }
From source file:net.ontopia.infoset.content.ContentStoreServlet.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException { // default values String ctype = "application/octet-stream"; boolean view = false; // get values from request String uri = request.getParameter("uri"); if (uri == null) throw new ServletException("Request parameter 'uri' required"); String tmid = request.getParameter("tmid"); if (tmid == null) throw new ServletException("Request parameter 'tmid' required"); String filename = request.getParameter("filename"); if (request.getParameter("ctype") != null) ctype = request.getParameter("ctype"); if (request.getParameter("view") != null) { String value = request.getParameter("ctype").trim().toLowerCase(); if ("true".equals(value)) view = true;/*from www .ja va 2 s. c o m*/ else if (!"false".equals(value)) throw new ServletException("Request parameter 'view' must hold 'true' or 'false'"); } // find the key if (!uri.startsWith("x-ontopia:cms:")) throw new ServletException("URI must begin with 'x-ontopia:cms:'"); int key; try { key = Integer.parseInt(uri.substring(14)); } catch (NumberFormatException e) { throw new ServletException("Content object ID was not an integer: '" + uri.substring(14) + "'"); } // set response headers (content-disposition defined in RFC 2183) response.setContentType(ctype); String disposition = "attachment"; if (view) disposition = "inline"; if (filename != null) disposition = disposition + "; filename=" + filename; response.setHeader("Content-disposition", disposition); // get the content store NavigatorApplicationIF navApp = null; TopicMapIF tm = null; try { navApp = NavigatorUtils.getNavigatorApplication(getServletContext()); tm = navApp.getTopicMapById(tmid); ContentStoreIF cs = getContentStore(tm, getServletContext()); // get the content stream ContentInputStream istream; try { istream = cs.get(key); } catch (ContentStoreException e) { throw new ServletException(e); } // set the content length response.setContentLength(istream.getLength()); // write content to output stream try { IOUtils.copy(istream, response.getOutputStream()); istream.close(); } catch (IOException e) { throw new ServletException(e); } } catch (NavigatorRuntimeException e) { throw new ServletException(e); } catch (ContentStoreException e) { throw new ServletException(e); } finally { if (navApp != null && tm != null) navApp.returnTopicMap(tm); } }