List of usage examples for org.apache.http.entity ContentType TEXT_HTML
ContentType TEXT_HTML
To view the source code for org.apache.http.entity ContentType TEXT_HTML.
Click Source Link
From source file:org.apache.hadoop.gateway.rm.dispatch.RMHaDispatchTest.java
private StringEntity getResponseEntity() { String body = "This is standby RM"; return new StringEntity(body, ContentType.TEXT_HTML); }
From source file:at.deder.ybr.test.server.SimpleHttpServerTest.java
/** * check access to files of a package with more than one file * * @throws ProtocolViolationException//from ww w .ja va 2s . co m * @throws IOException */ @Test public void test_get_package_file_multiple() throws ProtocolViolationException, IOException { //given String contentOneDat = "content of one.dat"; String contentTwoDat = "content of one.dat"; byte[] contentThreeDat = new byte[20]; new Random().nextBytes(contentThreeDat); SimpleHttpServer instance = spy(new SimpleHttpServer("none")); willReturn(MockUtils.getMockManifest()).given(instance).getManifest(); // return different response depending on called path HttpServerSimulator simulatedServer = new HttpServerSimulator(); simulatedServer.addResource("/repository/org/junit", "index", ContentType.TEXT_PLAIN, "one.dat\ntwo.dat\nthree.dat"); simulatedServer.addResource("/repository/org/junit", "one.dat", ContentType.TEXT_PLAIN, contentOneDat); simulatedServer.addResource("/repository/org/junit", "two.dat", ContentType.TEXT_PLAIN, contentTwoDat); simulatedServer.addResource("/repository/org/junit", "three.dat", HttpStatus.SC_OK, "OK", ContentType.TEXT_HTML, contentThreeDat); given(mockHttpClient.execute(Matchers.any(HttpGet.class))).willAnswer(simulatedServer); instance.setHttpClient(mockHttpClient); // when Map<String, byte[]> files = instance.getFilesOfPackage(".org.junit"); // then then(files.get("one.dat")).isEqualTo(IOUtils.toByteArray(new StringReader(contentOneDat))); then(files.get("two.dat")).isEqualTo(IOUtils.toByteArray(new StringReader(contentTwoDat))); then(files.get("three.dat")).isEqualTo(contentThreeDat); }
From source file:org.esigate.DriverTest.java
/** * 0000231: ESIgate should be enable to mashup elements for an error/404 page. * /* w w w . j a va 2 s . co m*/ * @see "http://www.esigate.org/mantisbt/view.php?id=231" * * @throws Exception */ public void testBug231RenderingOnProxyError() throws Exception { // Configuration Properties properties = new Properties(); properties.put(Parameters.REMOTE_URL_BASE.getName(), "http://localhost.mydomain.fr/"); properties.put(Parameters.PRESERVE_HOST.getName(), "true"); // Setup server responses. mockConnectionManager = new MockConnectionManager() { @Override public HttpResponse execute(HttpRequest httpRequest) { // The main page if (httpRequest.getRequestLine().getUri().equals("/foobar/")) { return new HttpResponseBuilder() .entity(new StringEntity("<esi:include src=\"http://test.mydomain.fr/esi/\"/>", ContentType.TEXT_HTML)) .status(HttpStatus.SC_BAD_REQUEST).build(); } // The ESI fragment if (httpRequest.getRequestLine().getUri().equals("/esi/")) { try { return new HttpResponseBuilder().entity("OK").build(); } catch (UnsupportedEncodingException e) { Assert.fail("Unexpected exception" + e.getMessage()); } } // Other unexpected request ? -> Fail Assert.fail("Unexpected request " + httpRequest.getRequestLine().getUri()); return null; } }; // Build driver and request. Driver driver = createMockDriver(properties, mockConnectionManager); request = IncomingRequest.builder("http://test.mydomain.fr/foobar/"); try { // Perform call with ESI rendering. driver.proxy("/foobar/", request.build(), new EsiRenderer()); fail("HttpErrorPage expected"); } catch (HttpErrorPage errorPage) { // Ensure request was esi-processed. HttpResponse response = errorPage.getHttpResponse(); Assert.assertEquals("OK", EntityUtils.toString(response.getEntity())); } }
From source file:ste.web.http.handlers.BugFreeFileHandler.java
@Test public void mime_type_based_on_file_extension() throws Exception { FileHandler h = new FileHandler("src/test/mime"); BasicHttpRequest request = HttpUtils.getSimpleGet("/test.txt"); BasicHttpResponse response = HttpUtils.getBasicResponse(); h.handle(request, response, new HttpSessionContext()); then(response.getStatusLine().getStatusCode()).isEqualTo(HttpStatus.SC_OK); then(response.getEntity().getContentType().getValue()).isEqualTo(ContentType.TEXT_PLAIN.getMimeType()); request = HttpUtils.getSimpleGet("/test.html"); h.handle(request, response, new HttpSessionContext()); then(response.getStatusLine().getStatusCode()).isEqualTo(HttpStatus.SC_OK); then(response.getEntity().getContentType().getValue()).isEqualTo(ContentType.TEXT_HTML.getMimeType()); request = HttpUtils.getSimpleGet("/test.png"); h.handle(request, response, new HttpSessionContext()); then(response.getStatusLine().getStatusCode()).isEqualTo(HttpStatus.SC_OK); then(response.getEntity().getContentType().getValue()) .isEqualTo(ContentType.create("image/png").getMimeType()); }
From source file:ste.web.http.handlers.FileHandler.java
@Override public void handle(final HttpRequest request, final HttpResponse response, final HttpContext context) throws HttpException, IOException { checkHttpMethod(request);//from w w w . j av a 2 s. co m String target = request.getRequestLine().getUri(); for (String exclude : excludePatterns) { if (target.matches(exclude)) { notFound(target, response); return; } } if (StringUtils.isNotBlank(webContext) && target.startsWith(webContext)) { target = target.substring(webContext.length()); } if (request instanceof HttpEntityEnclosingRequest) { HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity(); byte[] entityContent = EntityUtils.toByteArray(entity); } URI uri = null; try { uri = new URI(target); } catch (URISyntaxException x) { throw new HttpException("malformed URL '" + target + "'"); } final File file = new File(this.docRoot, uri.getPath()); if (!file.exists()) { notFound(target, response); } else if (!file.canRead() || file.isDirectory()) { response.setStatusCode(HttpStatus.SC_FORBIDDEN); StringEntity entity = new StringEntity("<html><body><h1>Access denied</h1></body></html>", ContentType.TEXT_HTML); response.setEntity(entity); } else { response.setStatusCode(HttpStatus.SC_OK); String mimeType = MimeUtils.getInstance().getMimeType(file); ContentType type = MimeUtils.MIME_UNKNOWN.equals(mimeType) ? ContentType.APPLICATION_OCTET_STREAM : ContentType.create(mimeType); FileEntity body = new FileEntity(file, type); response.setEntity(body); } }
From source file:ste.web.http.handlers.FileHandler.java
private void notFound(String target, final HttpResponse response) { response.setStatusCode(HttpStatus.SC_NOT_FOUND); StringEntity entity = new StringEntity("<html><body><h1>File " + target + " not found</h1></body></html>", ContentType.TEXT_HTML); response.setEntity(entity);/*ww w . j a va 2 s . c o m*/ }