List of usage examples for javax.servlet.http HttpServletResponse setStatus
public void setStatus(int sc);
From source file:hr.diskobolos.config.security.authentication.CustomLogoutHandler.java
@Override public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) { Integer userId = Integer.valueOf(request.getParameter("userId")); logger.info("Prelogut actions for user with ID: " + userId); userService.preLogoutActions(userId); response.setStatus(HttpServletResponse.SC_OK); }
From source file:fi.aluesarjat.prototype.SubjectGraphServlet.java
@Override public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; long ifModifiedSince = request.getDateHeader("If-Modified-Since"); if (ifModifiedSince >= LAST_MODIFIED) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return;//from w ww.j ava2 s. c o m } String subject = request.getRequestURL().toString(); RDFConnection connection = repository.openConnection(); try { SPARQLQuery query = connection.createQuery(QueryLanguage.SPARQL, "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }"); query.setBinding("s", new UID(subject)); String contentType = getAcceptedType(request, Format.RDFXML); response.setDateHeader("Last-Modified", System.currentTimeMillis()); response.setContentType(contentType); query.streamTriples(response.getWriter(), contentType); } finally { connection.close(); } }
From source file:com.baidu.stqa.signet.web.common.exception.ExceptionResolver.java
@Override protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { Object errors = null;/*from w w w . j a va 2s. co m*/ if (ex instanceof MethodArgumentNotValidException) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); errors = getDecorateErrors(ex); } else { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); errors = ex.getMessage(); LOGGER.error(ex); } ObjectMapper mapper = new ObjectMapper(); String errorJson = "Error occur when covert object to json!"; try { errorJson = mapper.writeValueAsString(errors); } catch (Exception e) { e.printStackTrace(); } ServletOutputStream outputStream = null; try { outputStream = response.getOutputStream(); outputStream.write(errorJson.getBytes()); } catch (IOException e) { e.printStackTrace(); } finally { if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } return null; }
From source file:de.yaio.services.metaextract.server.controller.MetaExtractController.java
@ExceptionHandler(ExtractorException.class) public void handleCustomException(final HttpServletRequest request, final ExtractorException e, final HttpServletResponse response) throws IOException { LOGGER.info("ExtractorException while running request:" + createRequestLogMessage(request), e); response.setStatus(SC_BAD_REQUEST); response.getWriter().append("exception while extracting metadata for requested resource"); }
From source file:byps.test.servlet.BypsServlet.java
/** * Overrides the testAdapter function in order to modify the application * version.//from w ww . j a v a2s . com */ @Override protected void doTestAdapter(HttpServletRequest request, HttpServletResponse response) throws IOException { if (!config.isTestAdapterEnabled()) { response.setStatus(HttpServletResponse.SC_FORBIDDEN); return; } final String testAdapter = request.getParameter(HTestAdapter.KEY_PARAM); if (testAdapter == null) { response.setStatus(HttpServletResponse.SC_FORBIDDEN); return; } if (testAdapter.equals(HTestAdapter.SET_SERVER_APP_VERSION)) { String versionStr = request.getParameter(HTestAdapter.VERSION); MySession.appVersion = Integer.parseInt(versionStr); return; } super.doTestAdapter(request, response); }
From source file:com.pymegest.applicationserver.api.SessionController.java
@RequestMapping(value = { "/Session" }, method = RequestMethod.DELETE) public void delete(HttpServletRequest httpServletRequest, HttpServletResponse response) { try {/*from ww w .j av a 2 s. c om*/ httpServletRequest.getSession(true).invalidate(); response.setStatus(HttpServletResponse.SC_NO_CONTENT); } catch (Exception ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); response.setContentType("text/plain; charset=UTF-8"); try { ex.printStackTrace(response.getWriter()); } catch (IOException ex1) { } } }
From source file:de.yaio.services.metaextract.server.controller.MetaExtractController.java
@ExceptionHandler(PermissionException.class) public void handleCustomException(final HttpServletRequest request, final PermissionException e, final HttpServletResponse response) throws IOException { LOGGER.info("PermissionException while running request:" + createRequestLogMessage(request), e); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getWriter()/*from w w w . j av a2 s.c o m*/ .append("permission denied (firewall...) while extracting metadata for requested resource"); }
From source file:de.yaio.services.metaextract.server.controller.MetaExtractController.java
@ExceptionHandler(IOExceptionWithCause.class) public void handleCustomException(final HttpServletRequest request, final IOExceptionWithCause e, final HttpServletResponse response) throws IOException { LOGGER.info("IOExceptionWithCause while running request:" + createRequestLogMessage(request), e); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getWriter().append("url-get failed while extracting metadata for requested resource:"); response.getWriter().append(e.getCause().getMessage()); }
From source file:org.magnum.dataup.VideoSvcUp.java
@RequestMapping(value = VideoSvcApi.VIDEO_DATA_PATH, method = RequestMethod.POST) public @ResponseBody VideoStatus setVideoData(@PathVariable(VideoSvcApi.ID_PARAMETER) long id, @RequestParam(VideoSvcApi.DATA_PARAMETER) MultipartFile data, HttpServletResponse response) throws IOException { if (!videos.containsKey(id)) { System.out.println("ID Not found"); response.setStatus(HttpStatus.NOT_FOUND.value()); } else {/*from w w w .ja v a 2s.c om*/ Video v = videos.get(id); //System.out.println("Vishal's video id: " + v.getId() + " url: " + v.getDataUrl() // + " title:" + v.getTitle() + " Content type:" + v.getContentType() + // " Subject:" + v.getSubject()); videoDataMgr = VideoFileManager.get(); //singleton if (videoDataMgr.hasVideoData(v)) { System.out.println("Notice: Overwriting video at id: " + v.getId()); } videoDataMgr.saveVideoData(v, data.getInputStream()); } return new VideoStatus(VideoState.READY); }
From source file:com.github.rabid_fish.proxy.servlet.SoapServlet.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter writer = response.getWriter(); response.setStatus(HttpServletResponse.SC_OK); response.setContentType("text/xml"); try {/* ww w.j ava 2 s .c o m*/ ServletInputStream stream = request.getInputStream(); String requestBody = IOUtils.toString(stream); Integer mathResult = getMathResult(requestBody); writeMathResult(writer, mathResult); } catch (Exception e) { writeSoapError(writer, e.getMessage()); } writer.flush(); writer.close(); }