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.jamespot.glifpix.wrappers.SampleHtmlTestService.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); response.setStatus(HttpServletResponse.SC_OK); PrintWriter out = response.getWriter(); SampleTagsServiceHandler tsh = new SampleTagsServiceHandler(); out.println("<h1>HtmlTestService</h1>"); out.println("<table>"); String[] tags = tsh.getTags(request.getParameter("text"), request.getParameter("lng"), Integer.parseInt(request.getParameter("nbTags"))); if (tags != null && tags.length > 0) { for (int i = 0; i < tags.length; i++) { out.println("<tr><td>" + tags[i] + "</td></tr>"); }/*from w w w . j a v a2 s. c o m*/ } out.println("</table>"); out.println("<p><a href='/html/form'>Back</a></p>"); }
From source file:org.auraframework.integration.test.validation.AuraValidationServletHttpTest.java
@Test public void testServlet() throws Exception { String path = AuraFiles.Core.getPath() + "/aura-components/src/test/components/validationTest/basic"; assertTrue(path, new File(path).exists()); method = obtainGetMethod("/qa/auraValidation?path=" + path); HttpResponse response = perform(method); assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); assertDefaultAntiClickjacking(response, true, false); String contentType = response.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue(); assertTrue(contentType, contentType.contains(JsonEncoder.MIME_TYPE)); assertTrue(contentType, contentType.contains(Charsets.UTF_8.toString())); String content = getResponseBody(response); List<String> errors = ValidationError.parseErrors(content); ValidationTestUtil.verifyValidationTestBasicErrors(errors); }
From source file:de.hska.ld.core.config.security.AjaxAuthenticationSuccessHandler.java
@Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { String userJson = null;/*from w w w. j a v a 2s .c o m*/ try { userJson = mapper.writeValueAsString(authentication.getPrincipal()); } catch (JsonProcessingException e) { LOGGER.error(e.getMessage()); } if (userJson != null) { response.setCharacterEncoding("UTF-8"); response.getWriter().write(userJson); response.setStatus(HttpServletResponse.SC_OK); } else { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
From source file:arena.web.view.DownloadView.java
@Override @SuppressWarnings("unchecked") protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setStatus(HttpServletResponse.SC_OK); String mt = (mimeTypeParam != null ? (String) model.get(mimeTypeParam) : this.mimeType); if (mt != null) { response.setContentType(this.mimeType); }/*from w ww . jav a 2 s. c om*/ Object contentObj = model.get(this.contentParam); String fileName = ServletUtils.replaceWildcards(this.filenamePattern, this.allowRequestArgs, model, request); if (!fileName.equals("")) { String rfc2047Name = javax.mail.internet.MimeUtility.encodeText(fileName, "UTF-8", null); String fullHeader = "attachment;filename=" + rfc2047Name; response.setHeader("Content-Disposition", fullHeader); } ServletOutputStream out = response.getOutputStream(); if (contentObj instanceof byte[]) { byte[] content = (byte[]) model.get(this.contentParam); response.setContentLength(content == null ? 0 : content.length); if (content != null && content.length > 0) { out.write(content); } } else if (contentObj instanceof InputStream) { InputStream content = (InputStream) contentObj; byte[] buffer = new byte[response.getBufferSize()]; int read = 0; while ((read = content.read(buffer)) >= 0) { out.write(buffer, 0, read); } if (this.closeStream) { content.close(); } } }
From source file:com.adanac.module.blog.api.HttpApiHelper.java
public static void baiduPush(int remain) { String pushUrl = DaoFactory.getDao(HtmlPageDao.class).findPushUrl(); if (pushUrl == null) { if (logger.isInfoEnabled()) { logger.info("all html page has been pushed!"); }/* ww w . j av a 2 s . c o m*/ return; } if (remain <= 0) { if (logger.isInfoEnabled()) { logger.info("there has no remain[" + remain + "]!"); } return; } if (logger.isInfoEnabled()) { logger.info("find push url : " + pushUrl); } String url = "http://data.zz.baidu.com/urls?site=" + site + "&token=" + token; try { HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); connection.setDoInput(true); connection.setDoOutput(true); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "text/plain"); OutputStream outputStream = connection.getOutputStream(); outputStream.write(pushUrl.getBytes("UTF-8")); outputStream.write("\r\n".getBytes("UTF-8")); outputStream.flush(); int status = connection.getResponseCode(); if (logger.isInfoEnabled()) { logger.info("baidu-push response code : " + status); } if (status == HttpServletResponse.SC_OK) { String response = IOUtil.read(connection.getInputStream()); if (logger.isInfoEnabled()) { logger.info("baidu-push response : " + response); } JSONObject result = JSONObject.fromObject(response); if (result.getInt("success") >= 1) { DaoFactory.getDao(HtmlPageDao.class).updateIsPush(pushUrl); } else { logger.warn("push url failed : " + pushUrl); } baiduPush(result.getInt("remain")); } else { logger.error("baidu-push error : " + IOUtil.read(connection.getErrorStream())); } } catch (Exception e) { logger.error("baidu push failed ...", e); } }
From source file:org.codemucker.testserver.capturing.CapturingTestServerTest.java
@Test public void test_captures_all_request_info() throws Exception { server.addServlet("/my/path/*", new TestServlet() { @Override/* w ww . ja v a2 s . c om*/ protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { resp.setStatus(HttpServletResponse.SC_OK); resp.getWriter().write("my_servlet"); resp.getWriter().flush(); } }); server.start(); final String url = "http://" + server.getHost() + ":" + server.getHttpPort() + "/my/path/extra/path/info?foo=bar&alice=bob"; // check we can hit the servlet, that it's run only once, and that we // get the params passed to it final HttpClient client = new DefaultHttpClient(); final HttpGet get = new HttpGet(url); get.setHeader("Content-Type", "text/html; charset=utf-8"); final HttpResponse resp = client.execute(get); assertEquals(HttpServletResponse.SC_OK, resp.getStatusLine().getStatusCode()); // check body assertEquals("my_servlet", IOUtils.toString(resp.getEntity().getContent())); // check we got the captures ok. final CapturedRequest expect = new CapturedRequest(); expect.scheme = "http"; expect.host = server.getHost(); expect.port = server.getHttpPort(); expect.contextPath = ""; expect.pathInfo = "/extra/path/info"; expect.servletPath = "/my/path"; expect.method = "GET"; expect.characterEncoding = "UTF-8"; expect.setParamValues("foo", "bar"); expect.setParamValues("alice", "bob"); Expect.that(server.getAllRequests()).is(AList.withOnly(ACapturedRequest.equalTo(expect))); Expect.that(server.getRequestsByServletPath("/my/path/*")) .is(AList.withOnly(ACapturedRequest.equalTo(expect))); }
From source file:com.datatorrent.lib.io.HttpOutputOperatorTest.java
@Test public void testHttpOutputNode() throws Exception { final List<String> receivedMessages = new ArrayList<String>(); Handler handler = new AbstractHandler() { @Override/*from w w w . jav a 2s .c o 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"; System.out.println("url: " + url); HttpOutputOperator<Object> node = new HttpOutputOperator<Object>(); node.setResourceURL(new URI(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()); System.out.println(receivedMessages.get(0)); 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:gsn.http.ContainerInfoHandler.java
public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setStatus(HttpServletResponse.SC_OK); String reqName = request.getParameter("name"); //Added by Behnaz HttpSession session = request.getSession(); User user = (User) session.getAttribute("user"); response.setHeader("Cache-Control", "no-store"); response.setDateHeader("Expires", 0); response.setHeader("Pragma", "no-cache"); String omitLatestValuesPar = request.getParameter("omit_latest_values"); boolean omitLatestValues = false; if (omitLatestValuesPar != null && "true".equals(omitLatestValuesPar)) { omitLatestValues = true;/*from w w w.j av a 2 s . c om*/ } //System.out.println( "The handle was called" ); // if (reqName != null) System.out.println("requst " + reqName); // if (user != null) System.out.println("User " + user.getUserName()); response.getWriter().write(buildOutput(reqName, user, omitLatestValues)); }