List of usage examples for org.apache.http.entity BasicHttpEntity BasicHttpEntity
public BasicHttpEntity()
From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testS_C1_PC_IB() throws IOException { String data = "0123456789"; BasicHttpEntity basic;/*from w w w . j ava2 s .c o m*/ PartiallyRepeatableHttpEntity replay; InputStream stream; String text; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic, 20); stream = replay.getContent(); text = byteRead(stream, 3); assertThat(text, is("012")); }
From source file:org.apache.hadoop.gateway.dispatch.CappedBufferHttpEntityTest.java
@Test public void testB_C1_PC_IB() throws IOException { String data = "0123456789"; BasicHttpEntity basic;//from ww w . j a v a 2 s . c o m CappedBufferHttpEntity replay; InputStream stream; String text; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8))); replay = new CappedBufferHttpEntity(basic, 20); stream = replay.getContent(); text = blockRead(stream, UTF8, 3, 3); assertThat(text, is("012")); }
From source file:org.fcrepo.integration.http.api.html.FedoraHtmlResponsesIT.java
License:asdf
private void postSparqlUpdateUsingHttpClient(final String sparql, final String pid) throws IOException { final HttpPatch method = new HttpPatch(serverAddress + pid); method.addHeader("Content-Type", "application/sparql-update"); final BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(sparql.getBytes())); method.setEntity(entity);//from w w w . j a va 2 s. co m final HttpResponse response = client.execute(method); assertEquals("Expected successful response.", 204, response.getStatusLine().getStatusCode()); }
From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testB_C1_PC_IB() throws IOException { String data = "0123456789"; BasicHttpEntity basic;/*from ww w . j a v a 2 s .c o m*/ PartiallyRepeatableHttpEntity replay; InputStream stream; String text; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic, 20); stream = replay.getContent(); text = blockRead(stream, UTF8, 3, 3); assertThat(text, is("012")); }
From source file:org.apache.hadoop.gateway.dispatch.CappedBufferHttpEntityTest.java
@Test public void testS_C1_PC_OB() throws IOException { try {/*from ww w. j a v a 2s.c o m*/ String data = "0123456789"; BasicHttpEntity basic; CappedBufferHttpEntity replay; InputStream stream; String text; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8))); replay = new CappedBufferHttpEntity(basic, 5); stream = replay.getContent(); text = byteRead(stream, -1); fail("Expected IOException"); assertThat(text, is("0123456789")); stream.close(); } catch (IOException e) { // expected } }
From source file:ch.ifocusit.livingdoc.plugin.publish.confluence.client.HttpRequestFactory.java
private static BasicHttpEntity httpEntityWithJsonPayload(Object payload) { String jsonPayload = toJsonString(payload); BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(jsonPayload.getBytes())); return entity; }
From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testS_C1_PC_OB() throws IOException { String data = "0123456789"; BasicHttpEntity basic;/*from www .ja va 2 s . c o m*/ PartiallyRepeatableHttpEntity replay; InputStream stream; String text; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic, 5); stream = replay.getContent(); text = byteRead(stream, -1); assertThat(text, is("0123456789")); stream.close(); }
From source file:org.fcrepo.integration.FedoraHtmlResponsesIT.java
License:asdf
private static void postSparqlUpdateUsingHttpClient(final String sparql, final String pid) throws IOException { final HttpPatch method = new HttpPatch(serverAddress + pid); method.addHeader(CONTENT_TYPE, "application/sparql-update"); final BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(sparql.getBytes())); method.setEntity(entity);/* www. ja v a 2 s . c o m*/ final HttpResponse response = client.execute(method); assertEquals("Expected successful response.", 204, response.getStatusLine().getStatusCode()); }
From source file:io.hops.hopsworks.api.kibana.KibanaProxyServlet.java
/** * Copy response body data (the entity) from the proxy to the servlet client. * * @param proxyResponse/*from ww w. j a v a2 s . c o m*/ * @param servletResponse * @param kibanaFilter * @param email */ protected void copyResponseEntity(HttpResponse proxyResponse, HttpServletResponse servletResponse, KibanaFilter kibanaFilter, String email) throws IOException { if (kibanaFilter == null) { super.copyResponseEntity(proxyResponse, servletResponse); } else { switch (kibanaFilter) { case LEGACY_SCROLL_START: case KIBANA_DEFAULT_INDEX: return; case KIBANA_SAVED_OBJECTS_API: case ELASTICSEARCH_SEARCH: HttpEntity entity = proxyResponse.getEntity(); if (entity != null) { GzipDecompressingEntity gzipEntity = new GzipDecompressingEntity(entity); String resp = EntityUtils.toString(gzipEntity); BasicHttpEntity basic = new BasicHttpEntity(); //Remove all projects other than the current one and check //if user is authorizer to access it JSONObject indices = new JSONObject(resp); LOG.log(Level.FINE, "indices:{0}", indices.toString()); JSONArray hits = null; String projectName = currentProjects.get(email); List<String> projects = new ArrayList(); //If we don't have the current project, filter out based on all user's projects if (Strings.isNullOrEmpty(projectName)) { List<String> projectNames = projectController.findProjectNamesByUser(email, true); if (projectNames != null && !projectNames.isEmpty()) { projects.addAll(projectNames); } } else { projects.add(projectName); } if (kibanaFilter == KibanaFilter.ELASTICSEARCH_SEARCH && HopsUtils.jsonKeyExists(indices, "buckets")) { hits = indices.getJSONObject("aggregations").getJSONObject("indices") .getJSONArray("buckets"); } else if (kibanaFilter == KibanaFilter.KIBANA_SAVED_OBJECTS_API && indices.has("saved_objects")) { hits = indices.getJSONArray("saved_objects"); } if (hits != null) { LOG.log(Level.FINE, "hits:{0}", hits); for (int i = hits.length() - 1; i >= 0; i--) { String objectId = null; switch (kibanaFilter) { case ELASTICSEARCH_SEARCH: objectId = hits.getJSONObject(i).getString("key"); break; case KIBANA_SAVED_OBJECTS_API: objectId = elasticController.getIndexFromKibana(hits.getJSONObject(i)); break; default: break; } if (!Strings.isNullOrEmpty(objectId) && (!isAuthorizedKibanaObject(objectId, email, projects))) { hits.remove(i); LOG.log(Level.FINE, "removed objectId:{0}", objectId); } } } InputStream in = IOUtils.toInputStream(indices.toString()); OutputStream servletOutputStream = servletResponse.getOutputStream(); basic.setContent(in); GzipCompressingEntity compress = new GzipCompressingEntity(basic); compress.writeTo(servletOutputStream); } break; default: super.copyResponseEntity(proxyResponse, servletResponse); break; } } }
From source file:org.apache.hadoop.gateway.dispatch.CappedBufferHttpEntityTest.java
@Test public void testB_C1_PC_OB() throws IOException { String data = "0123456789"; BasicHttpEntity basic;/*from w ww .ja v a 2 s. c o m*/ CappedBufferHttpEntity replay; InputStream stream; String text; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8))); replay = new CappedBufferHttpEntity(basic, 5); stream = replay.getContent(); try { text = blockRead(stream, UTF8, -1, 4); fail("Expected IOException"); } catch (IOException e) { // expected } }