List of usage examples for javax.servlet.http HttpServletResponse SC_INTERNAL_SERVER_ERROR
int SC_INTERNAL_SERVER_ERROR
To view the source code for javax.servlet.http HttpServletResponse SC_INTERNAL_SERVER_ERROR.
Click Source Link
From source file:at.gv.egiz.bku.online.webapp.UIServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { BindingProcessorManager bindingProcessorManager = (BindingProcessorManager) getServletContext() .getAttribute("bindingProcessorManager"); if (bindingProcessorManager == null) { String msg = "Configuration error: BindingProcessorManager missing!"; log.error(msg);//w w w. j av a 2s . c o m resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg); return; } Configuration conf = ((BindingProcessorManagerImpl) bindingProcessorManager).getConfiguration(); if (conf == null) log.error("No configuration"); else MoccaParameterBean.setP3PHeader(conf, resp); Id id = (Id) req.getAttribute("id"); BindingProcessor bindingProcessor = null; if (id == null || !((bindingProcessor = bindingProcessorManager .getBindingProcessor(id)) instanceof HTTPBindingProcessor)) { resp.sendRedirect(expiredPageUrl); return; } MoccaParameterBean parameterBean = new MoccaParameterBean((HTTPBindingProcessor) bindingProcessor); req.setAttribute("moccaParam", parameterBean); String uiPage = MoccaParameterBean.getInitParameter("uiPage", getServletConfig(), getServletContext()); uiPage = parameterBean.getUIPage(uiPage); if (uiPage == null) { uiPage = "applet.jsp"; } RequestDispatcher dispatcher = req.getRequestDispatcher(uiPage); if (dispatcher == null) { log.warn("Failed to get RequestDispatcher for page {}.", uiPage); resp.sendError(HttpServletResponse.SC_NOT_FOUND); } else { dispatcher.forward(req, resp); } }
From source file:com.autentia.intra.servlet.DocServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String uri = request.getRequestURI(); log.debug("doGet - uri='" + uri + "'"); int i = uri.indexOf(URL_PREFIX); if (i != -1) { String relPath = uri.substring(i + URL_PREFIX.length()); relPath = URLDecoder.decode(relPath, "UTF-8"); log.debug("doGet - relPath='" + relPath + "'"); File f = new File(ConfigurationUtil.getDefault().getUploadPath() + relPath); if (f.exists()) { response.setContentLength((int) f.length()); String mime = request.getParameter(ARG_MIME); if (mime != null && !mime.equals("")) { response.setContentType(mime); }/*from w ww.j av a 2 s. co m*/ OutputStream out = response.getOutputStream(); InputStream in = new FileInputStream(f); byte[] buffer = new byte[8192]; int nr; while ((nr = in.read(buffer)) != -1) { out.write(buffer, 0, nr); } in.close(); } else { response.sendError(HttpServletResponse.SC_NOT_FOUND); } } else { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Bad URL prefix for servlet: check your web.xml file"); } }
From source file:com.ikon.servlet.frontend.StaplingDownloadServlet.java
/** * //from ww w .ja v a2 s.com */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { request.setCharacterEncoding("UTF-8"); String sgName = WebUtils.getString(request, "sgName"); String groupName = sgName.substring(0, sgName.indexOf("?")) + "_" + sgName.charAt(sgName.length() - 1); String id = "" + groupName.charAt(groupName.length() - 1); int groupId = Integer.parseInt(id); File tmpZip = File.createTempFile("okm", ".zip"); try { System.out.println("before zip"); String archive = groupName + ".zip"; response.setHeader("Content-disposition", "attachment; filename=\"" + archive + "\""); response.setContentType("application/zip"); OutputStream out = response.getOutputStream(); exportZip(groupId, out); out.flush(); out.close(); } catch (RepositoryException e) { log.warn(e.getMessage(), e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "RepositoryException: " + e.getMessage()); } catch (Exception e) { log.warn(e.getMessage(), e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } finally { FileUtils.deleteQuietly(tmpZip); } }
From source file:com.cognifide.cq.cqsm.core.servlets.ScriptUploadServlet.java
@Override protected void doPost(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException { try {//from www . ja va2 s .com final Map<String, InputStream> files = Maps.newHashMap(); for (RequestParameter file : request.getRequestParameters("file")) { files.put(file.getFileName(), file.getInputStream()); } final List<Script> scripts = scriptStorage.saveAll(files, isOverwrite(request), request.getResourceResolver()); if (shouldRedirect(request)) { response.sendRedirect(getRedirectTo(request)); } else { ServletUtils.writeJson(response, ScriptUtils.toJson(scripts)); } } catch (RepositoryException e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); ServletUtils.writeJson(response, "Cannot save script in repository: " + e.getMessage()); } }
From source file:com.hp.autonomy.frontend.find.hod.view.HodViewController.java
@ExceptionHandler public ModelAndView handleHodErrorException(final HodErrorException e, final HttpServletRequest request, final HttpServletResponse response) { response.reset();// ww w.j ava 2 s . c o m log.error("HodErrorException thrown while viewing document", e); final String errorKey = HOD_ERROR_MESSAGE_CODE_PREFIX + e.getErrorCode(); String hodErrorMessage; try { hodErrorMessage = controllerUtils.getMessage(errorKey, null); } catch (final NoSuchMessageException ignored) { // we don't have a key in the bundle for this error code hodErrorMessage = controllerUtils.getMessage(HOD_ERROR_MESSAGE_CODE_UNKNOWN, null); } final int errorCode = e.isServerError() ? HttpServletResponse.SC_INTERNAL_SERVER_ERROR : HttpServletResponse.SC_BAD_REQUEST; final String subMessageCode; final Object[] subMessageArgs; if (hodErrorMessage != null) { subMessageCode = HOD_ERROR_MESSAGE_CODE_SUB; subMessageArgs = new String[] { hodErrorMessage }; } else { subMessageCode = HOD_ERROR_MESSAGE_CODE_SUB_NULL; subMessageArgs = null; } response.setStatus(errorCode); return controllerUtils.buildErrorModelAndView(new ErrorModelAndViewInfo.Builder().setRequest(request) .setMainMessageCode(HOD_ERROR_MESSAGE_CODE_MAIN).setSubMessageCode(subMessageCode) .setSubMessageArguments(subMessageArgs).setStatusCode(errorCode).setContactSupport(true) .setException(e).build()); }
From source file:no.dusken.momus.authentication.TokenAuthenticationProvider.java
private Person getLoggedInUser(String username) { Person person = personRepository.findByUsername(username); if (person == null) { throw new RestException("User was logged in, but not found in our database!", HttpServletResponse.SC_INTERNAL_SERVER_ERROR); }/*from www .j av a 2 s .c om*/ return person; }
From source file:com.autentia.intra.servlet.DocRootServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String uri = request.getRequestURI(); log.debug("doGet - uri='" + uri + "'"); int i = uri.indexOf(URL_PREFIX); if (i != -1) { String relPath = uri.substring(i + URL_PREFIX.length()); relPath = URLDecoder.decode(relPath, "UTF-8"); log.debug("doGet - relPath='" + relPath + "'"); File f = new File(ConfigurationUtil.getDefault().getDocumentRootPath() + relPath); if (f.exists()) { response.setContentLength((int) f.length()); String mime = request.getParameter(ARG_MIME); if (mime != null && !mime.equals("")) { response.setContentType(mime); }/*from www. j a va 2s . co m*/ OutputStream out = response.getOutputStream(); InputStream in = new FileInputStream(f); byte[] buffer = new byte[8192]; int nr; while ((nr = in.read(buffer)) != -1) { out.write(buffer, 0, nr); } in.close(); } else { response.sendError(HttpServletResponse.SC_NOT_FOUND); } } else { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Bad URL prefix for servlet: check your web.xml file"); } }
From source file:fi.solita.phantomrunner.browserserver.HttpPhantomJsServerNotifier.java
private JsonNode send(Map<String, Object> jsonMap) { try {//from w w w. ja v a 2s .c o m // FIXME: should relly get this port from the JUnit configs but have no real way to pass this // to JavaScript side of things yet, bummer PostMethod method = new PostMethod("http://localhost:18080"); method.setRequestEntity( new StringRequestEntity(mapper.writeValueAsString(jsonMap), "application/json", "UTF-8")); int responseCode = client.executeMethod(method); switch (responseCode) { case HttpServletResponse.SC_INTERNAL_SERVER_ERROR: throw new RuntimeException("Internal server error occured: " + method.getResponseBodyAsString()); default: return mapper.readTree(method.getResponseBodyAsString()); } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.google.gwt.benchmark.dashboard.server.servlets.AddBenchmarkResultServlet.java
@Override protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String auth = req.getHeader("auth"); if (!authController.validateAuth(auth)) { resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED); return;/*from w w w. ja v a2 s.c o m*/ } BenchmarkRunJson benchmarkRunJSON = null; String json = null; try { json = IOUtils.toString(req.getInputStream(), "UTF-8"); AutoBean<BenchmarkRunJson> bean = AutoBeanCodex.decode(JsonFactory.get(), BenchmarkRunJson.class, json); benchmarkRunJSON = bean.as(); } catch (Exception e) { logger.log(Level.WARNING, "Can not deserialize JSON", e); if (json != null) { logger.warning(json); } resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); resp.getWriter().write("Can't parse JSON, see App Engine log for details."); return; } try { benchmarkController.addBenchmarkResult(benchmarkRunJSON); resp.setStatus(HttpServletResponse.SC_OK); } catch (Exception e) { logger.log(Level.WARNING, "Can not add benchmark results", e); resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
From source file:com.ikon.servlet.DownloadServlet.java
/** * /*w ww . j a v a2 s . c o m*/ */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { request.setCharacterEncoding("UTF-8"); String userId = request.getRemoteUser(); String path = WebUtils.getString(request, "path"); String uuid = WebUtils.getString(request, "uuid"); boolean inline = WebUtils.getBoolean(request, "inline"); InputStream is = null; try { // Now an document can be located by UUID if (uuid != null && !uuid.equals("")) { path = OKMRepository.getInstance().getNodePath(null, uuid); } if (path != null) { Document doc = OKMDocument.getInstance().getProperties(null, path); String fileName = PathUtils.getName(doc.getPath()); log.info("Download {} by {} ({})", new Object[] { path, userId, (inline ? "inline" : "attachment") }); is = OKMDocument.getInstance().getContent(null, path, false); WebUtils.sendFile(request, response, fileName, doc.getMimeType(), inline, is); } else { response.setContentType("text/plain; charset=UTF-8"); PrintWriter out = response.getWriter(); out.println("Missing document reference"); out.close(); } } catch (PathNotFoundException e) { log.warn(e.getMessage(), e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "PathNotFoundException: " + e.getMessage()); } catch (RepositoryException e) { log.warn(e.getMessage(), e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "RepositoryException: " + e.getMessage()); } catch (Exception e) { log.warn(e.getMessage(), e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } finally { IOUtils.closeQuietly(is); } }