List of usage examples for org.apache.http.entity ContentType TEXT_XML
ContentType TEXT_XML
To view the source code for org.apache.http.entity ContentType TEXT_XML.
Click Source Link
From source file:eu.scape_project.fcrepo.integration.IntellectualEntitiesIT.java
@Test public void testIngestAndFetchVersionList() throws Exception { IntellectualEntity ie1 = TestUtil.createTestEntity("entity-23"); this.postEntity(ie1); HttpPut put = new HttpPut(SCAPE_URL + "/metadata/entity-23/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)); HttpResponse resp = this.client.execute(put); assertEquals(200, resp.getStatusLine().getStatusCode()); put.releaseConnection();// ww w. j av a2 s. c o m /* fetch the entity and check that the title has been updated */ HttpGet get = new HttpGet(SCAPE_URL + "/entity-version-list/entity-23"); resp = this.client.execute(get); assertEquals(200, resp.getStatusLine().getStatusCode()); VersionList fetched = (VersionList) this.marshaller.deserialize(resp.getEntity().getContent()); assertEquals(2, fetched.getVersionIdentifiers().size()); get.releaseConnection(); }
From source file:eu.scape_project.fcrepo.integration.IntellectualEntitiesIT.java
@Test public void testIngestAndUpdateRepresentationAndFetchOldVersion() throws Exception { IntellectualEntity ie1 = TestUtil.createTestEntity("entity-24"); this.postEntity(ie1); Representation r = new Representation.Builder(ie1.getRepresentations().get(0)).title("title update") .build();// w ww. ja v a2 s .c om HttpPut put = new HttpPut(SCAPE_URL + "/representation/entity-24/" + 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-24/" + r.getIdentifier().getValue() + "/1"); 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("Text representation", fetched.getTitle()); get.releaseConnection(); }
From source file:eu.scape_project.fcrepo.integration.IntellectualEntitiesIT.java
@Test public void testIngestAndUpdateFileAndFetchOldVersion() throws Exception { IntellectualEntity ie1 = TestUtil.createTestEntity("entity-25"); this.postEntity(ie1); File f = new File.Builder(ie1.getRepresentations().get(0).getFiles().get(0)) .uri(URI.create(TestUtil.class.getClassLoader().getResource("scape_logo.png").toString())) .filename("wikipedia.png").mimetype("image/png").build(); Representation r = new Representation.Builder(ie1.getRepresentations().get(0)).title("title update") .files(Arrays.asList(f)).build(); HttpPut put = new HttpPut(SCAPE_URL + "/representation/entity-25/" + 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();/*from w w w. ja va 2 s.co m*/ /* fetch the file */ HttpGet get = new HttpGet(SCAPE_URL + "/file/entity-25/" + r.getIdentifier().getValue() + "/" + f.getIdentifier().getValue() + "/1"); resp = this.client.execute(get); assertEquals(200, resp.getStatusLine().getStatusCode()); get.releaseConnection(); }
From source file:eu.scape_project.fcrepo.integration.IntellectualEntitiesIT.java
@Test public void testIngestAndUpdateBitstreamAndFetchOldVersion() throws Exception { IntellectualEntity ie1 = TestUtil.createTestEntity("entity-26"); this.postEntity(ie1); HttpPut put = new HttpPut(SCAPE_URL + "/metadata/entity-26/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)); HttpResponse resp = this.client.execute(put); assertEquals(200, resp.getStatusLine().getStatusCode()); put.releaseConnection();//from w w w . j av a 2s .co m /* fetch the entity and check that the title has been updated */ HttpGet get = new HttpGet(SCAPE_URL + "/bitstream/entity-26/representation-1/file-1/bitstream-1/1"); resp = this.client.execute(get); assertEquals(200, resp.getStatusLine().getStatusCode()); BitStream fetched = (BitStream) this.marshaller.deserialize(resp.getEntity().getContent()); assertEquals(Fits.class, fetched.getTechnical().getClass()); get.releaseConnection(); }
From source file:org.opentravel.schemacompiler.repository.impl.RemoteRepositoryClient.java
/** * @see org.opentravel.schemacompiler.repository.Repository#commit(org.opentravel.schemacompiler.repository.RepositoryItem) */// ww w. j a v a2 s . c o m @Override public void commit(RepositoryItem item) throws RepositoryException { InputStream wipContent = null; try { validateRepositoryItem(item); // Obtain a file stream for the item's WIP content File wipFile = manager.getFileManager().getLibraryWIPContentLocation(item.getBaseNamespace(), item.getFilename()); if (!wipFile.exists()) { throw new RepositoryException("The work-in-process file does not exist: " + item.getFilename()); } wipContent = new FileInputStream(wipFile); // Build the HTTP request for the remote service RepositoryItemIdentityType itemIdentity = createItemIdentity(item); Marshaller marshaller = RepositoryFileManager.getSharedJaxbContext().createMarshaller(); HttpPost request = newPostRequest(COMMIT_ENDPOINT); MultipartEntityBuilder mpEntity = MultipartEntityBuilder.create(); StringWriter xmlWriter = new StringWriter(); marshaller.marshal(objectFactory.createRepositoryItemIdentity(itemIdentity), xmlWriter); mpEntity.addTextBody("item", xmlWriter.toString(), ContentType.TEXT_XML); mpEntity.addBinaryBody("fileContent", toByteArray(wipContent), ContentType.DEFAULT_BINARY, item.getFilename()); // mpEntity.addPart( "fileContent", new InputStreamBody(wipContent, item.getFilename()) // ); request.setEntity(mpEntity.build()); // Send the web service request and check the response log.info("Sending commit request to HTTP endpoint: " + endpointUrl); HttpResponse response = executeWithAuthentication(request); if (response.getStatusLine().getStatusCode() != HTTP_RESPONSE_STATUS_OK) { throw new RepositoryException(getResponseErrorMessage(response)); } log.info("Commit response received - Status OK"); // Update the local cache with the content we just sent to the remote web service downloadContent(item, true); } catch (JAXBException e) { throw new RepositoryException("The format of the library meta-data is unreadable.", e); } catch (IOException e) { throw new RepositoryException("The remote repository is unavailable.", e); } finally { try { if (wipContent != null) wipContent.close(); } catch (Throwable t) { } } }
From source file:org.opentravel.schemacompiler.repository.impl.RemoteRepositoryClient.java
/** * @see org.opentravel.schemacompiler.repository.Repository#lock(org.opentravel.schemacompiler.repository.RepositoryItem) *//*w w w . j a v a2 s .c o m*/ @SuppressWarnings("unchecked") @Override public void lock(RepositoryItem item) throws RepositoryException { boolean success = false; try { validateRepositoryItem(item); manager.getFileManager().startChangeSet(); // Before performing the lock, check to see if we need to refresh the // library from the remote repository if (isLocalContentStale(item)) { throw new RepositoryOutOfSyncException("Unable to lock '" + item.getFilename() + "' because the local copy is out of date (refresh required)."); } // Build the HTTP request for the remote service RepositoryItemIdentityType itemIdentity = createItemIdentity(item); Marshaller marshaller = RepositoryFileManager.getSharedJaxbContext().createMarshaller(); HttpPost request = newPostRequest(LOCK_ENDPOINT); StringWriter xmlWriter = new StringWriter(); marshaller.marshal(objectFactory.createRepositoryItemIdentity(itemIdentity), xmlWriter); request.setEntity(new StringEntity(xmlWriter.toString(), ContentType.TEXT_XML)); // Send the web service request and unmarshall the updated meta-data from the response log.info("Sending lock request to HTTP endpoint: " + endpointUrl); HttpResponse response = executeWithAuthentication(request); if (response.getStatusLine().getStatusCode() != HTTP_RESPONSE_STATUS_OK) { throw new RepositoryException(getResponseErrorMessage(response)); } log.info("Lock response received - Status OK"); Unmarshaller unmarshaller = RepositoryFileManager.getSharedJaxbContext().createUnmarshaller(); JAXBElement<LibraryInfoType> jaxbElement = (JAXBElement<LibraryInfoType>) unmarshaller .unmarshal(response.getEntity().getContent()); // Update the local cache with the content we just received from the remote web service manager.getFileManager().saveLibraryMetadata(jaxbElement.getValue()); // Update the local repository item with the latest state information ((RepositoryItemImpl) item).setState(RepositoryItemState.MANAGED_WIP); ((RepositoryItemImpl) item).setLockedByUser(userId); success = true; } catch (JAXBException e) { throw new RepositoryException("The format of the library meta-data is unreadable.", e); } catch (IOException e) { throw new RepositoryException("The remote repository is unavailable.", e); } finally { // Commit or roll back the changes based on the result of the operation if (success) { manager.getFileManager().commitChangeSet(); } else { try { manager.getFileManager().rollbackChangeSet(); } catch (Throwable t) { log.error("Error rolling back the current change set.", t); } } } }
From source file:org.opentravel.schemacompiler.repository.impl.RemoteRepositoryClient.java
/** * @see org.opentravel.schemacompiler.repository.Repository#unlock(org.opentravel.schemacompiler.repository.RepositoryItem, * boolean)/*from w w w .ja v a2 s . c om*/ */ @SuppressWarnings("unchecked") @Override public void unlock(RepositoryItem item, boolean commitWIP) throws RepositoryException { InputStream wipContent = null; boolean success = false; try { validateRepositoryItem(item); manager.getFileManager().startChangeSet(); // Build the HTTP request for the remote service RepositoryItemIdentityType itemIdentity = createItemIdentity(item); Marshaller marshaller = RepositoryFileManager.getSharedJaxbContext().createMarshaller(); HttpPost request = newPostRequest(UNLOCK_ENDPOINT); MultipartEntityBuilder mpEntity = MultipartEntityBuilder.create(); StringWriter xmlWriter = new StringWriter(); if (commitWIP) { File wipFile = manager.getFileManager().getLibraryWIPContentLocation(item.getBaseNamespace(), item.getFilename()); if (!wipFile.exists()) { throw new RepositoryException("The work-in-process file does not exist: " + item.getFilename()); } wipContent = new FileInputStream(wipFile); mpEntity.addBinaryBody("fileContent", toByteArray(wipContent), ContentType.DEFAULT_BINARY, item.getFilename()); // mpEntity.addPart( "fileContent", new InputStreamBody(wipContent, // item.getFilename()) ); } marshaller.marshal(objectFactory.createRepositoryItemIdentity(itemIdentity), xmlWriter); mpEntity.addTextBody("item", xmlWriter.toString(), ContentType.TEXT_XML); request.setEntity(mpEntity.build()); // Send the web service request and unmarshall the updated meta-data from the response log.info("Sending lock request to HTTP endpoint: " + endpointUrl); HttpResponse response = executeWithAuthentication(request); if (response.getStatusLine().getStatusCode() != HTTP_RESPONSE_STATUS_OK) { throw new RepositoryException(getResponseErrorMessage(response)); } log.info("Lock response received - Status OK"); Unmarshaller unmarshaller = RepositoryFileManager.getSharedJaxbContext().createUnmarshaller(); JAXBElement<LibraryInfoType> jaxbElement = (JAXBElement<LibraryInfoType>) unmarshaller .unmarshal(response.getEntity().getContent()); // Update the local cache with the content we just received from the remote web service manager.getFileManager().saveLibraryMetadata(jaxbElement.getValue()); // Update the local repository item with the latest state information ((RepositoryItemImpl) item).setState(RepositoryItemState.MANAGED_UNLOCKED); ((RepositoryItemImpl) item).setLockedByUser(null); // Force a re-download of the updated content to make sure the local copy is // synchronized // with the remote repository. downloadContent(item, true); success = true; } catch (JAXBException e) { throw new RepositoryException("The format of the library meta-data is unreadable.", e); } catch (IOException e) { throw new RepositoryException("The remote repository is unavailable.", e); } finally { // Close the WIP content input stream try { if (wipContent != null) wipContent.close(); } catch (Throwable t) { } // Commit or roll back the changes based on the result of the operation if (success) { manager.getFileManager().commitChangeSet(); } else { try { manager.getFileManager().rollbackChangeSet(); } catch (Throwable t) { log.error("Error rolling back the current change set.", t); } } } }
From source file:org.opentravel.schemacompiler.repository.impl.RemoteRepositoryClient.java
/** * @see org.opentravel.schemacompiler.repository.Repository#promote(org.opentravel.schemacompiler.repository.RepositoryItem) *//*from w w w . j ava 2 s. c o m*/ @Override public void promote(RepositoryItem item) throws RepositoryException { try { validateRepositoryItem(item); // Build the HTTP request for the remote service RepositoryItemIdentityType itemIdentity = createItemIdentity(item); Marshaller marshaller = RepositoryFileManager.getSharedJaxbContext().createMarshaller(); HttpPost request = newPostRequest(PROMOTE_ENDPOINT); StringWriter xmlWriter = new StringWriter(); marshaller.marshal(objectFactory.createRepositoryItemIdentity(itemIdentity), xmlWriter); request.setEntity(new StringEntity(xmlWriter.toString(), ContentType.TEXT_XML)); // Send the web service request and check the response log.info("Sending promote request to HTTP endpoint: " + endpointUrl); HttpResponse response = executeWithAuthentication(request); if (response.getStatusLine().getStatusCode() != HTTP_RESPONSE_STATUS_OK) { throw new RepositoryException(getResponseErrorMessage(response)); } log.info("Promote response received - Status OK"); // Update the local cache with the content that was just modified in the remote // repository downloadContent(item, true); } catch (JAXBException e) { throw new RepositoryException("The format of the library meta-data is unreadable.", e); } catch (IOException e) { throw new RepositoryException("The remote repository is unavailable.", e); } }
From source file:org.opentravel.schemacompiler.repository.impl.RemoteRepositoryClient.java
/** * @see org.opentravel.schemacompiler.repository.Repository#demote(org.opentravel.schemacompiler.repository.RepositoryItem) *///from w w w.j a v a 2 s. co m @Override public void demote(RepositoryItem item) throws RepositoryException { try { validateRepositoryItem(item); // Build the HTTP request for the remote service RepositoryItemIdentityType itemIdentity = createItemIdentity(item); Marshaller marshaller = RepositoryFileManager.getSharedJaxbContext().createMarshaller(); HttpPost request = newPostRequest(DEMOTE_ENDPOINT); StringWriter xmlWriter = new StringWriter(); marshaller.marshal(objectFactory.createRepositoryItemIdentity(itemIdentity), xmlWriter); request.setEntity(new StringEntity(xmlWriter.toString(), ContentType.TEXT_XML)); // Send the web service request and check the response log.info("Sending promote request to HTTP endpoint: " + endpointUrl); HttpResponse response = executeWithAuthentication(request); if (response.getStatusLine().getStatusCode() != HTTP_RESPONSE_STATUS_OK) { throw new RepositoryException(getResponseErrorMessage(response)); } log.info("Promote response received - Status OK"); // Update the local cache by deleting the local copy of the item downloadContent(item, true); } catch (JAXBException e) { throw new RepositoryException("The format of the library meta-data is unreadable.", e); } catch (IOException e) { throw new RepositoryException("The remote repository is unavailable.", e); } }