List of usage examples for org.apache.http.entity BasicHttpEntity BasicHttpEntity
public BasicHttpEntity()
From source file:org.springframework.cloud.netflix.ribbon.apache.HttpClientUtils.java
/** * Creates an new {@link HttpEntity} by copying the {@link HttpEntity} from the {@link HttpResponse}. * This method will close the response after copying the entity. * @param response The response to create the {@link HttpEntity} from * @return A new {@link HttpEntity}/*from w ww . j a va 2s . co m*/ * @throws IOException thrown if there is a problem closing the response. */ public static HttpEntity createEntity(HttpResponse response) throws IOException { ByteArrayInputStream is = new ByteArrayInputStream(EntityUtils.toByteArray(response.getEntity())); BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(is); entity.setContentLength(response.getEntity().getContentLength()); if (CloseableHttpResponse.class.isInstance(response)) { ((CloseableHttpResponse) response).close(); } return entity; }
From source file:com.microsoft.alm.plugin.mocks.MockCatalogService.java
public void addResponse(String response) throws HttpException { final HttpResponse httpResponse = new BasicHttpResponse( new BasicStatusLine(new ProtocolVersion("https", 1, 0), HttpStatus.SC_OK, "reason")); final BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(response.getBytes())); httpResponse.setEntity(entity);/* www . ja v a 2s.c om*/ responses.add(httpResponse); }
From source file:com.aerofs.baseline.http.HttpUtils.java
public static BasicHttpEntity writeStringToEntity(String content) { BasicHttpEntity basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(content.getBytes(Charsets.UTF_8))); return basic; }
From source file:org.fcrepo.auth.xacml.XACMLTestUtil.java
/** * Removes the policy link from an object. * * @param client/*w w w. j a va 2s .co m*/ * @param serverAddress * @param objectPath * @throws Exception */ public static void unlinkPolicies(final HttpClient client, final String serverAddress, final String objectPath) throws Exception { final String subjectURI = serverAddress + objectPath; final HttpPatch patch = new HttpPatch(subjectURI); // setAuth(patch, "fedoraAdmin"); patch.addHeader("Content-Type", "application/sparql-update"); final BasicHttpEntity e = new BasicHttpEntity(); e.setContent(new ByteArrayInputStream(("DELETE { <" + subjectURI + "> <http://fedora.info/definitions/v4/authorization#policy> ?o } " + "WHERE { <" + subjectURI + "> <http://fedora.info/definitions/v4/authorization#policy> ?o }").getBytes())); patch.setEntity(e); LOGGER.debug("PATCH: {}", patch.getURI()); final HttpResponse response = client.execute(patch); assertEquals(NO_CONTENT.getStatusCode(), response.getStatusLine().getStatusCode()); }
From source file:at.deder.ybr.test.cukes.HttpServerSimulator.java
@Override public Object answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); HttpResponse response = null;//ww w . j a v a 2 s. co m if (args.length != 1 && !(args[0] instanceof HttpGet)) { response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_INTERNAL_SERVER_ERROR, "wrong arguments"); return response; } HttpGet request = (HttpGet) args[0]; BasicHttpEntity entity = new BasicHttpEntity(); String requestedPath = request.getURI().getPath(); VirtualResource requestedResource = getResource(requestedPath); if (requestedResource == null) { response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_FOUND, "not found"); } else { entity.setContent(new ByteArrayInputStream(requestedResource.content)); entity.setContentType(requestedResource.contentType); response = new BasicHttpResponse(HttpVersion.HTTP_1_1, requestedResource.httpStatus, requestedResource.httpStatusText); response.setEntity(entity); } return response; }
From source file:org.wso2.iot.refarch.rpi.agent.connector.HttpService.java
public void sendPayload(JSONObject data) throws IOException, ExecutionException, InterruptedException { JSONObject dataObj = new JSONObject(); dataObj.put("data", data); HttpClient client = HttpClientBuilder.create().build(); System.out.println("Created HTTP Client"); HttpPost post = new HttpPost(address); post.setHeader("content-type", "application/json"); BasicHttpEntity he = new BasicHttpEntity(); he.setContent(new ByteArrayInputStream(dataObj.toString().getBytes())); post.setEntity(he);/* ww w.j av a 2s . c o m*/ client.execute(post); System.out.println("Payload sent"); }
From source file:com.brokenevent.nanotests.http.TestPostRequest.java
/** * Initializes instance of the POST request for the given resource. * @param resource resource name// ww w . ja v a2s . c o m */ public TestPostRequest(String resource) { super(resource); request = new HttpPost(resource); entity = new BasicHttpEntity(); ((HttpPost) request).setEntity(entity); }
From source file:org.fcrepo.integration.generator.DublinCoreGeneratorIT.java
@Test public void testJcrPropertiesBasedOaiDc() throws Exception { final int status = getStatus(postObjMethod("DublinCoreTest1")); assertEquals(201, status);//from w w w.j ava 2s. co m final HttpPatch post = new HttpPatch(serverAddress + "DublinCoreTest1"); post.setHeader("Content-Type", "application/sparql-update"); final BasicHttpEntity entity = new BasicHttpEntity(); final String subjectURI = serverAddress + "DublinCoreTest1"; entity.setContent(new ByteArrayInputStream(("INSERT { <" + subjectURI + "> <http://purl.org/dc/elements/1.1/identifier> \"this is an identifier\" } WHERE {}") .getBytes())); post.setEntity(entity); assertEquals(204, getStatus(post)); final HttpGet getWorstCaseOaiMethod = new HttpGet(serverOAIAddress + "DublinCoreTest1/oai:dc"); getWorstCaseOaiMethod.setHeader("Accept", TEXT_XML); final HttpResponse response = client.execute(getWorstCaseOaiMethod); assertEquals(200, response.getStatusLine().getStatusCode()); final String content = EntityUtils.toString(response.getEntity()); logger.debug("Got content: {}", content); assertTrue("Didn't find oai_dc!", compile("oai_dc", DOTALL).matcher(content).find()); assertTrue("Didn't find dc:identifier!", compile("dc:identifier", DOTALL).matcher(content).find()); }
From source file:es.tid.fiware.rss.oauth.test.ResponseHandlerTest.java
/** * /*from w w w . ja v a 2 s .co m*/ */ @Test public void handleResponseTest() throws Exception { ResponseHandler handler = new ResponseHandler(); HttpResponseFactory factory = new DefaultHttpResponseFactory(); HttpResponse responseSent = factory .newHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "reason"), null); HttpResponse response = handler.handleResponse(responseSent); Assert.assertEquals(handler.getStatus(), HttpStatus.SC_OK); Assert.assertFalse(handler.hasContent()); // response with content. BasicHttpEntity entity = new BasicHttpEntity(); InputStream inputStream = new ByteArrayInputStream("new content".getBytes()); entity.setContent(inputStream); entity.setContentLength("new content".length()); // sets the length response.setEntity(entity); response = handler.handleResponse(responseSent); Assert.assertEquals("new content", handler.getResponseContent()); }