List of usage examples for javax.servlet.http HttpServletResponse sendError
public void sendError(int sc) throws IOException;
From source file:com.pentagon.web.system.controller.MenuPermissionController.java
@ResponseBody @RequestMapping(value = "/edit", method = RequestMethod.POST) public boolean doEdit(HttpServletRequest request, HttpServletResponse response) throws IOException { String groupId = request.getParameter("groupId"); if (StringUtil.isBlank(groupId)) { logger.error("Group Id required"); response.sendError(403); return Boolean.FALSE; }/*from w w w .java 2s . c o m*/ MenuPermission group = menuService.selectByPrimaryKey(Long.valueOf(groupId)); int count = menuService.updateByPrimaryKey(group); return count > 0; }
From source file:it.biztech.btable.api.FileApi.java
@GET @Path("/read") @Produces("text/plain") public void read(@QueryParam(MethodParams.PATH) @DefaultValue("") String path, @Context HttpServletResponse response) throws IOException { try {//from w ww. j a v a 2 s. c om IBasicFile file = Utils.getFile(path, null); if (file == null) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } IPluginResourceLoader resLoader = PentahoSystem.get(IPluginResourceLoader.class, null); String maxAge = resLoader.getPluginSetting(this.getClass(), "max-age"); String mimeType; try { final MimeTypes.FileType fileType = MimeTypes.FileType.valueOf(file.getExtension().toUpperCase()); mimeType = MimeTypes.getMimeType(fileType); } catch (java.lang.IllegalArgumentException ex) { mimeType = ""; } catch (EnumConstantNotPresentException ex) { mimeType = ""; } response.setHeader("Content-Type", mimeType); response.setHeader("content-disposition", "inline; filename=\"" + file.getName() + "\""); if (maxAge != null) { response.setHeader("Cache-Control", "max-age=" + maxAge); } byte[] contents = IOUtils.toByteArray(file.getContents()); IOUtils.write(contents, response.getOutputStream()); response.getOutputStream().flush(); } catch (SecurityException e) { response.sendError(HttpServletResponse.SC_FORBIDDEN); } }
From source file:com.mirth.connect.server.servlets.EngineServlet.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // MIRTH-1745 response.setCharacterEncoding("UTF-8"); if (!isUserLoggedIn(request)) { response.sendError(HttpServletResponse.SC_FORBIDDEN); } else {//from www. j ava2s . c om try { EngineController engineController = ControllerFactory.getFactory().createEngineController(); ObjectXMLSerializer serializer = new ObjectXMLSerializer(); Operation operation = Operations.getOperation(request.getParameter("op")); Map<String, Object> parameterMap = new HashMap<String, Object>(); ServerEventContext context = new ServerEventContext(); context.setUserId(getCurrentUserId(request)); if (operation.equals(Operations.CHANNEL_REDEPLOY)) { if (!isUserAuthorized(request, null) || doesUserHaveChannelRestrictions(request)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { engineController.redeployAllChannels(context); } } else if (operation.equals(Operations.CHANNEL_DEPLOY)) { List<String> channelIds = (List<String>) serializer.fromXML(request.getParameter("channelIds")); parameterMap.put("channelIds", channelIds); if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { engineController.deployChannels(channelIds, context); } } else if (operation.equals(Operations.CHANNEL_UNDEPLOY)) { List<String> channelIds = (List<String>) serializer.fromXML(request.getParameter("channelIds")); parameterMap.put("channelIds", channelIds); if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { engineController.undeployChannels(channelIds, context); } } } catch (RuntimeIOException rio) { logger.debug(rio); } catch (Throwable t) { logger.error(ExceptionUtils.getStackTrace(t)); throw new ServletException(t); } } }
From source file:edu.mayo.cts2.framework.webapp.rest.osgi.ProxyServlet.java
@Override protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { HttpServlet dispatcher = (HttpServlet) this.tracker.getService(); if (dispatcher != null) { dispatcher.service(req, res);/* w w w . j av a 2s.c o m*/ } else { res.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } }
From source file:de.micromata.genome.gwiki.web.StaticFileServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String uri = req.getPathInfo(); String servletp = req.getServletPath(); String respath = servletp + uri; if (uri == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); return;//from w w w. ja v a 2 s.co m } InputStream is = getServletContext().getResourceAsStream(respath); if (is == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); return; } long nt = new Date().getTime() + TimeInMillis.DAY; String mime = MimeUtils.getMimeTypeFromFile(respath); if (StringUtils.equals(mime, "application/x-shockwave-flash")) { resp.setHeader("Cache-Control", "cache, must-revalidate"); resp.setHeader("Pragma", "public"); } resp.setDateHeader("Expires", nt); resp.setHeader("Cache-Control", "max-age=86400, public"); if (mime != null) { resp.setContentType(mime); } byte[] data = IOUtils.toByteArray(is); IOUtils.closeQuietly(is); resp.setContentLength(data.length); IOUtils.write(data, resp.getOutputStream()); }
From source file:uk.co.caprica.bootlace.security.SecurityConfiguration.java
/** * Create a logout success handler./*from w w w . j av a2 s . c o m*/ * <p> * Simply return an appropriate response code instead of using the default handler that wants * to force a page redirect to "login?logout". * * @return logout success handler */ private LogoutSuccessHandler logoutSuccessHandler() { return new LogoutSuccessHandler() { @Override public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { response.sendError(HttpServletResponse.SC_NO_CONTENT); } }; }
From source file:aiai.ai.launchpad.server.ServerController.java
private HttpEntity<AbstractResource> returnEmptyAsGone(HttpServletResponse response) throws IOException { response.sendError(HttpServletResponse.SC_GONE); return new HttpEntity<>(new ByteArrayResource(new byte[0]), getHeader(0)); }
From source file:aiai.ai.launchpad.server.ServerController.java
private HttpEntity<AbstractResource> returnEmptyAsConflict(HttpServletResponse response) throws IOException { response.sendError(HttpServletResponse.SC_CONFLICT); return new HttpEntity<>(new ByteArrayResource(new byte[0]), getHeader(0)); }
From source file:com.mirth.connect.server.servlets.AlertServlet.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // MIRTH-1745 response.setCharacterEncoding("UTF-8"); if (!isUserLoggedIn(request)) { response.sendError(HttpServletResponse.SC_FORBIDDEN); } else {/* w w w. ja v a2s . c om*/ try { AlertController alertController = ControllerFactory.getFactory().createAlertController(); ObjectXMLSerializer serializer = new ObjectXMLSerializer(); PrintWriter out = response.getWriter(); Operation operation = Operations.getOperation(request.getParameter("op")); Map<String, Object> parameterMap = new HashMap<String, Object>(); if (operation.equals(Operations.ALERT_GET)) { Alert alert = (Alert) serializer.fromXML(request.getParameter("alert")); parameterMap.put("alert", alert); if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { response.setContentType(APPLICATION_XML); serializer.toXML(alertController.getAlert(alert), out); } } else if (operation.equals(Operations.ALERT_UPDATE)) { List<Alert> alerts = (List<Alert>) serializer.fromXML(request.getParameter("alerts")); parameterMap.put("alerts", alerts); if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { alertController.updateAlerts(alerts); } } else if (operation.equals(Operations.ALERT_REMOVE)) { Alert alert = (Alert) serializer.fromXML(request.getParameter("alert")); parameterMap.put("alert", alert); if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { alertController.removeAlert(alert); } } } catch (RuntimeIOException rio) { logger.debug(rio); } catch (Throwable t) { logger.error(ExceptionUtils.getStackTrace(t)); throw new ServletException(t); } } }