List of usage examples for javax.servlet.http HttpServletResponse setStatus
public void setStatus(int sc);
From source file:edu.unc.lib.dl.cdr.sword.server.servlets.ContainerServlet.java
@RequestMapping(value = { "/{pid}", "/{pid}/*" }, method = RequestMethod.GET) public void getDepositReceiptOrStatement(HttpServletRequest req, HttpServletResponse resp) { try {//from w w w . j a v a2 s . c om this.api.get(req, resp); } catch (Exception e) { log.error("Failed to get deposit receipt for " + req.getQueryString(), e); resp.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); } }
From source file:fi.aluesarjat.prototype.AreasServlet.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 w w. java 2s .co m } response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.setDateHeader("Last-Modified", System.currentTimeMillis()); response.setHeader("Cache-Control", "max-age=86400"); String level = request.getParameter("level"); String content; if (level == null) { content = areas; } else if ("1".equals(level)) { content = areas1; } else if ("2".equals(level)) { content = areas2; } else if ("3".equals(level)) { content = areas3; } else if ("4".equals(level)) { content = areas4; } else { throw new IllegalArgumentException("Illegal level " + level); } response.getWriter().append(content); response.getWriter().flush(); }
From source file:net.sourceforge.fenixedu.presentationTier.Action.publico.FileDownload.java
@Override public ActionForward execute(final ActionMapping mapping, final ActionForm actionForm, final HttpServletRequest request, final HttpServletResponse response) throws Exception { final String oid = request.getParameter("oid"); final File file = FenixFramework.getDomainObject(oid); if (file == null) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getWriter().write(HttpStatus.getStatusText(HttpStatus.SC_BAD_REQUEST)); response.getWriter().close();/* w w w . j av a 2 s . c om*/ } else { final Person person = AccessControl.getPerson(); if (!file.isPrivate() || file.isPersonAllowedToAccess(person)) { response.setContentType(file.getContentType()); response.addHeader("Content-Disposition", "attachment; filename=" + file.getFilename()); response.setContentLength(file.getSize().intValue()); final DataOutputStream dos = new DataOutputStream(response.getOutputStream()); dos.write(file.getContents()); dos.close(); } else if (file.isPrivate() && person == null) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.getWriter().write(HttpStatus.getStatusText(HttpStatus.SC_UNAUTHORIZED)); response.getWriter().close(); } else { response.setStatus(HttpServletResponse.SC_FORBIDDEN); response.getWriter().write(HttpStatus.getStatusText(HttpStatus.SC_FORBIDDEN)); response.getWriter().close(); } } return null; }
From source file:gateway.auth.PiazzaBasicAuthenticationEntryPoint.java
@Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authEx) throws IOException, ServletException { response.addHeader("WWW-Authenticate", "Basic realm=\"" + getRealmName() + "\""); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.setContentType("application/json"); PrintWriter writer = response.getWriter(); // Create a Response Object ErrorResponse error = new ErrorResponse("Gateway is unable to authenticate the provided user.", "Gateway"); try {// w ww. j a v a2 s . c om // Log the request logger.log( String.format("Unable to authenticate a user with Auth Type %s and Header %s", request.getAuthType(), request.getHeader("Authorization").toString()), PiazzaLogger.ERROR); } catch (Exception exception) { String errorString = String.format("Exception encountered during Authorization check: %s.", exception.getMessage()); LOGGER.error(errorString, exception); logger.log(errorString, PiazzaLogger.ERROR); } // Write back the response writer.println(new ObjectMapper().writeValueAsString(error)); }
From source file:net.prasenjit.auth.config.CustomAjaxAwareHandler.java
/** {@inheritDoc} */ @Override// w w w .j a v a 2 s . co m public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { if (checkIfAjaxRequest(request)) { response.setStatus(HttpStatus.UNAUTHORIZED.value()); } else { delegatedAuthenticationEntryPoint.commence(request, response, authException); } }
From source file:org.cryptoworkshop.ximix.console.handlers.ConsoleHandler.java
private void writeObject(Object o, HttpServletResponse resp) throws IOException { resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType("application/json"); OutputStream os = resp.getOutputStream(); objectMapper.writeValue(os, o);//w ww. j a v a 2 s . co m os.flush(); os.close(); }
From source file:org.codeqinvest.web.investment.QualityInvestmentPlanController.java
@RequestMapping(value = "/projects/{projectId}/investment", method = RequestMethod.PUT) @ResponseBody//from ww w.jav a 2 s. c om QualityInvestmentPlan generateInvestmentPlan(@PathVariable long projectId, @RequestBody InvestmentPlanRequest investmentPlanRequest, BindingResult errors, HttpServletRequest request, HttpServletResponse response) throws InvestmentParsingException { investmentPlanRequestValidator.validate(investmentPlanRequest, errors); if (errors.hasErrors()) { response.setStatus(400); return null; } Project project = projectRepository.findOne(projectId); if (project == null) { response.setStatus(400); return null; } QualityAnalysis lastAnalysis = lastQualityAnalysisService.retrieveLastSuccessfulAnalysis(project); if (lastAnalysis == null) { response.setStatus(400); return null; } int investmentInMinutes = investmentAmountParser.parseMinutes(investmentPlanRequest.getInvestment()); QualityInvestmentPlan investmentPlan = investmentPlanService.computeInvestmentPlan(lastAnalysis, investmentPlanRequest.getBasePackage(), investmentInMinutes); requirementCodeConverter.convertRequirementCodeToLocalizedMessage(request, investmentPlan); return investmentPlan; }
From source file:feedme.controller.AddOrDeleteCategoryServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response);/* w w w. j ava2 s . c o m*/ request.setCharacterEncoding("UTF-8"); response.setStatus(HttpServletResponse.SC_OK); String CategoryName = request.getParameter("categoryName").trim(); DbRestaurantsManagement ob = new DbRestaurantsManagement(); boolean flag = false; HashMap<String, Integer> cat = new DbHPOnLoad().getCategories(); for (String se : cat.keySet()) { if (se.contains(CategoryName)) flag = true; } int result = 0; if (!flag) result = ob.addNewCategory(CategoryName); PrintWriter out = response.getWriter(); if (result == 1) { if (isAjax(request) == true) { // Stay in the same page, and sand json message try { cat = new DbHPOnLoad().getCategories(); JSONObject catObj = new JSONObject(); JSONArray catArray = new JSONArray(); for (Entry<String, Integer> entry : cat.entrySet()) { catArray.put( new JSONObject().put("cat_id", entry.getValue()).put("cat_name", entry.getKey())); } catObj.put("categories", catArray); catObj.put("status", true); response.setContentType("application/json"); PrintWriter writer = response.getWriter(); writer.print(catObj); response.getWriter().flush(); } catch (JSONException e) { e.printStackTrace(); } } else { // redirect to othe page } } }
From source file:es.logongas.ix3.web.util.ControllerHelper.java
public void objectToHttpResponse(HttpResult httpResult, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { httpServletResponse.setStatus(httpResult.getHttpSuccessStatus()); MimeType mimeType;/*from w w w. j a v a 2s. co m*/ if (httpResult.isCache()) { cache(httpServletResponse); } else { noCache(httpServletResponse); } if (httpResult.getMimeType() == null) { mimeType = MimeType.JSON; } else { mimeType = httpResult.getMimeType(); } httpServletResponse.setContentType(mimeType.getText()); if (httpResult.getResult() != null) { switch (mimeType) { case JSON: JsonWriter jsonWriter = jsonFactory.getJsonWriter(httpResult.getResultClass()); Expands expands = getRequestExpands(httpServletRequest); BeanMapper beanMapper; if (httpResult.getBeanMapper() != null) { beanMapper = httpResult.getBeanMapper(); } else { beanMapper = getEndPoint(httpServletRequest).getBeanMapper(); } String jsonOut = jsonWriter.toJson(httpResult.getResult(), expands, beanMapper); httpServletResponse.getWriter().println(jsonOut); break; case OCTET_STREAM: if (httpResult.getResult() instanceof byte[]) { byte[] result = (byte[]) httpResult.getResult(); httpServletResponse.getOutputStream().write(result); httpServletResponse.getOutputStream().flush(); httpServletResponse.getOutputStream().close(); } else { throw new RuntimeException( "Si el MimeType es OCTET_STREAM es tipo de result debe ser byte[] pero es " + httpResult.getResult().getClass().getName()); } break; default: throw new RuntimeException("MimeType no soportado:" + httpResult.getMimeType()); } } }
From source file:eu.trentorise.smartcampus.permissionprovider.controller.BasicProfileController.java
@RequestMapping(method = RequestMethod.GET, value = "/basicprofile/me") public @ResponseBody BasicProfile findProfile(HttpServletResponse response) throws IOException { try {/*from w w w.ja va2s .c o m*/ Long user = getUserId(); if (user == null) { response.setStatus(HttpServletResponse.SC_FORBIDDEN); return null; } return profileManager.getBasicProfileById(user.toString()); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return null; } }