List of usage examples for javax.servlet ServletException getCause
public synchronized Throwable getCause()
From source file:com.osbitools.ws.shared.prj.web.EntityUtilsMgrWsSrvServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try {/*from www.j a v a2s .com*/ super.doGet(req, resp); } catch (ServletException e) { if (e.getCause().getClass().equals(WsSrvException.class)) { // Authentication failed checkSendError(req, resp, (WsSrvException) e.getCause()); return; } else { throw e; } } // Check if only info requires boolean fcheck = req.getParameter("check") != null; String name = req.getParameter(PrjMgrConstants.REQ_NAME_PARAM); if (fcheck) { try { // Get info about single file printJson(resp, GenericUtils.getInfo(getPrjRootDir(req), name, getBaseExt(req), getReqParamValues(req), isMinfied(req))); } catch (WsSrvException e) { return; } } else { try { // Download file File f = GenericUtils.checkFile(getPrjRootDir(req), name, getBaseExt(req)); printMimeFile(resp, Files.probeContentType(f.toPath()), name, GenericUtils.readFile(f), "utf-8"); } catch (WsSrvException e) { checkSendError(req, resp, e); } } }
From source file:com.osbitools.ws.shared.prj.web.EntityUtilsMgrWsSrvServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try {//w w w.j a va 2s . c o m super.doPost(req, resp); } catch (ServletException e) { if (e.getCause().getClass().equals(WsSrvException.class)) { // Authentication failed checkSendError(req, resp, (WsSrvException) e.getCause()); return; } else { throw e; } } // Get DsMap name String name = req.getParameter(PrjMgrConstants.REQ_NAME_PARAM); // Check if rename required try { if (!ServletFileUpload.isMultipartContent(req)) { checkSendError(req, resp, 200, "Request is not multipart"); return; } // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(getDiskFileItemFactory(req)); InputStream in = null; List<FileItem> items; try { items = upload.parseRequest(req); } catch (FileUploadException e) { checkSendError(req, resp, 201, "Error parsing request", null, e); return; } for (FileItem fi : items) { if (!fi.isFormField()) { in = fi.getInputStream(); break; } } if (in == null) { checkSendError(req, resp, 202, "File Multipart section is not found"); return; } boolean minified = isMinfied(req); printJson(resp, "{" + Utils.getCRT(minified) + "\"entity\":" + Utils.getSPACE(minified) + getEntityUtils(req).create(getPrjRootDir(req), name, in, false, minified) + "}"); in.close(); } catch (WsSrvException e) { checkSendError(req, resp, e); } }
From source file:com.npower.dm.tracking.servlet.AccessTrackingFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) { try {//from w ww . j a v a 2 s . co m if (request instanceof HttpServletRequest) { HttpServletRequest req = (HttpServletRequest) request; this.tracker4Access.log(req); } filterChain.doFilter(request, response); } catch (ServletException sx) { filterConfig.getServletContext().log(sx.getMessage()); log.error(sx.getMessage(), sx); log.error(sx.getMessage(), sx.getCause()); } catch (Throwable ex) { filterConfig.getServletContext().log(ex.getMessage()); log.error(ex.getMessage(), ex); } finally { } }
From source file:com.osbitools.ws.shared.prj.web.ExFileMgrWsSrvServlet.java
@Override protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try {//from w w w . j a v a2 s.c o m super.doDelete(req, resp); } catch (ServletException e) { if (e.getCause().getClass().equals(WsSrvException.class)) { // Authentication failed checkSendError(req, resp, (WsSrvException) e.getCause()); return; } else { throw e; } } // Get File name and extension EntityUtils eut = getEntityUtils(req); String name = req.getParameter(FNAME); String dname = req.getParameter(DNAME); HashSet<String> extl; try { extl = getExtListByDirName(eut, dname); } catch (WsSrvException e) { checkSendError(req, resp, e); return; } try { GenericUtils.deleteFile(getPrjRootDir(req), name, extl, dname); } catch (WsSrvException e) { checkSendError(req, resp, e); } }
From source file:com.hortonworks.registries.auth.server.TestKerberosAuthenticationHandler.java
@Test(timeout = 60000) public void testDynamicPrincipalDiscoveryMissingPrincipals() throws Exception { String[] keytabUsers = new String[] { "hdfs/localhost" }; String keytab = KerberosTestUtils.getKeytabFile(); getKdc().createPrincipal(new File(keytab), keytabUsers); // destroy handler created in setUp() handler.destroy();// w w w.j av a 2 s .c o m Properties props = new Properties(); props.setProperty(KerberosAuthenticationHandler.KEYTAB, keytab); props.setProperty(KerberosAuthenticationHandler.PRINCIPAL, "*"); handler = getNewAuthenticationHandler(); try { handler.init(props); Assert.fail("init should have failed"); } catch (ServletException ex) { Assert.assertEquals("Principals do not exist in the keytab", ex.getCause().getMessage()); } catch (Throwable t) { Assert.fail("wrong exception: " + t); } }
From source file:com.osbitools.ws.shared.prj.web.ExFileMgrWsSrvServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try {//from w ww.j a v a2s. com super.doPost(req, resp); } catch (ServletException e) { if (e.getCause().getClass().equals(WsSrvException.class)) { // Authentication failed checkSendError(req, resp, (WsSrvException) e.getCause()); return; } else { throw e; } } // Get File name and extension EntityUtils eut = getEntityUtils(req); String name = req.getParameter(FNAME); String dname = req.getParameter(DNAME); HashSet<String> extl; try { extl = getExtListByDirName(eut, dname); } catch (WsSrvException e) { checkSendError(req, resp, e); return; } // Check if rename required String rename = req.getParameter("rename_to"); if (rename != null) { if (rename.equals("")) { //-- 235 checkSendError(req, resp, 235, "Empty parameter rename_to"); return; } try { GenericUtils.renameFile(getPrjRootDir(req), name, rename, extl, dname); } catch (WsSrvException e) { checkSendError(req, resp, e); } } else { try { if (!ServletFileUpload.isMultipartContent(req)) { //-- 255 checkSendError(req, resp, 255, "Request is not multipart"); return; } // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(getDiskFileItemFactory(req)); InputStream in = null; List<FileItem> items; try { items = upload.parseRequest(req); } catch (FileUploadException e) { //-- 256 checkSendError(req, resp, 256, "Error parsing request", null, e); return; } for (FileItem fi : items) { if (!fi.isFormField()) { in = fi.getInputStream(); break; } } if (in == null) { //-- 257 checkSendError(req, resp, 257, "Multipart section is not found"); return; } String res = ExFileUtils.createFile(getPrjRootDir(req), name, in, extl, dname, getReqParamValues(req), getEntityUtils(req), isMinfied(req), req.getParameter("overwrite") != null); printJson(resp, Utils.isEmpty(res) ? "{}" : res); } catch (WsSrvException e) { checkSendError(req, resp, e); } } }
From source file:com.osbitools.ws.shared.prj.web.ExFileMgrWsSrvServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try {//from w ww.j a v a2 s. c o m super.doGet(req, resp); } catch (ServletException e) { if (e.getCause().getClass().equals(WsSrvException.class)) { // Authentication failed checkSendError(req, resp, (WsSrvException) e.getCause()); return; } else { throw e; } } // Check if only info requires HashSet<String> extl = null; String info = req.getParameter("info"); String fname = req.getParameter(FNAME); EntityUtils eut = getEntityUtils(req); String dname = req.getParameter(DNAME); Boolean fmask = PrjMgrConstants.EXT_FILE_LIST_MASK.matcher(fname).matches(); if (!fmask) { // Check if file extension supported String ext; try { ext = GenericUtils.getFileExt(fname); } catch (WsSrvException e) { checkSendError(req, resp, e); return; } if (!eut.hasExt(ext)) { //-- 258 checkSendError(req, resp, 258, "File extension '" + ext + "' is not supported"); return; } } try { extl = getExtListByDirName(eut, dname); } catch (WsSrvException e) { checkSendError(req, resp, e); return; } if (Utils.isEmpty(info)) { try { // Check if file list required if (fmask) { resp.getWriter().print(GenericUtils.getResDirExtList(getPrjRootDir(req), fname, dname, eut.getExtLstFilenameFilter(dname))); } else { // Get single file File f = GenericUtils.checkFile(getPrjRootDir(req), fname, extl, dname, true); printMimeFile(resp, Files.probeContentType(f.toPath()), fname, GenericUtils.readFile(f), "utf-8"); } } catch (WsSrvException e) { checkSendError(req, resp, e); } } else { if (info.toLowerCase().equals("file_info")) { try { printJson(resp, GenericUtils.getInfo(getPrjRootDir(req), fname, extl, dname, getReqParamValues(req), isMinfied(req))); } catch (WsSrvException e) { return; } } else { if (!eut.hasInfoReq(info)) { //-- 252 checkSendError(req, resp, 252, null, new String[] { "Info request \'" + info + "\' is not supported." }); return; } try { printJson(resp, eut.execInfoReq(info, getPrjRootDir(req), fname, extl, dname, getReqParamValues(req), isMinfied(req))); } catch (WsSrvException e) { checkSendError(req, resp, e); } } } }
From source file:org.jtwig.unit.mvc.JtwigViewTest.java
@Test(expected = BeansException.class) public void ensureAppCtxInitializationCapturesServletException() throws Throwable { JtwigView underTest = new JtwigView() { @Override// ww w . java 2s . com protected GenericServlet getGenericServlet() { GenericServlet servlet = spy(super.getGenericServlet()); try { doThrow(ServletException.class).when(servlet).init(any(ServletConfig.class)); } catch (ServletException ex) { } return servlet; } }; // Let's just use reflection to call the method try { Method meth = JtwigView.class.getDeclaredMethod("initApplicationContext"); meth.setAccessible(true); meth.invoke(underTest); } catch (InvocationTargetException ex) { throw ex.getCause(); } }
From source file:org.bonitasoft.console.common.server.login.filter.AuthenticationFilter.java
/** * @return true if one of the rules pass false otherwise *//*from ww w.j a v a 2s . c o m*/ protected boolean isAuthorized(final HttpServletRequestAccessor requestAccessor, final HttpServletResponseAccessor responseAccessor, final TenantIdAccessor tenantIdAccessor, final FilterChain chain) throws ServletException, IOException { for (final AuthenticationRule rule : getRules()) { try { if (rule.doAuthorize(requestAccessor, tenantIdAccessor)) { chain.doFilter(requestAccessor.asHttpServletRequest(), responseAccessor.asServletResponse()); return true; } } catch (final ServletException e) { if (e.getCause() instanceof TenantIsPausedRedirectionToMaintenancePageException) { return handleTenantPausedException(requestAccessor, responseAccessor, e); } else { throw e; } } } return false; }
From source file:org.bonitasoft.console.common.server.login.filter.AuthenticationFilter.java
protected boolean handleTenantPausedException(final HttpServletRequestAccessor requestAccessor, final HttpServletResponseAccessor responseAccessor, final ServletException e) throws ServletException { final TenantIsPausedRedirectionToMaintenancePageException tenantIsPausedException = (TenantIsPausedRedirectionToMaintenancePageException) e .getCause();//w ww .j a v a2 s . c om if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "redirection to maintenance page : " + e.getMessage(), e); } redirectToMaintenance(requestAccessor, responseAccessor, tenantIsPausedException.getTenantId()); return false; }