List of usage examples for javax.servlet ServletException ServletException
public ServletException(Throwable rootCause)
From source file:WeblogicDbServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { String sql = "select * from athlete"; Connection conn = null;/*from w ww . j a v a 2s . c om*/ Statement stmt = null; ResultSet rs = null; ResultSetMetaData rsm = null; response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); out.println("<html><head><title>Weblogic Database Access</title></head><body>"); out.println("<h2>Database info</h2>"); out.println("<table border='1'><tr>"); try { conn = pool.getConnection(); 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></body></html>"); out.close(); }
From source file:com.spt.evt.view.PartialRenderingTilesView.java
protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { ServletContext servletContext = getServletContext(); if ("nolayout".equals(request.getParameter("htmlFormat"))) { BasicTilesContainer container = (BasicTilesContainer) ServletUtil.getCurrentContainer(request, servletContext);// www .ja v a 2 s .c o m if (container == null) { throw new ServletException("Tiles container is not initialized. " + "Have you added a TilesConfigurer to your web application context?"); } exposeModelAsRequestAttributes(model, request); JstlUtils.exposeLocalizationContext(new RequestContext(request, servletContext)); TilesRequestContext tilesRequestContext = tilesRequestContextFactory .createRequestContext(container.getApplicationContext(), new Object[] { request, response }); Definition compositeDefinition = container.getDefinitionsFactory().getDefinition(getUrl(), tilesRequestContext); Iterator<String> iterator = compositeDefinition.getAttributeNames(); while (iterator.hasNext()) { String attributeName = (String) iterator.next(); Attribute attribute = compositeDefinition.getAttribute(attributeName); if (attribute.getValue() == null || !(attribute.getValue() instanceof String)) { continue; } container.startContext(request, response).inheritCascadedAttributes(compositeDefinition); container.render(attribute, request, response); container.endContext(request, response); } } else { super.renderMergedOutputModel(model, request, response); } }
From source file:edu.umd.cs.submitServer.filters.RegisterStudentsFilter.java
@Override public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) resp; if (!request.getMethod().equals("POST")) { throw new ServletException("Only POST accepted"); }/* ww w . jav a 2s . com*/ Connection conn = null; BufferedReader reader = null; FileItem fileItem = null; TreeSet<StudentRegistration> registeredStudents = new TreeSet<StudentRegistration>(); List<String> errors = new ArrayList<String>(); try { conn = getConnection(); // MultipartRequestFilter is required MultipartRequest multipartRequest = (MultipartRequest) request.getAttribute(MULTIPART_REQUEST); Course course = (Course) request.getAttribute("course"); // open the uploaded file fileItem = multipartRequest.getFileItem(); reader = new BufferedReader(new InputStreamReader(fileItem.getInputStream())); int lineNumber = 1; while (true) { String line = reader.readLine(); if (line == null) break; lineNumber++; // hard-coded skip of first two lines for Maryland-specific // format if (line.startsWith("Last,First,UID,section,ClassAcct,DirectoryID")) continue; if (line.startsWith(",,,,,")) { if (line.equals(",,,,,")) continue; String ldap = line.substring(5); Student student = Student.lookupByLoginName(ldap, conn); if (student != null) { StudentRegistration sr = StudentForUpload.registerStudent(course, student, "", ldap, null, conn); registeredStudents.add(sr); } else errors.add("Did not find " + ldap); continue; } if (line.startsWith("#")) continue; // skip blank lines if (line.trim().equals("")) continue; try { StudentForUpload s = new StudentForUpload(line, delimiter); Student student = s.lookupOrInsert(conn); StudentRegistration sr = StudentForUpload.registerStudent(course, student, s.section, s.classAccount, null, conn); registeredStudents.add(sr); } catch (IllegalStateException e) { errors.add(e.getMessage()); ServletExceptionFilter.logError(conn, ServerError.Kind.EXCEPTION, request, "error while registering " + line, null, e); } catch (Exception e1) { errors.add("Problem processing line: '" + line + "' at line number: " + lineNumber); ServletExceptionFilter.logError(conn, ServerError.Kind.EXCEPTION, request, "error while registering " + line, null, e1); } } } catch (SQLException e) { throw new ServletException(e); } finally { releaseConnection(conn); if (reader != null) reader.close(); if (fileItem != null) fileItem.delete(); } request.setAttribute("registeredStudents", registeredStudents); request.setAttribute("errors", errors); chain.doFilter(request, response); }
From source file:com.parakhcomputer.web.servlet.view.tiles2.AjaxDynamicTilesView.java
/** * Renders output using Tiles./*from ww w .j a v a 2 s . com*/ */ protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { String beanName = getBeanName(); String url = getUrl(); ServletContext servletContext = getServletContext(); TilesContainer container = TilesAccess.getContainer(servletContext); if (container == null) { throw new ServletException("Tiles container is not initialized. " + "Have you added a TilesConfigurer to your web application context?"); } if (ajaxHandler.isAjaxRequest(request, response)) { // change URL used to lookup tiles template to correct definition String definitionName = dynamicTilesViewProcessor.startDynamicDefinition(beanName, url, request, response, container); super.renderMergedOutputModel(model, request, response); dynamicTilesViewProcessor.endDynamicDefinition(definitionName, beanName, request, response, container); } else { exposeModelAsRequestAttributes(model, request); dynamicTilesViewProcessor.renderMergedOutputModel(beanName, url, servletContext, request, response, container); } }
From source file:com.adobe.communities.ugc.migration.legacyProfileExport.SocialGraphExportServlet.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 ww . j a v a 2s . c om*/ final SocialGraph graph = request.getResourceResolver().adaptTo(SocialGraph.class); 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(); exportSocialGraph(writer, userRoot, graph); writer.endObject(); } catch (final JSONException e) { throw new ServletException("Encountered a json exception while exporting social graph", e); } }
From source file:it.vige.greenarea.sgrl.servlet.CommonsFileUploadServlet.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); tmpDir = new File(TMP_DIR_PATH); if (!tmpDir.isDirectory()) { throw new ServletException(TMP_DIR_PATH + " is not a directory"); }/* w ww . j a v a 2 s . c o m*/ String realPath = getServletContext().getRealPath(DESTINATION_DIR_PATH); destinationDir = new File(realPath); if (!destinationDir.isDirectory()) { throw new ServletException(DESTINATION_DIR_PATH + " is not a directory"); } logger.info("realpath=" + realPath); }
From source file:com.liferay.petra.doulos.servlet.DoulosServlet.java
@Override public void init(ServletConfig servletConfig) throws ServletException { try {/*from ww w . jav a2s . c o m*/ registerDoulosRequestProcessors(); } catch (Exception e) { throw new ServletException(e); } String validIpsString = servletConfig.getInitParameter("validIps"); if (validIpsString != null) { _validIps = validIpsString.split(","); } else { _validIps = new String[0]; } }
From source file:de.thischwa.pmcms.server.ZipProxyServlet.java
@Override public void init(ServletConfig config) throws ServletException { zipPathToSkip = config.getInitParameter("zipPathToSkip"); String fileParam = config.getInitParameter("file"); if (StringUtils.isBlank(fileParam)) throw new IllegalArgumentException("No file parameter found!"); File file = null;/* www . j a va2 s.c om*/ zipInfo = new HashMap<String, ZipEntry>(); try { file = new File(config.getInitParameter("file")); if (!file.exists()) { throw new ServletException(String.format("Zip-file not found: %s", file.getPath())); } zipFile = new ZipFile(file); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry ze = entries.nextElement(); String entryName = ze.getName(); if (zipPathToSkip != null) entryName = entryName.substring(zipPathToSkip.length() + 1); if (entryName.startsWith("/")) entryName = entryName.substring(1); zipInfo.put(entryName, ze); } logger.debug("Found entries in zip: " + zipInfo.size()); } catch (IOException e) { throw new ServletException("Couldn't read the zip file: " + e.getMessage(), e); } logger.info(String.format("ZipProxyServlet initialzed with file [%s] and path to skip [%s]", file.getPath(), zipPathToSkip)); }
From source file:org.guanxi.sp.engine.form.RegisterIdPFormController.java
public void init() throws ServletException { try {/*from w w w. ja v a 2s. co m*/ config = (Config) getServletContext().getAttribute(Guanxi.CONTEXT_ATTR_ENGINE_CONFIG); String exampleIdPFile = config.getIdPMetadataDirectory() + File.separator + "ExampleIDP.xml"; exampleIdPDoc = EntityDescriptorDocument.Factory.parse(new File(exampleIdPFile)); } catch (Exception ge) { throw new ServletException(ge); } }
From source file:GuestBookServlet.java
/** * Provides the servlet with the chance to get runtime configuration values * and initialize itself. For a database servlet, you want to grab the * driver name, URL, and any connection information. For this example, I * assume a driver that requires a user name and password. For an example of * more database independent configuration, see Chapter 4. * /*w ww . j a va 2s . c om*/ * @param cfg * the servlet configuration information * @throws javax.servlet.ServletException * could not load the specified JDBC driver */ public void init(ServletConfig cfg) throws ServletException { super.init(cfg); { String user, pw; driverName = cfg.getInitParameter("gb.driver"); jdbcURL = cfg.getInitParameter("gb.jdbcURL"); user = cfg.getInitParameter("gb.user"); if (user != null) { connectionProperties.put("user", user); } pw = cfg.getInitParameter("gb.pw"); if (pw != null) { connectionProperties.put("password", pw); } try { driver = (Driver) Class.forName(driverName).newInstance(); } catch (Exception e) { throw new ServletException("Unable to load driver: " + e.getMessage()); } } }