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.jboss.as.test.clustering.cluster.web.ClusteredWebSimpleTestCase.java
@Test @OperateOnDeployment(DEPLOYMENT_1)/* w w w . j a va 2 s. co m*/ public void testSerialized(@ArquillianResource(SimpleServlet.class) URL baseURL) throws IOException { DefaultHttpClient client = HttpClientUtils.relaxedCookieHttpClient(); // returns the URL of the deployment (http://127.0.0.1:8180/distributable) String url = baseURL.toString(); log.info("URL = " + url); try { HttpResponse response = client.execute(new HttpGet(url + "simple")); 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 + "simple")); 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 Assert.assertTrue(Boolean.valueOf(response.getFirstHeader("serialized").getValue())); response.getEntity().getContent().close(); } finally { client.getConnectionManager().shutdown(); } }
From source file:org.jboss.additional.testsuite.jdkall.present.clustering.cluster.web.ExternalizerTestCase.java
private static void assertValue(HttpClient client, URI uri, int value) throws IOException { HttpResponse response = client.execute(new HttpGet(uri)); try {/*from w w w. jav a 2 s . c om*/ Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(value, Integer.parseInt(response.getFirstHeader(CounterServlet.COUNT_HEADER).getValue())); } finally { HttpClientUtils.closeQuietly(response); } }
From source file:org.jboss.as.test.clustering.cluster.web.context.InvalidateConversationTestCase.java
@Test public void testInvalidate( @ArquillianResource(ConversationServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource(ConversationServlet.class) @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2) throws IOException, URISyntaxException { String conversation = null;//from w w w. j a va2s. c o m establishTopology(baseURL1, NODES); try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) { HttpResponse response = client.execute(new HttpGet(ConversationServlet.createURI(baseURL1))); try { assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); assertTrue(response.containsHeader(ConversationServlet.COUNT_HEADER)); assertEquals(1, Integer.parseInt(response.getFirstHeader(ConversationServlet.COUNT_HEADER).getValue())); conversation = response.getFirstHeader(ConversationServlet.CONVERSATION_ID).getValue(); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute(new HttpGet(ConversationServlet.createURI(baseURL2, conversation))); try { assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); assertTrue(response.containsHeader(ConversationServlet.COUNT_HEADER)); assertEquals(2, Integer.parseInt(response.getFirstHeader(ConversationServlet.COUNT_HEADER).getValue())); assertEquals(conversation, response.getFirstHeader(ConversationServlet.CONVERSATION_ID).getValue()); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute(new HttpGet(LogoutServlet.createURI(baseURL1, conversation))); try { assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); assertTrue(response.containsHeader(ConversationServlet.COUNT_HEADER)); assertEquals(3, Integer.parseInt(response.getFirstHeader(ConversationServlet.COUNT_HEADER).getValue())); assertEquals(conversation, response.getFirstHeader(ConversationServlet.CONVERSATION_ID).getValue()); } finally { HttpClientUtils.closeQuietly(response); } } }
From source file:com.homesnap.webserver.GroupRestAPITest.java
@Test public void test6ModifyGroup() { // Test to get a specific group (TODO no add or remove by this methode... should be done unit by unit...) JSONObject group = putRequestJSONObject(urn_groups + "/1", createGroup1Bis(), HttpServletResponse.SC_OK); // Test group 1 testGroup1Bis(group);//from www.j av a 2s . c o m group = putRequestJSONObject(urn_groups + "/group?id=6", createGroup6Bis(), HttpServletResponse.SC_OK); // Test group 1 testGroup6Bis(group); }
From source file:eu.trentorise.smartcampus.permissionprovider.auth.fb.FBController.java
/** * This rest web service is the one that google called after login (callback * url). First it retrieve code and token that google sends back. It checks * if code and token are not null, then if token is the same that was saved * in session. If it is not response status is UNAUTHORIZED, otherwise it * retrieves user data. If user is not already saved in db, then user is * added in db, iff email is not already used, otherwise it sends an * UNAUTHORIZED status and redirect user to home page without authenticating * him/her. If it is all ok, then it authenticates user in spring security * and create cookie user. Then redirects authenticated user to home page * where user can access protected resources. * //from w ww .j av a 2s. co m * @param request * : instance of {@link HttpServletRequest} * @param response * : instance of {@link HttpServletResponse} * @return redirect to home page */ @RequestMapping(value = "/callback", method = RequestMethod.GET) public String confirmStateToken(HttpServletRequest request, HttpServletResponse response) { String code = request.getParameter("code"); // compare state token in session and state token in response of google // if equals return to home // if not error page if (code == null) { logger.error("Error in google authentication flow"); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); return ""; } else { try { FBUser userInfo = auth.getUserInfoJson(code); response.setStatus(HttpServletResponse.SC_OK); request.getSession().setAttribute(FBAuthHelper.SESSION_FB_CHECK, "true"); return String.format("redirect:/eauth/facebook?target=%s&id=%s&email=%s&first_name=%s&last_name=%s", URLEncoder.encode((String) request.getSession().getAttribute("redirect"), "UTF8"), userInfo.getId(), userInfo.getEmail(), userInfo.getFirst_name(), userInfo.getLast_name()); } catch (IOException e) { logger.error("IOException .. Problem in reading user data.", e); response.setStatus(HttpServletResponse.SC_NOT_FOUND); } } return "redirect:/"; }
From source file:ch.admin.suis.msghandler.servlet.TriggerServlet.java
/** * Processes the incoming requests.//from w ww . j a v a2 s. co m * * @param request An HTTP Request. * @param response The Response * @throws ServletException Something went wront in the servlet ! * @throws IOException Classical IO problems. */ private void doProcess(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setStatus(HttpServletResponse.SC_OK); response.setContentType(TEXT); final String action = request.getParameter("action"); try { if (StringUtils.equalsIgnoreCase(action, "send")) { dispatchSendRequest(request, response); } else if (StringUtils.equalsIgnoreCase(action, "receive")) { handleReceive(response); } else if (StringUtils.equalsIgnoreCase(action, "poll")) { handlePoll(response); } else { String msg = "No valid parameter found. Valid parameter: action={send,receive,poll}"; LOG.warn(msg); response.getWriter().println(msg); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } } catch (SchedulerException ex) { String msg = "cannot trigger an immediate job"; LOG.fatal(msg, ex); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); throw new ServletException(msg, ex); } }
From source file:org.keycloak.secretstore.boundary.QRCodeServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String tokenIdAsString = req.getParameter("tokenId"); String sizeAsString = req.getParameter("size"); Principal principal = req.getUserPrincipal(); int size = 250; if (null != sizeAsString && !sizeAsString.isEmpty()) { try {/*from ww w . j a v a 2s .c o m*/ size = Integer.parseInt(req.getParameter("size")); } catch (Throwable t) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Size is invalid."); return; } } if (null == tokenIdAsString || tokenIdAsString.isEmpty()) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Token key is missing."); return; } UUID tokenId; try { tokenId = UUID.fromString(tokenIdAsString); } catch (Throwable t) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Token key is invalid."); return; } Token token = tokenService.getByIdForDistribution(tokenId); if (null == token) { resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Token could not be found."); return; } if (!principal.getName().equals(token.getPrincipal())) { resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Token could not be found for principal."); return; } String response = token.getId().toString() + "," + token.getSecret(); if (null != token.getExpiresAt()) { response += "," + token.getExpiresAt().toString(); } BitMatrix bitMatrix; try { QRCodeWriter writer = new QRCodeWriter(); bitMatrix = writer.encode(response, BarcodeFormat.QR_CODE, size, size); } catch (WriterException e) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error while generating the QR Code."); return; } ByteArrayOutputStream pngOut = new ByteArrayOutputStream(); MatrixToImageWriter.writeToStream(bitMatrix, "PNG", pngOut); byte[] pngData = pngOut.toByteArray(); resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType("image/png"); resp.getOutputStream().write(pngData); }
From source file:it.smartcommunitylab.aac.auth.fb.FBController.java
/** * This rest web service is the one that google called after login (callback * url). First it retrieve code and token that google sends back. It checks * if code and token are not null, then if token is the same that was saved * in session. If it is not response status is UNAUTHORIZED, otherwise it * retrieves user data. If user is not already saved in db, then user is * added in db, iff email is not already used, otherwise it sends an * UNAUTHORIZED status and redirect user to home page without authenticating * him/her. If it is all ok, then it authenticates user in spring security * and create cookie user. Then redirects authenticated user to home page * where user can access protected resources. * // w ww .j a v a 2 s .c om * @param request * : instance of {@link HttpServletRequest} * @param response * : instance of {@link HttpServletResponse} * @return redirect to home page */ @RequestMapping(value = "/callback", method = RequestMethod.GET) public String confirmStateToken(HttpServletRequest request, HttpServletResponse response) { String code = request.getParameter("code"); // compare state token in session and state token in response of google // if equals return to home // if not error page if (code == null) { logger.error("Error in google authentication flow"); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); return ""; } else { try { FBUser userInfo = auth.getUserInfoJson(code); response.setStatus(HttpServletResponse.SC_OK); request.getSession().setAttribute(FBAuthHelper.SESSION_FB_CHECK, "true"); String res = String.format( "redirect:/eauth/facebook?" + "target=%s" + "&id=%s" + "&first_name=%s" + "&last_name=%s", URLEncoder.encode((String) request.getSession().getAttribute("redirect"), "UTF8"), userInfo.getId(), userInfo.getFirst_name(), userInfo.getLast_name()); if (StringUtils.hasText(userInfo.getEmail())) { res += "&email=" + userInfo.getEmail(); } return res; } catch (IOException e) { logger.error("IOException .. Problem in reading user data.", e); response.setStatus(HttpServletResponse.SC_NOT_FOUND); } } return "redirect:/"; }
From source file:costumetrade.user.login.BasicAuthenticateInterceptor.java
private void handleFailure(HttpServletResponse response, ApiResponse apiResponse) throws IOException { response.setStatus(HttpServletResponse.SC_OK); response.setContentType(MediaType.APPLICATION_JSON_VALUE); response.setCharacterEncoding(StandardCharsets.UTF_8.name()); PrintWriter out = response.getWriter(); out.println(JSON.toJSONString(apiResponse)); out.flush();//from w ww .j a v a 2 s . c o m }
From source file:org.jboss.as.test.clustering.cluster.web.ClusteredWebTestCase.java
@Test @OperateOnDeployment("deployment-0") public void testSerialized(@ArquillianResource(SimpleServlet.class) URL baseURL) throws ClientProtocolException, IOException { DefaultHttpClient client = new DefaultHttpClient(); // returns the URL of the deployment (http://127.0.0.1:8180/distributable) String url = baseURL.toString(); System.out.println("URL = " + url); try {//from www . j a va 2s . c om HttpResponse response = client.execute(new HttpGet(url + "simple")); 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 + "simple")); 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 Assert.assertTrue(Boolean.valueOf(response.getFirstHeader("serialized").getValue())); response.getEntity().getContent().close(); } finally { client.getConnectionManager().shutdown(); } }