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.jaspersoft.jasperserver.rest.services.RESTUser.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServiceException { String searchCriteria = getUserSearchInformation(req.getPathInfo()); WSUser[] users = null;/*from w w w. j a va 2 s . com*/ WSUserSearchCriteria wsUserSearchCriteria = restUtils.getWSUserSearchCriteria(searchCriteria); try { // get the resources.... users = userAndRoleManagementService.findUsers(wsUserSearchCriteria); } catch (AxisFault axisFault) { throw new ServiceException(HttpServletResponse.SC_NOT_FOUND, "could not locate users in uri: " + wsUserSearchCriteria.getName() + axisFault.getLocalizedMessage()); } if (log.isDebugEnabled()) { log.debug("" + users.length + " users were found"); } String marshal = generateSummeryReport(users); if (log.isDebugEnabled()) { log.debug("Marshaling OK"); } restUtils.setStatusAndBody(HttpServletResponse.SC_OK, resp, marshal); }
From source file:com.google.api.server.spi.EndpointsServletTest.java
@Test public void methodOverride() throws IOException { req.setRequestURI("/_ah/api/test/v2/increment"); req.setMethod("POST"); req.addHeader("X-HTTP-Method-Override", "PATCH"); req.setParameter("x", "1"); servlet.service(req, resp);//w ww. j a v a 2s . c om assertThat(resp.getStatus()).isEqualTo(HttpServletResponse.SC_OK); ObjectMapper mapper = ObjectMapperUtil.createStandardObjectMapper(); ObjectNode actual = mapper.readValue(resp.getContentAsString(), ObjectNode.class); assertThat(actual.size()).isEqualTo(1); assertThat(actual.get("x").asInt()).isEqualTo(2); }
From source file:io.wcm.caconfig.editor.impl.ConfigNamesServletTest.java
@Test void testResponse() throws Exception { ConfigNamesServlet underTest = context.registerInjectActivateService(new ConfigNamesServlet()); underTest.doGet(context.request(), context.response()); assertEquals(HttpServletResponse.SC_OK, context.response().getStatus()); String expectedJson = "{contextPath:'/context/path',configNames:[" + "{configName:'name2',label:'A-label2',collection=true,exists:true,allowAdd:true}," + "{configName:'name1',label:'B-label1',description:'desc1',collection:false,exists:true,allowAdd:true}," + "{configName:'name3',label:'C-label3',collection:false,exists:false,allowAdd:true}" + "]}"; JSONAssert.assertEquals(expectedJson, context.response().getOutputAsString(), true); }
From source file:org.openmrs.module.clinicalsummary.web.controller.service.ResponseController.java
@RequestMapping(method = RequestMethod.POST) public void processResponse(@RequestParam(required = false, value = USERNAME) String username, @RequestParam(required = false, value = PASSWORD) String password, HttpServletRequest request, HttpServletResponse response) throws IOException { log.info("Processing responses from the android devices ..."); try {/*from w w w. j a v a2 s . c o m*/ if (!Context.isAuthenticated()) Context.authenticate(username, password); UtilService utilService = Context.getService(UtilService.class); // TODO: wanna puke with this code!!!!! super hacky!!!!!!! Map parameterMap = request.getParameterMap(); for (Object parameterName : parameterMap.keySet()) { // skip the username and password request parameter if (!StringUtils.equalsIgnoreCase(USERNAME, String.valueOf(parameterName)) && !StringUtils.equalsIgnoreCase(PASSWORD, String.valueOf(parameterName))) { String id = String.valueOf(parameterName); String[] parameterValues = (String[]) parameterMap.get(id); log.info("ID: " + id); for (String parameterValue : parameterValues) log.info("Parameter Values: " + String.valueOf(parameterValue)); Patient patient = Context.getPatientService().getPatient(NumberUtils.toInt(id)); if (patient != null) processResponse(utilService, parameterValues, patient); else processDeviceLogs(utilService, id, parameterValues); } } response.setStatus(HttpServletResponse.SC_OK); } catch (ContextAuthenticationException e) { log.error("Authentication failure!", e); response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } catch (Exception e) { log.error("Unspecified exception happened when processing the request!", e); response.sendError(HttpServletResponse.SC_BAD_REQUEST); } }
From source file:com.proofpoint.http.server.TestHttpServerProvider.java
@Test public void testHttp() throws Exception { createServer();/* w ww . jav a 2 s . c om*/ server.start(); HttpClient client = new ApacheHttpClient(); StatusResponse response = client.execute(prepareGet().setUri(httpServerInfo.getHttpUri()).build(), createStatusResponseHandler()); assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK); }
From source file:com.eureka.v1_0.account.information.api.AccountInformationController.java
@ResponseBody @RequestMapping(method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE, produces = MediaType.TEXT_XML_VALUE, value = "/resettoken") public CreateResetPasswordTokenResponse createResetPasswordToken( @RequestBody CreateResetPasswordTokenRequest createResetPasswordTokenRequest, HttpServletRequest request, HttpServletResponse response) { if (createResetPasswordTokenRequest != null) { try {/*from w w w . j a v a2s . co m*/ witLoggerService.debug(JaxbHandler.toXml(createResetPasswordTokenRequest)); CreateResetPasswordTokenResponse createResetPasswordTokenResponse = this.accountInformationApiService .createResetPasswordToken(createResetPasswordTokenRequest); if (createResetPasswordTokenResponse != null) { witLoggerService.debug(JaxbHandler.toXml(createResetPasswordTokenResponse)); response.setStatus(HttpServletResponse.SC_OK); return createResetPasswordTokenResponse; } else { response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED); } } catch (Exception ex) { witLoggerService.warn(ex); ex.printStackTrace(); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } } response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return null; }
From source file:org.everit.authentication.http.session.ecm.tests.SessionAuthenticationComponentTest.java
private long hello(final HttpContext httpContext, final long expectedResourceId) throws IOException { HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(helloUrl); HttpResponse httpResponse = httpClient.execute(httpGet, httpContext); Assert.assertEquals(HttpServletResponse.SC_OK, httpResponse.getStatusLine().getStatusCode()); HttpEntity responseEntity = httpResponse.getEntity(); InputStream inputStream = responseEntity.getContent(); StringWriter writer = new StringWriter(); IOUtils.copy(inputStream, writer);/*from w w w . java 2 s.c o m*/ String[] responseBodyAsString = writer.toString().split(":"); long actualResourceId = Long.parseLong(responseBodyAsString[0]); long newResourceId = Long.parseLong(responseBodyAsString[1]); String st = responseBodyAsString.length == RESPONSE_BODY_LENGTH ? responseBodyAsString[2] : "should be success"; Assert.assertEquals(st.replaceAll("-->", ":"), expectedResourceId, actualResourceId); return newResourceId; }
From source file:org.obm.healthcheck.server.HealthCheckServletDefaultHandlersTest.java
@Test public void testGetJavaEncoding() throws Exception { HttpResponse response = get("/java/encoding"); assertThat(response.getStatusLine().getStatusCode()).isEqualTo(HttpServletResponse.SC_OK); assertThat(IO.toString(response.getEntity().getContent())).isEqualTo(System.getProperty("file.encoding")); }
From source file:org.codemucker.testserver.capturing.CapturingTestServerTest.java
/** * Ensure that our servlets are wrapped and that requests going in are correctly captured, and * that we can retrieve them afterwards, and that asserts are good * * @throws Exception//from w w w . j ava2 s . co m */ @Test public void test_request_captures_and_retrieval() throws Exception { server.addServlet("/my/first/path", new TestServlet() { @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { resp.setStatus(HttpServletResponse.SC_OK); resp.getWriter().write("first_servlet"); resp.getWriter().flush(); } }); server.addServlet("/my/second/path", new TestServlet() { @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { resp.setStatus(HttpServletResponse.SC_OK); resp.getWriter().write("second_servlet"); resp.getWriter().flush(); } }); server.start(); final String url1 = "http://" + server.getHost() + ":" + server.getHttpPort() + "/my/first/path"; final String url2 = "http://" + server.getHost() + ":" + server.getHttpPort() + "/my/second/path"; //check we can hit the servlet, that it's run only once, and that we // get the params passed to it //make the requests final HttpClient client = new DefaultHttpClient(); // first path { final HttpGet get = new HttpGet(url1); final HttpResponse resp = client.execute(get); assertEquals(HttpServletResponse.SC_OK, resp.getStatusLine().getStatusCode()); // check body assertEquals("first_servlet", IOUtils.toString(resp.getEntity().getContent())); } // second path { final HttpGet get = new HttpGet(url2); final HttpResponse resp = client.execute(get); assertEquals(HttpServletResponse.SC_OK, resp.getStatusLine().getStatusCode()); // check body assertEquals("second_servlet", IOUtils.toString(resp.getEntity().getContent())); } // check we got the captures ok. final CapturedRequest req1 = new CapturedRequest(); req1.scheme = "http"; req1.host = server.getHost(); req1.port = server.getHttpPort(); req1.contextPath = ""; req1.pathInfo = null; req1.servletPath = "/my/first/path"; req1.method = "GET"; req1.characterEncoding = null; final CapturedRequest req2 = new CapturedRequest(); req2.scheme = "http"; req2.host = server.getHost(); req2.port = server.getHttpPort(); req2.contextPath = ""; req2.pathInfo = null; req2.servletPath = "/my/second/path"; req2.method = "GET"; req2.characterEncoding = null; //check the server retrieval methods work Expect.that(server.getAllRequests()).is( AList.inAnyOrder().withOnly(ACapturedRequest.equalTo(req1)).and(ACapturedRequest.equalTo(req2))); Expect.that(server.getRequestsByServletPath("/my/first/path")) .is(AList.withOnly(ACapturedRequest.equalTo(req1))); Expect.that(server.getRequestsByServletPath("/my/second/path")) .is(AList.withOnly(ACapturedRequest.equalTo(req2))); }