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:org.magnum.mobilecloud.video.AFilledController.java
private void setLike(long id, String user, HttpServletResponse res, boolean isLike) { Video v = videos.findOne(id);/*from w w w .j ava2 s . co m*/ int code = HttpServletResponse.SC_OK; if (v == null) { code = HttpServletResponse.SC_NOT_FOUND; } else { if (isLike ? v.addLikedUser(user) : v.removeLikedUser(user)) { videos.save(v); } else { code = HttpServletResponse.SC_BAD_REQUEST; } } res.setStatus(code); }
From source file:com.wso2telco.workflow.api.WorkflowHistoryAPI.java
@GET @Path("/subscribers") @Produces(MediaType.APPLICATION_JSON)/*from w w w . jav a 2s. c om*/ public Response getAllSubscribers() { String jsonPayload; try { List<String> subscribers = SbHostObjectUtils.getAllSubscribers(); jsonPayload = new Gson().toJson(subscribers); } catch (Exception e) { log.error(e); return Response.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).build(); } return Response.status(HttpServletResponse.SC_OK).entity(jsonPayload).build(); }
From source file:com.esri.ArcGISController.java
@RequestMapping(value = "/rest/services/InfoUSA/MapServer", method = RequestMethod.GET) public void doMapServer(final HttpServletResponse response) throws IOException { response.setStatus(HttpServletResponse.SC_OK); response.setContentType("application/json"); response.setContentLength(m_byteArrayOutputStream.size()); m_byteArrayOutputStream.writeTo(response.getOutputStream()); response.getOutputStream().flush();//from w w w. jav a2 s . c o m }
From source file:com.fpmislata.banco.presentation.controladores.CuentaBancariaController.java
@RequestMapping(value = "/cuentabancaria", method = RequestMethod.GET, produces = "application/json") public void find(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { try {//from ww w.ja va 2 s . c o m List<CuentaBancaria> CuentasBancarias = cuentaBancariaService.findAll(); String jsonSalida = jsonTransformer.ObjectToJson(CuentasBancarias); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.setContentType("application/json; charset=UTF-8"); httpServletResponse.getWriter().println(jsonSalida); } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:net.jadler.JadlerMocker.java
/** * Package private constructor, for testing purposes only! Allows to define a StubbingFactory instance * as well./*w w w . j a v a 2 s .c o m*/ * @param server stub http server instance this mocker should use * @param stubbingFactory a factory to create stubbing instances */ JadlerMocker(final StubHttpServer server, final StubbingFactory stubbingFactory) { Validate.notNull(server, "server cannot be null"); this.server = server; this.stubbings = new ArrayList<Stubbing>(); this.defaultHeaders = new MultiValueMap(); this.defaultStatus = HttpServletResponse.SC_OK; this.defaultEncoding = Charset.forName("UTF-8"); Validate.notNull(stubbingFactory, "stubbingFactory cannot be null"); this.stubbingFactory = stubbingFactory; this.httpStubRules = new LinkedList<StubRule>(); this.recordedRequests = synchronizedList(new LinkedList<Request>()); //synchronized, more requests can arrive in parallel }
From source file:com.rsginer.spring.controllers.RestaurantesController.java
@RequestMapping(value = { "/random-restaurante" }, method = RequestMethod.GET, produces = "application/json") public void getRestauranteRandom(HttpServletRequest httpResquest, HttpServletResponse httpServletResponse) { try {// www . j ava 2s . c o m Restaurante restaurante = restaurantesDAO.getRandom(); String jsonSalida = jsonTransformer.toJson(restaurante); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.setContentType("application/json; charset=UTF-8"); httpServletResponse.getWriter().println(jsonSalida); } catch (BussinessException ex) { List<BussinessMessage> bussinessMessages = ex.getBussinessMessages(); String jsonSalida = jsonTransformer.toJson(bussinessMessages); httpServletResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST); httpServletResponse.setContentType("application/json; charset=UTF-8"); try { httpServletResponse.getWriter().println(jsonSalida); } catch (IOException ex1) { Logger.getLogger(RestaurantesController.class.getName()).log(Level.SEVERE, null, ex1); } } catch (Exception ex) { httpServletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); httpServletResponse.setContentType("text/plain; charset=UTF-8"); try { ex.printStackTrace(httpServletResponse.getWriter()); } catch (IOException ex1) { Logger.getLogger(RestaurantesController.class.getName()).log(Level.SEVERE, null, ex1); } } }
From source file:com.streamsets.pipeline.stage.destination.http.TestHttpClientTarget.java
@Before public void setUp() throws Exception { int port = getFreePort(); server = new Server(port); server.setHandler(new AbstractHandler() { @Override// ww w .ja va 2 s .co m public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { serverRequested = true; if (returnErrorResponse) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } compressionType = request.getHeader(HttpConstants.CONTENT_ENCODING_HEADER); InputStream is = request.getInputStream(); if (compressionType != null && compressionType.equals(HttpConstants.SNAPPY_COMPRESSION)) { is = new SnappyFramedInputStream(is, true); } else if (compressionType != null && compressionType.equals(HttpConstants.GZIP_COMPRESSION)) { is = new GZIPInputStream(is); } requestPayload = IOUtils.toString(is); requestContentType = request.getContentType(); response.setStatus(HttpServletResponse.SC_OK); baseRequest.setHandled(true); } }); server.start(); }
From source file:com.hortonworks.amstore.view.AmbariStoreServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setContentType("text/html"); response.setStatus(HttpServletResponse.SC_OK); // very important, used throughout writer = response.getWriter();/*from ww w. j a v a2 s . c o m*/ // Reload all settings in case they changed mainStoreApplication.reloadConfiguration(); bootstrapjs(response); writer.println("<h2>Ambari Store</h2>"); displayExceptions(latestExceptions); latestExceptions = new LinkedList<StoreException>(); try { // TODO: remove use of global variable endpointIssues if (endpointIssues) { displayChecks(request, response); // If we still have issues after the checks if (endpointIssues) return; } if (request.getParameter("app_id") != null) { displayApplicationDetails(request.getParameter("app_id"), response); return; } displayAllApplications(request, response); // displayInstalledServicesInformation(); } catch (NullPointerException e) { writer.println("NullPointerException caught.<br>"); writer.println(GenericException.prettyTrace(e)); } catch (Exception e) { writer.println("Catch All Exception: " + e.toString() + "<br/>"); writer.println(org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(e)); } }
From source file:com.nesscomputing.jmx.jolokia.JolokiaServlet.java
private void sendResponse(final HttpServletResponse resp, final String contentType, final String jsonTxt) throws IOException { resp.setCharacterEncoding("utf-8"); resp.addHeader("Access-Control-Allow-Origin", "*"); resp.setContentType(contentType);/* w w w . j ava 2s . co m*/ resp.setStatus(HttpServletResponse.SC_OK); final PrintWriter writer = resp.getWriter(); writer.write(jsonTxt); writer.flush(); }