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.thinkberg.moxo.dav.DeleteHandler.java
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { FileObject object = getResourceManager().getFileObject(request.getPathInfo()); if (request instanceof Request) { String fragment = ((Request) request).getUri().getFragment(); if (fragment != null) { response.sendError(HttpServletResponse.SC_FORBIDDEN); return; }//from w w w . jav a 2 s . co m } try { LockManager.getInstance().checkCondition(object, getIf(request)); } catch (LockException e) { if (e.getLocks() != null) { response.sendError(SC_LOCKED); } else { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); } return; } if (object.exists()) { if (object.delete(ALL_FILES_SELECTOR) > 0) { response.setStatus(HttpServletResponse.SC_OK); } else { response.sendError(HttpServletResponse.SC_FORBIDDEN); } } else { response.sendError(HttpServletResponse.SC_NOT_FOUND); } }
From source file:net.oauth.client.httpclient4.OAuthSchemeTest.java
private void get(String URL) throws IOException { HttpResponse response = client.execute(new HttpGet(URL), context); assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); release(response);//w w w. ja v a 2s . c o m }
From source file:org.wso2.identity.integration.test.entitlement.EntitlementSecurityTestCase.java
@Test(alwaysRun = true, description = "Test reflected XSS in XACML policy editor") public void testXSS() throws IOException { HttpGet request = new HttpGet(url); HttpResponse response = httpClient.execute(request); // If HTTP status code is 200... if (response.getStatusLine().getStatusCode() == HttpServletResponse.SC_OK) { BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line;/*from w w w . jav a 2 s . co m*/ boolean success = false; while ((line = rd.readLine()) != null) { success = line.equals(StringEscapeUtils.escapeHtml(value)); if (success) { break; } } rd.close(); if (!success) { Assert.fail("Content is not encoded"); } } // If HTTP status code is 405... else if (response.getStatusLine().getStatusCode() == HttpServletResponse.SC_METHOD_NOT_ALLOWED) { log.info("GET request to XACML policy editor is blocked as expected"); } // If HTTP status code is neither 200 nor 405... else { log.info("Unknown response"); } }
From source file:fr.epsi.controllers.rest.LoginController.java
/** * Methode qui deconnecte un utilisateur * @param guid le guid de l'utilisateur connecte *//*from w ww. j av a2s . c om*/ @RequestMapping(value = "/disconnect", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody void disconnect(@RequestParam("token") String token, HttpServletResponse resp) { try { // On recupre l'instance et on la supprime Users userModel = Users.getInstance(); User user = userModel.findByGUID(token); if (user != null) { user.clearGUID(); resp.setStatus(HttpServletResponse.SC_OK); } else { resp.setStatus(HttpServletResponse.SC_FORBIDDEN); } } catch (Exception e) { resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
From source file:eu.stratosphere.nephele.jobmanager.web.LogfileInfoServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try {//from w ww . ja v a 2s .c o m if ("stdout".equals(req.getParameter("get"))) { // Find current stdtout file for (File f : logDir.listFiles()) { // contains "jobmanager" ".log" and no number in the end ->needs improvement if (f.getName().equals("jobmanager-stdout.log") || (f.getName().indexOf("jobmanager") != -1 && f.getName().indexOf(".out") != -1 && !Character.isDigit(f.getName().charAt(f.getName().length() - 1)))) { resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType("text/plain "); writeFile(resp.getOutputStream(), f); break; } } } else { // Find current logfile for (File f : logDir.listFiles()) { // contains "jobmanager" ".log" and no number in the end ->needs improvement if (f.getName().equals("jobmanager-stderr.log") || (f.getName().indexOf("jobmanager") != -1 && f.getName().indexOf(".log") != -1 && !Character.isDigit(f.getName().charAt(f.getName().length() - 1)))) { resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType("text/plain "); writeFile(resp.getOutputStream(), f); break; } } } } catch (Throwable t) { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); resp.getWriter().print(t.getMessage()); if (LOG.isWarnEnabled()) { LOG.warn(StringUtils.stringifyException(t)); } } }
From source file:de.steilerdev.myVerein.server.security.rest.RestAuthenticationSuccessHandler.java
@Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException { User currentUser = (User) authentication.getPrincipal(); logger.info("[{}] Successfully authenticated user from IP {}", currentUser, SecurityHelper.getClientIpAddr(request)); clearAuthenticationAttributes(request); if (!response.isCommitted()) { Settings settings = Settings.loadSettings(settingsRepository); response.setHeader("System-ID", settings.getId()); response.setHeader("System-Version", settings.getSystemVersion()); response.setHeader("User-ID", currentUser.getId()); response.sendError(HttpServletResponse.SC_OK, "Successfully logged in"); }//w w w . ja v a 2 s. com }
From source file:com.datatorrent.lib.io.HttpPostOutputOperatorTest.java
@Test public void testHttpOutputNode() throws Exception { final List<String> receivedMessages = new ArrayList<String>(); Handler handler = new AbstractHandler() { @Override/*www. j a va2 s .co m*/ @Consumes({ MediaType.APPLICATION_JSON }) public void handle(String string, Request rq, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); IOUtils.copy(request.getInputStream(), bos); receivedMessages.add(new String(bos.toByteArray())); response.setContentType("text/html"); response.setStatus(HttpServletResponse.SC_OK); response.getWriter().println("<h1>Thanks</h1>"); ((Request) request).setHandled(true); receivedMessage = true; } }; Server server = new Server(0); server.setHandler(handler); server.start(); String url = "http://localhost:" + server.getConnectors()[0].getLocalPort() + "/somecontext"; HttpPostOutputOperator<Object> node = new HttpPostOutputOperator<Object>(); node.setUrl(url); node.setup(null); Map<String, String> data = new HashMap<String, String>(); data.put("somekey", "somevalue"); node.input.process(data); // Wait till the message is received or a maximum timeout elapses int timeoutMillis = 10000; while (!receivedMessage && timeoutMillis > 0) { timeoutMillis -= 20; Thread.sleep(20); } Assert.assertEquals("number requests", 1, receivedMessages.size()); JSONObject json = new JSONObject(data); Assert.assertTrue("request body " + receivedMessages.get(0), receivedMessages.get(0).contains(json.toString())); receivedMessages.clear(); String stringData = "stringData"; node.input.process(stringData); Assert.assertEquals("number requests", 1, receivedMessages.size()); Assert.assertEquals("request body " + receivedMessages.get(0), stringData, receivedMessages.get(0)); node.teardown(); server.stop(); }
From source file:com.ns.cm.ProvisionServlet.java
@Override protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { InputStream is = request.getInputStream(); byte[] bytes = readAll(is); String sJson = new String(bytes, "utf-8"); // json is utf-8 PrintWriter out = response.getWriter(); String a = "Reached doPut <BR> Data submitted: <BR>"; out.println(a);/*from ww w. ja v a 2s . com*/ out.println(sJson); response.setContentType("text/html"); response.setStatus(HttpServletResponse.SC_OK); }
From source file:org.craftercms.security.authentication.impl.RestLoginSuccessHandlerTest.java
@Test public void testHandle() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/login.json"); MockHttpServletResponse response = new MockHttpServletResponse(); RequestContext context = new RequestContext(request, response); String ticket = UUID.randomUUID().toString(); ObjectId profileId = new ObjectId(); Profile profile = new Profile(); profile.setId(profileId);//from w w w .j ava 2 s . c om profile.setUsername("jdoe"); profile.setPassword("1234"); profile.setEmail("jdoe@craftercms.org"); Authentication auth = new DefaultAuthentication(ticket.toString(), profile); handler.handle(context, auth); assertEquals(HttpServletResponse.SC_OK, response.getStatus()); assertEquals( "{\"ticket\":\"" + ticket + "\",\"profile\":{\"username\":\"jdoe\"," + "\"password\":\"1234\",\"email\":\"jdoe@craftercms.org\",\"verified\":false," + "\"enabled\":false,\"createdOn\":null,\"lastModified\":null,\"tenant\":null,\"roles\":[]," + "\"attributes\":{},\"id\":\"" + profileId.toString() + "\"},\"remembered\":false}", response.getContentAsString()); }