List of usage examples for javax.servlet.http HttpServletResponse setStatus
public void setStatus(int sc);
From source file:com.liferay.arquillian.DeployerServlet.java
private void signalError(Throwable t, HttpServletResponse response) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); try {/* ww w. j a v a 2 s .c o m*/ ServletOutputStream outputStream = response.getOutputStream(); response.setContentType(StringPool.UTF8); PrintWriter printWriter = new PrintWriter(outputStream); t.printStackTrace(printWriter); printWriter.flush(); } catch (IOException e) { e.printStackTrace(); } }
From source file:de.undercouch.gradle.tasks.download.HeadersTest.java
@Override protected Handler[] makeHandlers() throws IOException { //echo X-* headers back in response body ContextHandler echoHeadersHandler = new ContextHandler("/" + ECHO_HEADERS) { @Override// w w w . j av a2s . c o m public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException { response.setStatus(200); PrintWriter rw = response.getWriter(); rw.write(HEADERS + "\n"); @SuppressWarnings("unchecked") Enumeration<String> headerNames = (Enumeration<String>) request.getHeaderNames(); while (headerNames.hasMoreElements()) { String name = headerNames.nextElement(); if (name.startsWith("X-")) { rw.write(String.format(" %s: %s\n", name, request.getHeader(name))); } } rw.close(); } }; return new Handler[] { echoHeadersHandler }; }
From source file:hr.diskobolos.controller.FinancialResourcesController.java
/** * REST service responsible for editing financial resources data * * @param financialResourcesDto/*from w w w . j av a2s .com*/ * @param request * @param response * @return * @throws JSONException */ @RequestMapping(value = "/edit", method = RequestMethod.POST) @ResponseBody @PreAuthorize("hasAnyRole('ROLE_USER','ROLE_ADMIN')") public String editFinancialResourcesData(@RequestBody FinancialResourcesDto financialResourcesDto, HttpServletRequest request, HttpServletResponse response) throws JSONException { try { financialResourcesService.bulkSave(financialResourcesDto.getFinancialResources()); response.setStatus(HttpServletResponse.SC_OK); return new JSONObject().put("result", 200).toString(); } catch (Exception e) { logger.error("Error during editing financial resources data: ", e.getMessage()); return ErrorHandlerUtils.handleAjaxError(request, response); } }
From source file:org.magnum.mobilecloud.video.VideoSvcCtrl.java
@PreAuthorize("hasRole(USER)") @RequestMapping(method = RequestMethod.GET, value = VideoSvcApi.VIDEO_SVC_PATH + "/{id}") public @ResponseBody Video getVideoById(@PathVariable("id") long id, HttpServletResponse response) { Video ret = videoRepo.findOne(id);//from w ww . j a v a2 s .c om if (ret == null) response.setStatus(HttpServletResponse.SC_NOT_FOUND); else response.setStatus(HttpServletResponse.SC_OK); return ret; }
From source file:de.undercouch.gradle.tasks.download.InterceptorTest.java
@Override protected Handler[] makeHandlers() throws IOException { ContextHandler contentLengthHandler = new ContextHandler("/" + INTERCEPTOR) { @Override/* w w w.j a va 2 s .c o m*/ public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException { response.setStatus(200); String message = UNINTERCEPTED; String addValue = request.getHeader(ADDITIONAL_REQUEST_HEADER_KEY); if (addValue != null) { message += ":" + addValue; } PrintWriter rw = response.getWriter(); rw.write(message); rw.close(); } }; return new Handler[] { contentLengthHandler }; }
From source file:edu.cornell.mannlib.vitro.webapp.controller.admin.SparqlQueryController.java
private void do400BadRequest(String message, HttpServletResponse resp) throws IOException { resp.setStatus(400); resp.getWriter().println(message);/* w w w .j av a 2 s . co m*/ }
From source file:org.ednovo.gooru.controller.ScreenshotController.java
/** * Get and check parameters/* www . j av a 2s . com*/ * * @param sourceUrl * (URL should be encoded) * @param width * @param height * @param request * @param response * @throws Exception */ @RequestMapping(method = RequestMethod.GET, value = "/snapshot/generate/{width}/{height}") public void getScreenshot(@PathVariable(value = "width") int width, @PathVariable(value = "height") int height, @RequestParam(value = "SourceUrl", required = true) String sourceUrl, HttpServletRequest request, HttpServletResponse response) throws Exception { sourceUrl = URLDecoder.decode(sourceUrl, ENCODE_FORMAT); if (checkUrl(sourceUrl)) { response.setStatus(400); response.getWriter().append(INVALID_URL); return; } else { response.getOutputStream().write(getWebDriverUtil().generateScreenshot(sourceUrl, width, height)); } }
From source file:com.liangc.hq.base.web.AvailabilityBaseServlet.java
protected void sendIcon(HttpServletRequest request, HttpServletResponse response, String url) throws IOException { response.setStatus(HttpServletResponse.SC_OK); response.setContentType("image/gif"); IconBytes icon = (IconBytes) iconData.get(url); response.setContentLength(icon.getLength()); response.getOutputStream().write(icon.getBytes()); response.flushBuffer();/* w w w .j a v a2s . c om*/ }
From source file:edu.cornell.mannlib.vitro.webapp.controller.admin.SparqlQueryController.java
private void do400BadRequest(String message, Exception e, HttpServletResponse resp) throws IOException { resp.setStatus(400); PrintWriter w = resp.getWriter(); w.println(message);/* w w w . java2 s.c om*/ e.printStackTrace(w); }
From source file:de.thm.arsnova.controller.UserController.java
@RequestMapping(value = { "/{username}/resetpassword" }, method = RequestMethod.POST) public void resetPassword(@PathVariable final String username, @RequestParam(required = false) final String key, @RequestParam(required = false) final String password, final HttpServletRequest request, final HttpServletResponse response) { DbUser dbUser = userService.getDbUser(username); if (null == dbUser) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); return;/*www . j a v a 2 s . com*/ } if (null != key) { if (!userService.resetPassword(dbUser, key, password)) { response.setStatus(HttpServletResponse.SC_FORBIDDEN); } } else { userService.initiatePasswordReset(username); } }