List of usage examples for org.apache.http.entity InputStreamEntity InputStreamEntity
public InputStreamEntity(InputStream inputStream, long j, ContentType contentType)
From source file:eu.scape_project.fcrepo.integration.IntellectualEntitiesIT.java
@Test public void testIngestAndUpdateIntellectualEntity() throws Exception { IntellectualEntity ie1 = TestUtil.createTestEntity("entity-17"); this.postEntity(ie1); org.purl.dc.elements._1.ObjectFactory dcFac = new org.purl.dc.elements._1.ObjectFactory(); ElementContainer cnt = dcFac.createElementContainer(); SimpleLiteral lit_title = new SimpleLiteral(); lit_title.getContent().add("Object Updated"); cnt.getAny().add(dcFac.createTitle(lit_title)); IntellectualEntity ie2 = new IntellectualEntity.Builder(ie1).descriptive(cnt).build(); /* update the current object */ HttpPut put = new HttpPut(SCAPE_URL + "/entity/entity-17"); ByteArrayOutputStream sink = new ByteArrayOutputStream(); this.marshaller.serialize(ie2, sink); put.setEntity(new InputStreamEntity(new ByteArrayInputStream(sink.toByteArray()), sink.size(), ContentType.TEXT_XML));/*w ww.ja v a 2 s.c om*/ HttpResponse resp = this.client.execute(put); assertEquals(200, resp.getStatusLine().getStatusCode()); put.releaseConnection(); /* check that the new version is returned */ HttpGet get = new HttpGet(SCAPE_URL + "/entity/entity-17"); resp = this.client.execute(get); assertEquals(200, resp.getStatusLine().getStatusCode()); IntellectualEntity fetched = this.marshaller.deserialize(IntellectualEntity.class, resp.getEntity().getContent()); get.releaseConnection(); assertNotNull(fetched.getDescriptive()); assertEquals(ElementContainer.class, fetched.getDescriptive().getClass()); ElementContainer dc = (ElementContainer) fetched.getDescriptive(); assertEquals("Object Updated", dc.getAny().get(0).getValue().getContent().get(0)); /* check that the old version is returned when specifically asked for */ get = new HttpGet(SCAPE_URL + "/entity/entity-17/1"); resp = this.client.execute(get); assertEquals(200, resp.getStatusLine().getStatusCode()); fetched = this.marshaller.deserialize(IntellectualEntity.class, resp.getEntity().getContent()); get.releaseConnection(); assertNotNull(fetched.getDescriptive()); assertEquals(ElementContainer.class, fetched.getDescriptive().getClass()); dc = (ElementContainer) fetched.getDescriptive(); assertEquals("Object 1", dc.getAny().get(0).getValue().getContent().get(0)); /* check that the new version is returned when specifically asked for */ get = new HttpGet(SCAPE_URL + "/entity/entity-17/2"); resp = this.client.execute(get); assertEquals(200, resp.getStatusLine().getStatusCode()); fetched = this.marshaller.deserialize(IntellectualEntity.class, resp.getEntity().getContent()); get.releaseConnection(); assertNotNull(fetched.getDescriptive()); assertEquals(ElementContainer.class, fetched.getDescriptive().getClass()); dc = (ElementContainer) fetched.getDescriptive(); assertEquals("Object Updated", dc.getAny().get(0).getValue().getContent().get(0)); }
From source file:eu.scape_project.fcrepo.integration.IntellectualEntitiesIT.java
@Test public void testIngestAndUpdateRepresentation() throws Exception { IntellectualEntity ie1 = TestUtil.createTestEntity("entity-18"); this.postEntity(ie1); Representation r = new Representation.Builder(ie1.getRepresentations().get(0)).title("title update") .build();//from w ww . j a v a 2 s .c o m HttpPut put = new HttpPut(SCAPE_URL + "/representation/entity-18/" + r.getIdentifier().getValue()); ByteArrayOutputStream sink = new ByteArrayOutputStream(); this.marshaller.serialize(r, sink); put.setEntity(new InputStreamEntity(new ByteArrayInputStream(sink.toByteArray()), sink.size(), ContentType.TEXT_XML)); HttpResponse resp = this.client.execute(put); assertEquals(200, resp.getStatusLine().getStatusCode()); put.releaseConnection(); /* fetch the representation and check that the title has been updated */ HttpGet get = new HttpGet(SCAPE_URL + "/representation/entity-18/" + r.getIdentifier().getValue()); resp = this.client.execute(get); assertEquals(200, resp.getStatusLine().getStatusCode()); Representation fetched = this.marshaller.deserialize(Representation.class, resp.getEntity().getContent()); assertEquals(r.getIdentifier().getValue(), fetched.getIdentifier().getValue()); assertEquals("title update", fetched.getTitle()); get.releaseConnection(); }
From source file:eu.scape_project.fcrepo.integration.IntellectualEntitiesIT.java
@Test public void testIngestAndUpdateEntityMetadata() throws Exception { IntellectualEntity ie1 = TestUtil.createTestEntity("entity-19"); this.postEntity(ie1); org.purl.dc.elements._1.ObjectFactory dcFac = new org.purl.dc.elements._1.ObjectFactory(); ElementContainer cnt = dcFac.createElementContainer(); SimpleLiteral lit_title = new SimpleLiteral(); lit_title.getContent().add("DC metadata updated"); cnt.getAny().add(dcFac.createTitle(lit_title)); HttpPut put = new HttpPut(SCAPE_URL + "/metadata/entity-19/DESCRIPTIVE"); ByteArrayOutputStream sink = new ByteArrayOutputStream(); this.marshaller.serialize(cnt, sink); put.setEntity(new InputStreamEntity(new ByteArrayInputStream(sink.toByteArray()), sink.size(), ContentType.TEXT_XML));/*from w w w . j a v a2 s . c o m*/ HttpResponse resp = this.client.execute(put); assertEquals(200, resp.getStatusLine().getStatusCode()); put.releaseConnection(); /* fetch the entity and check that the title has been updated */ HttpGet get = new HttpGet(SCAPE_URL + "/metadata/entity-19/DESCRIPTIVE"); resp = this.client.execute(get); assertEquals(200, resp.getStatusLine().getStatusCode()); ElementContainer fetched = (ElementContainer) this.marshaller.deserialize(resp.getEntity().getContent()); assertEquals("DC metadata updated", fetched.getAny().get(0).getValue().getContent().get(0)); get.releaseConnection(); }
From source file:eu.scape_project.fcrepo.integration.IntellectualEntitiesIT.java
@Test public void testIngestAndUpdateRepresentationMetadata() throws Exception { IntellectualEntity ie1 = TestUtil.createTestEntity("entity-20"); this.postEntity(ie1); org.purl.dc.elements._1.ObjectFactory dcFac = new org.purl.dc.elements._1.ObjectFactory(); ElementContainer cnt = dcFac.createElementContainer(); SimpleLiteral lit_title = new SimpleLiteral(); lit_title.getContent().add("SOURCE metadata updated"); cnt.getAny().add(dcFac.createTitle(lit_title)); HttpPut put = new HttpPut(SCAPE_URL + "/metadata/entity-20/representation-1/SOURCE"); ByteArrayOutputStream sink = new ByteArrayOutputStream(); this.marshaller.serialize(cnt, sink); put.setEntity(new InputStreamEntity(new ByteArrayInputStream(sink.toByteArray()), sink.size(), ContentType.TEXT_XML));/* www .j a v a2 s . c o m*/ HttpResponse resp = this.client.execute(put); assertEquals(200, resp.getStatusLine().getStatusCode()); put.releaseConnection(); /* fetch the entity and check that the title has been updated */ HttpGet get = new HttpGet(SCAPE_URL + "/metadata/entity-20/representation-1/SOURCE"); resp = this.client.execute(get); assertEquals(200, resp.getStatusLine().getStatusCode()); ElementContainer fetched = (ElementContainer) this.marshaller.deserialize(resp.getEntity().getContent()); assertEquals("SOURCE metadata updated", fetched.getAny().get(0).getValue().getContent().get(0)); get.releaseConnection(); }
From source file:eu.scape_project.fcrepo.integration.IntellectualEntitiesIT.java
@Test public void testIngestAndUpdateFileMetadata() throws Exception { IntellectualEntity ie1 = TestUtil.createTestEntity("entity-21"); this.postEntity(ie1); HttpPut put = new HttpPut(SCAPE_URL + "/metadata/entity-21/representation-1/file-1/TECHNICAL"); ByteArrayOutputStream sink = new ByteArrayOutputStream(); this.marshaller.serialize(TestUtil.createFITSRecord(), sink); put.setEntity(new InputStreamEntity(new ByteArrayInputStream(sink.toByteArray()), sink.size(), ContentType.TEXT_XML));//from w w w .j a v a 2 s. c o m HttpResponse resp = this.client.execute(put); assertEquals(200, resp.getStatusLine().getStatusCode()); put.releaseConnection(); /* fetch the entity and check that the title has been updated */ HttpGet get = new HttpGet(SCAPE_URL + "/metadata/entity-21/representation-1/file-1/TECHNICAL"); resp = this.client.execute(get); assertEquals(200, resp.getStatusLine().getStatusCode()); Object fetched = this.marshaller.deserialize(resp.getEntity().getContent()); assertEquals(Fits.class, fetched.getClass()); get.releaseConnection(); }
From source file:org.eclipse.rdf4j.http.client.RDF4JProtocolSession.java
protected void upload(InputStream contents, String baseURI, RDFFormat dataFormat, boolean overwrite, boolean preserveNodeIds, Action action, Resource... contexts) throws IOException, RDFParseException, RepositoryException, UnauthorizedException { // Set Content-Length to -1 as we don't know it and we also don't want to // cache//ww w . ja va 2 s . c om HttpEntity entity = new InputStreamEntity(contents, -1, ContentType.parse(dataFormat.getDefaultMIMEType())); upload(entity, baseURI, overwrite, preserveNodeIds, action, contexts); }
From source file:com.naryx.tagfusion.cfm.http.cfHttpConnection.java
private void addFiles() throws cfmRunTimeException { List<fileDescriptor> files = httpData.getFiles(); if (files.size() > 0) { if (message instanceof HttpPost && (isMultipart || httpData.getFiles().size() > 0)) { if (multipartEntityBuilder == null) multipartEntityBuilder = MultipartEntityBuilder.create().setCharset(charset); for (int i = 0; i < files.size(); i++) { fileDescriptor nextFile = files.get(i); multipartEntityBuilder.addPart(nextFile.getName(), new FileBody(nextFile.getFile(), ContentType.create(nextFile.getMimeType()), nextFile.getFile().getName())); }//from w w w . j a v a 2s.co m } else if (message instanceof HttpPut) { fileDescriptor nextFile = files.get(0); // just use the first file specified try { FileInputStream fileIn = new FileInputStream(nextFile.getFile()); InputStreamEntity entity = new InputStreamEntity(fileIn, nextFile.getFile().length(), ContentType.create(nextFile.getMimeType())); ((HttpPut) message).setEntity(entity); } catch (FileNotFoundException e) { throw newRunTimeException("Failed to locate file " + nextFile.getFile().getAbsolutePath()); } } } }
From source file:org.apache.hadoop.gateway.dispatch.CappedBufferHttpEntityTest.java
@Test public void testIsStreaming() throws Exception { String input = "0123456789"; BasicHttpEntity basic;//from w w w .j a v a 2 s. co m InputStreamEntity streaming; CappedBufferHttpEntity replay; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(input.getBytes(UTF8))); replay = new CappedBufferHttpEntity(basic, 5); assertThat(replay.isStreaming(), is(true)); basic = new BasicHttpEntity(); basic.setContent(null); replay = new CappedBufferHttpEntity(basic, 5); assertThat(replay.isStreaming(), is(false)); streaming = new InputStreamEntity(new ByteArrayInputStream(input.getBytes(UTF8)), 10, ContentType.TEXT_PLAIN); replay = new CappedBufferHttpEntity(streaming, 5); assertThat(replay.isStreaming(), is(true)); }
From source file:eu.scape_project.fcrepo.integration.IntellectualEntitiesIT.java
@Test public void testIngestAndUpdateBistreamMetadata() throws Exception { IntellectualEntity ie1 = TestUtil.createTestEntity("entity-22"); this.postEntity(ie1); HttpPut put = new HttpPut(SCAPE_URL + "/metadata/entity-22/representation-1/file-1/bitstream-1/TECHNICAL"); ByteArrayOutputStream sink = new ByteArrayOutputStream(); this.marshaller.serialize(TestUtil.createMIXRecord(), sink); put.setEntity(new InputStreamEntity(new ByteArrayInputStream(sink.toByteArray()), sink.size(), ContentType.TEXT_XML));/*from w ww . jav a 2 s . c o m*/ HttpResponse resp = this.client.execute(put); assertEquals(200, resp.getStatusLine().getStatusCode()); put.releaseConnection(); /* fetch the entity and check that the title has been updated */ HttpGet get = new HttpGet(SCAPE_URL + "/metadata/entity-22/representation-1/file-1/bitstream-1/TECHNICAL"); resp = this.client.execute(get); assertEquals(200, resp.getStatusLine().getStatusCode()); Object fetched = this.marshaller.deserialize(resp.getEntity().getContent()); assertEquals(Mix.class, fetched.getClass()); get.releaseConnection(); }
From source file:com.sangupta.jerry.http.WebRequest.java
/** * Set the body stream from given input stream of given content type. * * @param instream/* w w w .ja v a2 s. com*/ * the {@link InputStream} from which to read * * @param contentType * the {@link ContentType} of the stream * * @return this very {@link WebRequest} */ public WebRequest bodyStream(final InputStream instream, final ContentType contentType) { return body(new InputStreamEntity(instream, -1, contentType)); }