List of usage examples for javax.servlet.http HttpServletResponse setStatus
public void setStatus(int sc);
From source file:com.googlecode.webutilities.servlets.WebProxyServlet.java
private void copyResponse(CloseableHttpResponse fromResponse, HttpServletResponse toResponse) throws IOException { toResponse.setStatus(fromResponse.getStatusLine().getStatusCode()); for (Header header : fromResponse.getAllHeaders()) { toResponse.setHeader(header.getName(), header.getValue()); }//from w w w.ja v a 2s . c o m HttpEntity entity = fromResponse.getEntity(); IOUtils.copy(entity.getContent(), toResponse.getOutputStream()); }
From source file:authentication.DefaultAuthenticationFailureHandler.java
/** {@inheritDoc} */ @Override// w w w . j a va 2 s . c o m public void onAuthenticationFailure(final HttpServletRequest request, final HttpServletResponse response, final AuthenticationException exception) throws IOException { response.setContentType(MediaType.APPLICATION_JSON_VALUE); response.setStatus(HttpStatus.UNAUTHORIZED.value()); response.getOutputStream() .print(String.format(JSON, HttpStatus.UNAUTHORIZED.value(), exception.getMessage())); }
From source file:com.sg.dvdlibrary.controller.HomeController.java
@RequestMapping(value = "/addDvd", method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED)/* w w w . j ava 2s . c o m*/ @ResponseBody public Dvd createEntry(@Valid @RequestBody Dvd dvd, HttpServletResponse response) { if (!dvd.getTitle().equals(".")) { dao.addEntry(dvd); } else { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } return dvd; }
From source file:Core.Security.CustomEntryPoint.java
public void commence(final HttpServletRequest request, final HttpServletResponse response, final AuthenticationException authException) throws IOException, ServletException { //Authentication failed, send error response. response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.addHeader("WWW-Authenticate", "Basic realm=" + getRealmName() + ""); PrintWriter writer = response.getWriter(); writer.println("HTTP Status 401 : " + authException.getMessage()); }
From source file:org.magnum.dataup.VideoSvcUp.java
@RequestMapping(value = VideoSvcApi.VIDEO_DATA_PATH, method = RequestMethod.GET) public @ResponseBody void getVideoData(@PathVariable(VideoSvcApi.ID_PARAMETER) long id, HttpServletResponse response) throws IOException { if (!videos.containsKey(id)) { response.setStatus(HttpStatus.NOT_FOUND.value()); } else {//from w ww .j ava 2s. c om Video v = videos.get(id); videoDataMgr.copyVideoData(v, response.getOutputStream()); } }
From source file:org.vbossica.springbox.metrics.PingController.java
@RequestMapping(value = "/metrics/ping", method = RequestMethod.GET) public void process(HttpServletResponse resp) throws IOException { resp.setContentType("text/plain"); resp.setHeader("Cache-Control", "must-revalidate,no-cache,no-store"); resp.setStatus(HttpServletResponse.SC_OK); if (message != null || message.isEmpty()) { PrintWriter writer = resp.getWriter(); try {//from w ww .ja v a 2 s.co m writer.println(message); } finally { writer.close(); } } }
From source file:de.undercouch.gradle.tasks.download.SslTest.java
@Override protected Handler[] makeHandlers() throws IOException { ContextHandler sslHandler = new ContextHandler("/" + SSL) { @Override//from w w w. j a v a2s . co m public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException { response.setStatus(200); PrintWriter rw = response.getWriter(); rw.write("Hello"); rw.close(); } }; return new Handler[] { sslHandler }; }
From source file:com.jamespot.glifpix.wrappers.SampleHtmlTestService.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); response.setStatus(HttpServletResponse.SC_OK); PrintWriter out = response.getWriter(); String htmlPage = FileUtils.readFileToString(new File(props.getProperty("tagsServer.testPage"))); out.println(htmlPage);/*from w w w . j av a 2 s . co m*/ }
From source file:de.codecentric.boot.admin.actuate.LogfileMvcEndpoint.java
@RequestMapping(method = RequestMethod.GET) public void invoke(HttpServletResponse response) throws IOException { if (!isAvailable()) { response.setStatus(HttpStatus.NOT_FOUND.value()); return;//w ww .ja va 2s .co m } Resource file = new FileSystemResource(logfile); response.setContentType(MediaType.TEXT_PLAIN_VALUE); response.setHeader("Content-Disposition", "attachment; filename=\"" + file.getFilename() + "\""); FileCopyUtils.copy(file.getInputStream(), response.getOutputStream()); }
From source file:info.raack.appliancelabeler.web.BaseController.java
@ExceptionHandler public ModelAndView handleUncaughtException(Exception ex, HttpServletRequest request, HttpServletResponse response) throws IOException { if (ex instanceof AccessDeniedException) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); } else if (ex instanceof OAuthUnauthorizedException) { /*if(request.getSession() != null) { request.getSession().invalidate(); }// ww w . j a v a 2s. c om SecurityContextHolder.getContext().setAuthentication(null);*/ try { response.sendRedirect("/t/logout.do"); logger.warn("Could not authorize oauth request", ex); } catch (IOException e1) { logger.error("Could not send redirect", e1); } return null; } else if (ex instanceof ClientAPIException) { if (ex.getCause() != null && ex.getCause() instanceof OAuthUnauthorizedException) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); } else { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } response.getOutputStream().write(ex.getMessage().getBytes()); return null; } else { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); errorService.reportError("Error while processing user web page request", URGENCY.URGENT, ex); logger.error("An exception was caught while processing", ex); } return templateProvider.showPageInTemplate(1, "error/basic", new ModelMap()); }