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:controller.IndicadoresRestController.java
/** * * @param id// w w w. j a va 2 s. c om * @param request * @param response * @return JSON */ @RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/json") public String getByIdJSON(@PathVariable("id") String id, HttpServletRequest request, HttpServletResponse response) { IndicadoresDAO tabla = new IndicadoresDAO(); Gson JSON; Indicadores elemento; try { elemento = tabla.selectById(id); if (elemento == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); Error e = new Error(); e.setTypeAndDescription("Warning", "No existe el elemeto solicitado con id:" + id); JSON = new Gson(); return JSON.toJson(e); } } catch (HibernateException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); Error e = new Error(); e.setTypeAndDescription("errorServerError", ex.getMessage()); JSON = new Gson(); return JSON.toJson(e); } JSON = new Gson(); response.setStatus(HttpServletResponse.SC_OK); return JSON.toJson(elemento); }
From source file:org.jboss.as.test.clustering.cluster.web.shared.SharedSessionTestCase.java
@Test public void test(@ArquillianResource @OperateOnDeployment(DEPLOYMENT_1) URL baseURLDep1, @ArquillianResource @OperateOnDeployment(DEPLOYMENT_2) URL baseURLDep2) throws URISyntaxException, IOException { URI baseURI1 = new URI(baseURLDep1.toExternalForm() + "/"); URI baseURI2 = new URI(baseURLDep2.toExternalForm() + "/"); URI uri11 = SimpleServlet.createURI(baseURI1.resolve(MODULE_1 + "/")); URI uri12 = SimpleServlet.createURI(baseURI1.resolve(MODULE_2 + "/")); URI uri21 = SimpleServlet.createURI(baseURI2.resolve(MODULE_1 + "/")); URI uri22 = SimpleServlet.createURI(baseURI2.resolve(MODULE_2 + "/")); try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) { int expected = 1; try (CloseableHttpResponse response = client.execute(new HttpGet(uri11))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(expected++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); }/*from w w w .j a va2 s . co m*/ try (CloseableHttpResponse response = client.execute(new HttpGet(uri12))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(expected++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); } try (CloseableHttpResponse response = client.execute(new HttpGet(uri21))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(expected++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); } try (CloseableHttpResponse response = client.execute(new HttpGet(uri22))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(expected++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); } } }
From source file:org.infinispan.server.test.rest.security.RESTCertSecurityTest.java
@Test @InSequence(1)//from w w w .ja v a 2 s. c om public void testSecuredWriteOperations() throws Exception { try { controller.start(CONTAINER1); //correct alias for the certificate put(securedClient(testAlias), keyAddress(KEY_A), HttpServletResponse.SC_OK); //test wrong authorization, 1. wrong alias for the certificate put(securedClient(test2Alias), keyAddress(KEY_B), HttpServletResponse.SC_FORBIDDEN); //2. access over 8080 put(securedClient(testAlias), keyAddressUnsecured(KEY_B), HttpServletResponse.SC_UNAUTHORIZED); post(securedClient(testAlias), keyAddress(KEY_C), HttpServletResponse.SC_OK); post(securedClient(test2Alias), keyAddress(KEY_D), HttpServletResponse.SC_FORBIDDEN); //get is not secured, should be working over 8080 HttpResponse resp = get(securedClient(test2Alias), keyAddressUnsecured(KEY_A), HttpServletResponse.SC_OK); String content = new BufferedReader(new InputStreamReader(resp.getEntity().getContent())).readLine(); assertEquals("data", content); head(securedClient(test2Alias), keyAddressUnsecured(KEY_A), HttpServletResponse.SC_OK); delete(securedClient(test2Alias), keyAddress(KEY_A), HttpServletResponse.SC_FORBIDDEN); delete(securedClient(testAlias), keyAddress(KEY_A), HttpServletResponse.SC_OK); delete(securedClient(testAlias), keyAddress(KEY_C), HttpServletResponse.SC_OK); } finally { controller.stop(CONTAINER1); } }
From source file:controller.TemasNivel2RestController.java
/** * * @param id/* w w w .ja v a2s .com*/ * @param request * @param response * @return JSON */ @RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/json") public String getByIdJSON(@PathVariable("id") int id, HttpServletRequest request, HttpServletResponse response) { TemasNivel2DAO tabla = new TemasNivel2DAO(); Gson JSON; TemasNivel2 elemento; try { elemento = tabla.selectById(id); if (elemento == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); Error e = new Error(); e.setTypeAndDescription("Warning", "No existe el elemeto solicitado con id:" + id); JSON = new Gson(); return JSON.toJson(e); } } catch (HibernateException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); Error e = new Error(); e.setTypeAndDescription("errorServerError", ex.getMessage()); JSON = new Gson(); return JSON.toJson(e); } JSON = new Gson(); response.setStatus(HttpServletResponse.SC_OK); return JSON.toJson(elemento); }
From source file:controller.TemasNivel1RestController.java
/** * * @param id// w w w . jav a 2s . c o m * @param request * @param response * @return JSON */ @RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/json") public String getByIdJSON(@PathVariable("id") int id, HttpServletRequest request, HttpServletResponse response) { TemasNivel1DAO tabla = new TemasNivel1DAO(); Gson JSON; TemasNivel1 elemento; try { elemento = tabla.selectById(id); if (elemento == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); Error e = new Error(); e.setTypeAndDescription("Warning", "No existe el elemeto solicitado con id:" + id); JSON = new Gson(); return JSON.toJson(e); } } catch (HibernateException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); Error e = new Error(); e.setTypeAndDescription("errorServerError", ex.getMessage()); JSON = new Gson(); return JSON.toJson(e); } JSON = new Gson(); response.setStatus(HttpServletResponse.SC_OK); return JSON.toJson(elemento); }
From source file:ee.ria.xroad.common.request.DummyCentralServiceHandler.java
private static void sendErrorResponse(HttpServletResponse response, String faultCode, String faultString, String faultActor, String faultDetail) throws IOException { String soapMessageXml = SoapFault.createFaultXml(faultCode, faultString, faultActor, faultDetail); String encoding = StandardCharsets.UTF_8.name(); byte[] messageBytes = soapMessageXml.getBytes(encoding); response.setStatus(HttpServletResponse.SC_OK); response.setContentType(MimeTypes.TEXT_XML); response.setContentLength(messageBytes.length); response.setHeader("SOAPAction", ""); response.setCharacterEncoding(encoding); response.getOutputStream().write(messageBytes); }
From source file:controller.TemasNivel3RestController.java
/** * * @param id/* www . j av a 2 s . c o m*/ * @param request * @param response * @return JSON */ @RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/json") public String getByIdJSON(@PathVariable("id") int id, HttpServletRequest request, HttpServletResponse response) { TemasNivel3DAO tabla = new TemasNivel3DAO(); Gson JSON; TemasNivel3 elemento; try { elemento = tabla.selectById(id); if (elemento == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); Error e = new Error(); e.setTypeAndDescription("Warning", "No existe el elemeto solicitado con id:" + id); JSON = new Gson(); return JSON.toJson(e); } } catch (HibernateException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); Error e = new Error(); e.setTypeAndDescription("errorServerError", ex.getMessage()); JSON = new Gson(); return JSON.toJson(e); } JSON = new Gson(); response.setStatus(HttpServletResponse.SC_OK); return JSON.toJson(elemento); }
From source file:io.lavagna.web.security.login.DemoLoginTest.java
@Test public void testLogoutWithoutSession() throws IOException, ServletException { when(req.getSession()).thenReturn(session); Assert.assertTrue(dl.handleLogout(req, resp)); verify(resp).setStatus(HttpServletResponse.SC_OK); verify(session).invalidate();//from w ww . ja va2s . c om }
From source file:com.homesnap.webserver.LabelRestAPITest.java
@Test public void test9DeleteLabel() { // Test new label creation JSONObject label = deleteRequestJSONObject(urn_labels + "/ch6", HttpServletResponse.SC_OK); testLabelCh6Bis(label);// ww w. j av a 2s . c o m label = deleteRequestJSONObject(urn_labels + "/label?id=ch7", HttpServletResponse.SC_NOT_ACCEPTABLE); Assert.assertNull(label); }