List of usage examples for javax.servlet.http HttpServletResponse sendError
public void sendError(int sc) throws IOException;
From source file:io.nebo.container.RequestDispatcherHandler.java
@Override protected void channelRead0(ChannelHandlerContext ctx, NettyHttpServletRequest request) throws Exception { HttpServletResponse servletResponse = (HttpServletResponse) request.getServletResponse(); try {//w w w. j a v a 2 s . c om NettyRequestDispatcher dispatcher = (NettyRequestDispatcher) context .getRequestDispatcher(request.getRequestURI()); if (dispatcher == null) { servletResponse.sendError(404); return; } dispatcher.dispatch(request, servletResponse); servletResponse.getWriter().flush(); servletResponse.getOutputStream().flush(); servletResponse.getWriter().close(); servletResponse.getOutputStream().close(); } catch (Exception e) { e.printStackTrace(); } finally { if (!request.isAsyncStarted()) { servletResponse.getOutputStream().close(); } } }
From source file:com.thinkberg.moxo.dav.DeleteHandler.java
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { FileObject object = getResourceManager().getFileObject(request.getPathInfo()); if (request instanceof Request) { String fragment = ((Request) request).getUri().getFragment(); if (fragment != null) { response.sendError(HttpServletResponse.SC_FORBIDDEN); return; }// w w w . j a v a 2 s . c o m } try { LockManager.getInstance().checkCondition(object, getIf(request)); } catch (LockException e) { if (e.getLocks() != null) { response.sendError(SC_LOCKED); } else { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); } return; } if (object.exists()) { if (object.delete(ALL_FILES_SELECTOR) > 0) { response.setStatus(HttpServletResponse.SC_OK); } else { response.sendError(HttpServletResponse.SC_FORBIDDEN); } } else { response.sendError(HttpServletResponse.SC_NOT_FOUND); } }
From source file:jp.aegif.nemaki.rest.AuthenticationFilter.java
@Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest hreq = (HttpServletRequest) req; HttpServletResponse hres = (HttpServletResponse) res; boolean auth = login(hreq, hres); if (auth) {// w w w. j a v a2 s .co m chain.doFilter(req, res); } else { log.error("REST API Unauthorized!"); hres.sendError(HttpServletResponse.SC_UNAUTHORIZED); } }
From source file:com.haulmont.cuba.core.controllers.FileUploadController.java
private FileDescriptor getFileDescriptor(HttpServletRequest request, HttpServletResponse response) throws IOException { FileDescriptor fd;//from w ww .ja v a 2 s . c o m try { fd = FileDescriptor.fromUrlParam(request.getParameter("f")); } catch (Exception e) { log.error("Error parsing FileDescriptor from URL param", e); response.sendError(HttpServletResponse.SC_BAD_REQUEST); return null; } return fd; }
From source file:io.hakbot.controller.servlet.ConsoleControllerServlet.java
private void doRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { final String pathInfo = request.getPathInfo(); final String uuid; // Check to make sure path info was specified if (StringUtils.isEmpty(pathInfo)) { response.sendError(400); return;/*from w w w . j av a 2 s.c om*/ } else { // Path info was specified so strip off the leading / character uuid = StringUtils.stripStart(pathInfo, "/"); } // Check to make sure the uuid is a valid format if (!UuidUtil.isValidUUID(uuid)) { response.sendError(400); return; } final QueryManager qm = new QueryManager(); final Job job = qm.getJob(uuid, new SystemAccount()); qm.close(); if (job == null) { response.sendError(404); return; } final ExpectedClassResolver resolver = new ExpectedClassResolver(); try { final Class pluginClass = resolver.resolveProvider(job); request.setAttribute("job", job); final String pluginPage = "/WEB-INF/plugins/" + pluginClass.getName() + "/index.jsp?uuid=" + uuid; response.setContentType("text/html;charset=UTF-8"); request.getRequestDispatcher(pluginPage).include(request, response); return; } catch (ClassNotFoundException | ExpectedClassResolverException e) { LOGGER.error(e.getMessage()); } response.sendError(404); }
From source file:no.dusken.common.view.FileView.java
protected void renderMergedOutputModel(Map map, HttpServletRequest request, HttpServletResponse response) throws IOException { // get the file from the map File file = (File) map.get("file"); // check if it exists if (file == null || !file.exists() || !file.canRead()) { log.warn("Error reading: {}", file); try {//from www.j a v a2s. c o m response.sendError(404); } catch (IOException e) { log.error("Could not write to response", e); } return; } // give some info in the response String mimeType; if (file.getName().contains(".image")) { mimeType = "image/jpeg"; } else { mimeType = getServletContext().getMimeType(file.getAbsolutePath()); } response.setContentType(mimeType); // files does not change so often, allow three days caching response.setHeader("Cache-Control", "public, max-age=2505600"); response.setContentLength((int) file.length()); // start writing to the response OutputStream outputStream = response.getOutputStream(); InputStream inputStream = new FileInputStream(file); IOUtils.copy(inputStream, outputStream); }
From source file:arena.web.view.ErrorView.java
@SuppressWarnings("unchecked") protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { if (this.message != null) { response.setStatus(this.errorCode); response.getWriter()// ww w. j a v a 2 s . com .append(ServletUtils.replaceWildcards(this.message, this.allowRequestArgs, model, request)); response.flushBuffer(); } else { response.sendError(this.errorCode); } }
From source file:org.callistasoftware.netcare.web.mobile.controller.BankIdController.java
@RequestMapping(value = "/complete", method = RequestMethod.GET, produces = "application/json") @ResponseBody//from w w w. j a v a2 s . c o m public UserDetails collect(final HttpServletResponse response) throws IOException { final Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth != null) { return (UserDetails) auth.getPrincipal(); } log.debug("We have no authentication.. Returning unathorized."); response.sendError(HttpServletResponse.SC_UNAUTHORIZED); return null; }
From source file:com.github.rnewson.couchdb.lucene.LuceneServlet.java
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { try {//ww w.jav a 2s . c o m doGetInternal(req, resp); } catch (final JSONException e) { resp.sendError(500); } }
From source file:com.github.rnewson.couchdb.lucene.LuceneServlet.java
@Override protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { try {//w ww. j a va 2 s . c om doPostInternal(req, resp); } catch (final JSONException e) { resp.sendError(500); } }