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:ch.entwine.weblounge.test.util.TestSiteUtils.java
/** * Test for the correct response when etag header is set. * //www . ja v a 2s . co m * @param request * the http request * @param eTagValue * the expected etag value * @param logger * used to log test output * @param params * the request parameters * @throws Exception * if processing the request fails */ public static void testETagHeader(HttpUriRequest request, String eTagValue, Logger logger, String[][] params) throws Exception { DefaultHttpClient httpClient = new DefaultHttpClient(); try { request.removeHeaders("If-Modified-Since"); request.setHeader("If-None-Match", eTagValue); logger.info("Sending 'If-None-Match' request to {}", request.getURI()); HttpResponse response = TestUtils.request(httpClient, request, params); assertEquals(HttpServletResponse.SC_NOT_MODIFIED, response.getStatusLine().getStatusCode()); assertNull(response.getEntity()); } finally { httpClient.getConnectionManager().shutdown(); } httpClient = new DefaultHttpClient(); try { request.removeHeaders("If-Modified-Since"); request.setHeader("If-None-Match", "\"abcdefghijklmt\""); logger.info("Sending 'If-None-Match' request to {}", request.getURI()); HttpResponse response = TestUtils.request(httpClient, request, params); assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); assertNotNull(response.getEntity()); response.getEntity().consumeContent(); } finally { httpClient.getConnectionManager().shutdown(); } }
From source file:hr.diskobolos.controller.FinancialResourcesController.java
/** * REST service responsible for editing financial resources data * * @param financialResourcesDto//from www . j a va 2s .c o m * @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:com.fpmislata.banco.presentation.controladores.SucursalBancariaController.java
@RequestMapping(value = "/sucursalbancaria", method = RequestMethod.GET, produces = "application/json") public void find(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { try {/*from w w w . j a va 2s .com*/ List<SucursalBancaria> sucursalBancaria; if (httpServletRequest.getParameter("identidadbancaria") != null) { sucursalBancaria = sucursalBancariaService .getByEntidad(Integer.parseInt(httpServletRequest.getParameter("identidadbancaria"))); } else { sucursalBancaria = sucursalBancariaService.findAll(); } httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.setContentType("application/json; charset=UTF-8"); String jsonSalida = jsonTransformer.ObjectToJson(sucursalBancaria); httpServletResponse.getWriter().println(jsonSalida); } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:org.onlab.stc.MonitorWebSocketServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String uri = req.getRequestURI(); uri = uri.length() <= 1 ? "/index.html" : uri; InputStream resource = getClass().getResourceAsStream(uri); if (resource == null) { resp.setStatus(HttpServletResponse.SC_NOT_FOUND); } else {//from w w w . j av a2 s . c om byte[] entity = ByteStreams.toByteArray(resource); resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType(contentType(uri).toString()); resp.setContentLength(entity.length); resp.getOutputStream().write(entity); } }
From source file:org.alfresco.repo.lotus.server.QuickrServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException { if (request.getMethod().equals("GET") && (request.getPathInfo().endsWith("/services/LibraryService") || request.getPathInfo().endsWith("/services/ContentService"))) { response.setStatus(HttpServletResponse.SC_OK); return;//from ww w . ja va 2 s. co m } super.doGet(request, response); }
From source file:com.vmware.identity.HealthStatusController.java
/** * Handle GET request for the health status *///w ww. j a va 2 s.c om @RequestMapping(value = "/HealthStatus", method = RequestMethod.GET) public void getHealthStatus(HttpServletRequest request, HttpServletResponse response) throws ServletException { Validate.notNull(request, "HttpServletRequest should not be null."); Validate.notNull(response, "HttpServletResponse should not be null."); // we are going to be very simple in this request processing for now // and just report if we are "reachable" // we also do not worry about the sender's identity // (in reality CM will include the SAML token in the header, // and so generally it means they successfully obtained it through sso ...) logger.debug("Handling getHealthStatus HTTP request; method:{} url:{}", request.getMethod(), request.getRequestURL()); try { response.setHeader("Content-Type", "application/xml; charset=utf-8"); response.setStatus(HttpServletResponse.SC_OK); OutputStreamWriter osw = new OutputStreamWriter(response.getOutputStream(), UTF8); try { osw.write(healthStatusXml); } finally { osw.close(); } logger.debug("Handled getHealthStatus HTTP request; method:{} url:{}", request.getMethod(), request.getRequestURL()); } catch (Exception e) { logger.error("Failed to return Health Status with [%s]." + e.toString(), e); throw new ServletException(e); // let the exception bubble up and show in the response since this is not user-facing } }
From source file:org.jboss.as.test.clustering.single.web.SimpleWebTestCase.java
@Test @OperateOnDeployment("deployment-single") public void test(@ArquillianResource(SimpleServlet.class) URL baseURL) throws ClientProtocolException, IOException { DefaultHttpClient client = new DefaultHttpClient(); String url = baseURL.toString() + "simple"; try {/*from ww w . j a v a2 s. c o m*/ HttpResponse response = client.execute(new HttpGet(url)); Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(1, Integer.parseInt(response.getFirstHeader("value").getValue())); Assert.assertFalse(Boolean.valueOf(response.getFirstHeader("serialized").getValue())); response.getEntity().getContent().close(); response = client.execute(new HttpGet(url)); Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(2, Integer.parseInt(response.getFirstHeader("value").getValue())); // This won't be true unless we have somewhere to which to replicate or session persistence is configured (current default) Assert.assertFalse(Boolean.valueOf(response.getFirstHeader("serialized").getValue())); response.getEntity().getContent().close(); } finally { client.getConnectionManager().shutdown(); } }
From source file:com.kixeye.chassis.transport.swagger.SwaggerServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // figure out the real path String pathInfo = StringUtils.trimToEmpty(req.getPathInfo()); while (pathInfo.endsWith("/")) { pathInfo = StringUtils.removeEnd(pathInfo, "/"); }// www . ja v a 2 s . co m while (pathInfo.startsWith("/")) { pathInfo = StringUtils.removeStart(pathInfo, "/"); } if (StringUtils.isBlank(pathInfo)) { resp.sendRedirect(rootContextPath + "/" + WELCOME_PAGE); } else { // get the resource AbstractFileResolvingResource resource = (AbstractFileResolvingResource) resourceLoader .getResource(SWAGGER_DIRECTORY + "/" + pathInfo); // send it to the response if (resource.exists()) { StreamUtils.copy(resource.getInputStream(), resp.getOutputStream()); resp.setStatus(HttpServletResponse.SC_OK); resp.flushBuffer(); } else { resp.sendError(HttpServletResponse.SC_NOT_FOUND); } } }
From source file:com.coroptis.coidi.rp.services.impl.DiscoveryProcessorYadis.java
private DiscoveryResult doHead(String userSuppliedId) throws ClientProtocolException, IOException { logger.debug("trying HEAD at '" + userSuppliedId + "'"); HttpClient httpClient = httpService.getHttpClient(); HttpHead httpHead = new HttpHead(userSuppliedId); httpHead.setHeader("Accept", "application/xrds+xml"); HttpResponse response = httpClient.execute(httpHead); if (HttpServletResponse.SC_OK == response.getStatusLine().getStatusCode()) { Header header = response.getFirstHeader("X-XRDS-Location"); if (header == null) { return doGet(userSuppliedId); } else {// ww w. j ava 2s. c o m return discoverySupport.getXrdsDocument(header.getValue(), userSuppliedId); } } else { logger.info("OpendID provider response for YADIS HEAD request is:" + response.toString()); return null; } }
From source file:com.rockagen.gnext.service.spring.security.extension.ExAuthenticationHandler.java
/** * Authentication success handler/*from ww w .j a v a2 s. c o m*/ * * @param request request * @param response response * @param authentication {@link org.springframework.security.core.Authentication} */ public void successHandler(HttpServletRequest request, HttpServletResponse response, Authentication authentication) { String uid = authentication.getName(); successRegister(uid, request); // Response Token String token = exTokenAuthentication.newToken(uid); if (CommUtil.isNotBlank(token)) { response.setHeader(tokenName, token); response.setStatus(HttpServletResponse.SC_OK); } else { response.setStatus(HttpServletResponse.SC_FORBIDDEN); } }