List of usage examples for javax.servlet.http HttpServletResponse SC_OK
int SC_OK
To view the source code for javax.servlet.http HttpServletResponse SC_OK.
Click Source Link
From source file:com.sketchy.server.JsonServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); String pathInfo = request.getPathInfo(); if (pathInfo.startsWith("/")) pathInfo = StringUtils.substringAfter(pathInfo, "/"); String action = ACTION_PACKAGE + pathInfo; JSONServletResult jsonServletResult = null; try {/*w ww.j a v a 2 s . co m*/ ServletAction servletAction = ServletAction.getInstance(action); jsonServletResult = servletAction.execute(request); } catch (ClassNotFoundException e) { jsonServletResult = new JSONServletResult(Status.ERROR, "ServletAction '" + pathInfo + "' not found! " + e.getMessage()); } catch (Exception e) { jsonServletResult = new JSONServletResult(Status.ERROR, "Unexpected Exception from ServletAction '" + pathInfo + "'! " + e.getMessage()); } response.setStatus(HttpServletResponse.SC_OK); response.getWriter().println(jsonServletResult.toJSONString()); }
From source file:com.skymobi.monitor.action.LogsAction.java
@RequestMapping(value = "/projects/{projectName}/logs/download", method = RequestMethod.GET) public void download(final HttpServletResponse response, ModelMap map, @PathVariable String projectName, LogQuery logQuery) throws IOException, ParseException { Project project = projectService.findProject(projectName); final MongoConverter converter = project.fetchMongoTemplate().getConverter(); final DBCursor cursor = logsService.findLogs(projectName, logQuery, 100000); response.setContentType("file/txt;charset=utf-8"); response.addHeader("content-disposition", String.format("attachment; filename=%s.txt", java.net.URLEncoder.encode("logs", "UTF-8"))); response.setStatus(HttpServletResponse.SC_OK); while (cursor.hasNext()) { Log log = converter.read(Log.class, cursor.next()); response.getWriter().println(log.toString()); }/*from ww w . j a v a2s . c om*/ }
From source file:com.fpmislata.banco.presentation.controladores.CuentaBancariaController.java
@RequestMapping(value = "/cuentabancaria", method = RequestMethod.POST, consumes = "application/json", produces = "application/json") public void insert(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, @RequestBody String jsonEntrada) throws IOException { try {/* w ww .j av a2 s . c o m*/ CuentaBancaria cuentaBancaria = (CuentaBancaria) jsonTransformer.fromJsonToObject(jsonEntrada, CuentaBancaria.class); cuentaBancariaService.insert(cuentaBancaria); String jsonSalida = jsonTransformer.ObjectToJson(cuentaBancaria); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.setContentType("application/json; charset=UTF-8"); httpServletResponse.getWriter().println(jsonSalida); } catch (BusinessException ex) { List<BusinessMessage> bussinessMessage = ex.getBusinessMessages(); String jsonSalida = jsonTransformer.ObjectToJson(bussinessMessage); httpServletResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST); httpServletResponse.setContentType("application/json; charset=UTF-8"); httpServletResponse.getWriter().println(jsonSalida); } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:com.vmware.photon.controller.api.common.filters.LoggingFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request instanceof HttpServletRequest) { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; String requestId = requestIdProvider.get().toString(); LoggingUtils.setRequestId(requestId); logger.debug("Request: {} {}", httpRequest.getMethod(), httpRequest.getPathInfo()); StopWatch stopwatch = new StopWatch(); stopwatch.start();//from w w w . j a v a 2s. c o m try { chain.doFilter(request, response); } finally { stopwatch.stop(); String msg = String.format("Response: %s [%s] in %sms", httpRequest.getPathInfo(), httpResponse.getStatus(), stopwatch.getTime()); if (httpResponse.getStatus() == HttpServletResponse.SC_OK) { logger.debug(msg); } else { logger.info(msg); } LoggingUtils.clearRequestId(); } } else { chain.doFilter(request, response); } }
From source file:org.obm.healthcheck.server.HealthCheckServletOneHandlerTest.java
@Test public void testRootUrl() throws Exception { HttpResponse response = get("/"); Map<String, String> expected = ImmutableMap.of("method", "GET", "path", "/testing/string"); assertThat(response.getStatusLine().getStatusCode()).isEqualTo(HttpServletResponse.SC_OK); Object[] result = (Object[]) JSON.parse(IO.toString(response.getEntity().getContent())); assertThat(result).containsOnly(expected); }
From source file:hr.diskobolos.controller.MembershipCategoryController.java
/** * REST service responsible for editing membership category data * * @param membershipCategory//from w w w .j a v a 2 s . co m * @param request * @param response * @return * @throws JSONException */ @RequestMapping(value = "/edit", method = RequestMethod.POST) @ResponseBody @PreAuthorize("hasAnyRole('ROLE_USER','ROLE_ADMIN')") public String editMembershipCategorysData(@RequestBody MembershipCategory membershipCategory, HttpServletRequest request, HttpServletResponse response) throws JSONException { try { membershipCategoryService.update(membershipCategory); response.setStatus(HttpServletResponse.SC_OK); return new JSONObject().put("result", 200).toString(); } catch (Exception e) { logger.error("Error during editing membership category data: ", e.getMessage()); return ErrorHandlerUtils.handleAjaxError(request, response); } }
From source file:fr.gael.dhus.api.SearchController.java
@PreAuthorize("hasRole('ROLE_SEARCH')") @RequestMapping(value = "/search/suggest/{query}") public void suggestions(@PathVariable String query, HttpServletResponse res) throws IOException { List<String> suggestions = searchService.getSuggestions(query); res.setStatus(HttpServletResponse.SC_OK); res.setContentType("text/plain"); try (ServletOutputStream outputStream = res.getOutputStream()) { if (suggestions != null) { for (String suggestion : suggestions) { outputStream.println(suggestion); }/*from ww w . j ava 2 s . com*/ } } }
From source file:com.excella.deploy.agent.core.DynamicCommandServlet.java
/** * COMMENT DynamicCommandServlet.success() */*from w w w.j a v a 2 s .c om*/ * @param execute * @param response * @param request */ protected void success(String execute, HttpServletRequest request, HttpServletResponse response) { try { log.debug("Attempting to respond with a success..."); response.setContentType("text/html"); response.setStatus(HttpServletResponse.SC_OK); PrintWriter writer = response.getWriter(); writer.println("<h1>SUCCESS</h1>"); writer.println("<p>"); writer.println(execute); writer.println("</p>"); ((Request) request).setHandled(true); } catch (Exception e) { log.error("Failed to respond with a success.", e); } }
From source file:com.mockey.storage.file.FileUploadOctetStreamReaderServlet.java
/** * Handles the HTTP <code>POST</code> method. * //from w ww.j a v a 2s .c o m * @param request * servlet request * @param response * servlet response * @throws ServletException * if a servlet-specific error occurs * @throws IOException * if an I/O error occurs */ @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException { PrintWriter writer = null; InputStream is = null; FileOutputStream fos = null; try { writer = response.getWriter(); } catch (IOException ex) { log(FileUploadOctetStreamReaderServlet.class.getName() + "has thrown an exception: " + ex.getMessage()); } try { String filename = URLDecoder.decode(request.getHeader("X-File-Name"), "UTF-8"); is = request.getInputStream(); FileSystemManager fsm = new FileSystemManager(); File fileToWriteTo = fsm.getImageFile(filename); fos = new FileOutputStream(fileToWriteTo); IOUtils.copy(is, fos); response.setStatus(HttpServletResponse.SC_OK); writer.print("{success: true}"); } catch (FileNotFoundException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); writer.print("{success: false}"); log(FileUploadOctetStreamReaderServlet.class.getName() + "has thrown an exception: " + ex.getMessage()); } catch (IOException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); writer.print("{success: false}"); log(FileUploadOctetStreamReaderServlet.class.getName() + "has thrown an exception: " + ex.getMessage()); } finally { try { if (fos != null) { fos.close(); } } catch (IOException ignored) { } try { if (is != null) { is.close(); } } catch (IOException ignored) { } } writer.flush(); writer.close(); }
From source file:com.appleframework.monitor.action.LogsAction.java
@RequestMapping(value = "/projects/{projectName}/logs/download", method = RequestMethod.GET) public void download(final HttpServletResponse response, ModelMap map, @PathVariable String projectName, LogQuery logQuery) throws IOException, ParseException { Project project = projectService.findProject(projectName); final MongoConverter converter = project.fetchMongoTemplate().getConverter(); final DBCursor cursor = logsService.findLogs(projectName, logQuery, 100000); response.setContentType("file/txt;charset=utf-8"); response.addHeader("content-disposition", String.format("attachment; filename=%s.txt", java.net.URLEncoder.encode("logs", "UTF-8"))); response.setStatus(HttpServletResponse.SC_OK); while (cursor.hasNext()) { Log log = converter.read(Log.class, cursor.next()); response.getWriter().println(log.toString()); }/*w w w . java2 s .c om*/ }