public Response setFileContentsFromURL()

in taverna-server-webapp/src/main/java/org/apache/taverna/server/master/DirectoryREST.java [355:387]


	public Response setFileContentsFromURL(List<PathSegment> filePath,
			List<URI> referenceList, UriInfo ui)
			throws NoDirectoryEntryException, NoUpdateException,
			FilesystemAccessException {
		support.permitUpdate(run);
		if (referenceList.isEmpty() || referenceList.size() > 1)
			return status(422).entity("URI list must have single URI in it")
					.build();
		URI uri = referenceList.get(0);
		try {
			uri.toURL();
		} catch (MalformedURLException e) {
			return status(422).entity("URI list must have value URL in it")
					.build();
		}
		Holder<Boolean> isNew = new Holder<>(true);
		File f = getFileForWrite(filePath, isNew);

		try {
			support.copyDataToFile(uri, f);
		} catch (MalformedURLException ex) {
			// Should not happen; called uri.toURL() successfully above
			throw new NoUpdateException("failed to parse URI", ex);
		} catch (IOException ex) {
			throw new FilesystemAccessException(
					"failed to transfer data from URI", ex);
		}

		if (isNew.value)
			return created(ui.getAbsolutePath()).build();
		else
			return noContent().build();
	}