Java Code Examples for org.sonatype.nexus.repository.storage.StorageFacet#createTempBlob()
The following examples show how to use
org.sonatype.nexus.repository.storage.StorageFacet#createTempBlob() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NpmRequestParser.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
/** * Parses an incoming "npm publish" or "npm unpublish" request, returning the results. Note that you should probably * call this from within a try-with-resources block to manage the lifecycle of any temp blobs created during the * operation. */ public NpmPublishRequest parsePublish(final Repository repository, final Payload payload) throws IOException { checkNotNull(repository); checkNotNull(payload); StorageFacet storageFacet = repository.facet(StorageFacet.class); try (TempBlob tempBlob = storageFacet.createTempBlob(payload, NpmFacetUtils.HASH_ALGORITHMS)) { try { return parseNpmPublish(storageFacet, tempBlob, UTF_8); } catch (JsonParseException e) { // fallback if (e.getMessage().contains("Invalid UTF-8")) { // try again, but assume ISO8859-1 encoding now, that is illegal for JSON return parseNpmPublish(storageFacet, tempBlob, ISO_8859_1); } throw new InvalidContentException("Invalid JSON input", e); } } }
Example 2
Source File: OrientPyPiHostedFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
private Asset createIndexAsset(final String name, final StorageTx tx, final String indexPath, final Bucket bucket) throws IOException { String html = buildIndex(name, tx); Asset savedIndex = tx.createAsset(bucket, getRepository().getFormat()); savedIndex.name(indexPath); savedIndex.formatAttributes().set(P_ASSET_KIND, AssetKind.INDEX.name()); StorageFacet storageFacet = getRepository().facet(StorageFacet.class); TempBlob tempBlob = storageFacet.createTempBlob(new ByteArrayInputStream(html.getBytes(UTF_8)), HASH_ALGORITHMS); saveAsset(tx, savedIndex, tempBlob, TEXT_HTML, new AttributesMap()); return savedIndex; }
Example 3
Source File: AptSnapshotFacetSupport.java From nexus-repository-apt with Eclipse Public License 1.0 | 6 votes |
@Transactional(retryOn = { ONeedRetryException.class }) @Override public void createSnapshot(String id, SnapshotComponentSelector selector) throws IOException { StorageTx tx = UnitOfWork.currentTx(); StorageFacet storageFacet = facet(StorageFacet.class); Bucket bucket = tx.findBucket(getRepository()); Component component = tx.createComponent(bucket, getRepository().getFormat()).name(id); tx.saveComponent(component); for (SnapshotItem item : collectSnapshotItems(selector)) { String assetName = createAssetPath(id, item.specifier.path); Asset asset = tx.createAsset(bucket, component).name(assetName); try (final TempBlob streamSupplier = storageFacet.createTempBlob(item.content.openInputStream(), FacetHelper.hashAlgorithms)) { AssetBlob blob = tx.createBlob(item.specifier.path, streamSupplier, FacetHelper.hashAlgorithms, null, FacetHelper.determineContentType(item), true); tx.attachBlob(asset, blob); } finally { item.content.close(); } tx.saveAsset(asset); } }
Example 4
Source File: OrientNpmUploadHandler.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Override public Content handle( final Repository repository, final File content, final String path) throws IOException { NpmHostedFacet npmFacet = repository.facet(NpmHostedFacet.class); StorageFacet storageFacet = repository.facet(StorageFacet.class); Path contentPath = content.toPath(); Payload payload = new StreamPayload(() -> new FileInputStream(content), content.length(), Files.probeContentType(contentPath)); TempBlob tempBlob = storageFacet.createTempBlob(payload, NpmFacetUtils.HASH_ALGORITHMS); final Map<String, Object> packageJson = npmPackageParser.parsePackageJson(tempBlob); ensureNpmPermitted(repository, packageJson); StorageTx tx = UnitOfWork.currentTx(); Asset asset = npmFacet.putPackage(packageJson, tempBlob); return toContent(asset, tx.requireBlob(asset.requireBlobRef())); }
Example 5
Source File: OrientNpmProxyFacet.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override protected Content store(final Context context, final Content content) throws IOException { ProxyTarget proxyTarget = context.getAttributes().require(ProxyTarget.class); if (proxyTarget.equals(ProxyTarget.SEARCH_V1_RESULTS)) { return content; // we do not cache search results } StorageFacet storageFacet = facet(StorageFacet.class); try (TempBlob tempBlob = storageFacet.createTempBlob(content, NpmFacetUtils.HASH_ALGORITHMS)) { if (ProxyTarget.PACKAGE == proxyTarget) { return putPackageRoot(packageId(matcherState(context)), tempBlob, content); } else if (ProxyTarget.DIST_TAGS == proxyTarget) { putPackageRoot(packageId(matcherState(context)), tempBlob, content); return getDistTags(packageId(matcherState(context))); } else if (ProxyTarget.TARBALL == proxyTarget) { TokenMatcher.State state = matcherState(context); return putTarball(packageId(state), tarballName(state), tempBlob, content, context); } else if (ProxyTarget.SEARCH_INDEX == proxyTarget) { Content fullIndex = putRepositoryRoot(tempBlob, content); return NpmSearchIndexFilter.filterModifiedSince( fullIndex, NpmHandlers.indexSince(context.getRequest().getParameters())); } throw new IllegalStateException(); } }
Example 6
Source File: OrientMavenGroupFacet.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
private TempBlob createTempBlob(final InputStream inputStream) { StorageFacet storageFacet = getRepository().facet(StorageFacet.class); List<HashAlgorithm> hashAlgorithms = stream(HashType.values()) .map(HashType::getHashAlgorithm) .collect(toList()); return storageFacet.createTempBlob(inputStream, hashAlgorithms); }
Example 7
Source File: AptFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override @TransactionalStoreBlob public Content put(final String path, final Payload content, final PackageInfo info) throws IOException { StorageFacet storageFacet = facet(StorageFacet.class); try (final TempBlob tempBlob = storageFacet.createTempBlob(content, FacetHelper.hashAlgorithms)) { StorageTx tx = UnitOfWork.currentTx(); Asset asset = isDebPackageContentType(path) ? findOrCreateDebAsset(tx, path, info != null ? info : new PackageInfo(AptPackageParser.getDebControlFile(tempBlob.getBlob()))) : findOrCreateMetadataAsset(tx, path); AttributesMap contentAttributes = null; if (content instanceof Content) { contentAttributes = ((Content) content).getAttributes(); } Content.applyToAsset(asset, Content.maintainLastModified(asset, contentAttributes)); AssetBlob blob = tx.setBlob( asset, path, tempBlob, FacetHelper.hashAlgorithms, null, content.getContentType(), false); tx.saveAsset(asset); return FacetHelper.toContent(asset, blob.getBlob()); } }
Example 8
Source File: ConanHostedFacet.java From nexus-repository-conan with Eclipse Public License 1.0 | 5 votes |
private void doPutArchive(final String assetPath, final ConanCoords coord, final Payload payload, final AssetKind assetKind) throws IOException { StorageFacet storageFacet = facet(StorageFacet.class); try (TempBlob tempBlob = storageFacet.createTempBlob(payload, ConanFacetUtils.HASH_ALGORITHMS)) { doPutArchive(coord, assetPath, tempBlob, assetKind); } }
Example 9
Source File: GolangProxyFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
private Content putAsset(final Content content, final String assetPath, final AssetKind assetKind) throws IOException { StorageFacet storageFacet = facet(StorageFacet.class); try (TempBlob tempBlob = storageFacet.createTempBlob(content.openInputStream(), HASH_ALGORITHMS)) { return golangDataAccess.maybeCreateAndSaveAsset(getRepository(), assetPath, assetKind, tempBlob, content ); } }
Example 10
Source File: ConanProxyFacet.java From nexus-repository-conan with Eclipse Public License 1.0 | 5 votes |
private Content putPackage(final Content content, final ConanCoords coords, final AssetKind assetKind) throws IOException { StorageFacet storageFacet = facet(StorageFacet.class); try (TempBlob tempBlob = storageFacet.createTempBlob(content.openInputStream(), HASH_ALGORITHMS)) { return doPutPackage(tempBlob, content, coords, assetKind); } }
Example 11
Source File: OrientPyPiHostedFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@TransactionalStoreBlob protected Content storeHtmlPage(final StorageTx tx, final Asset asset, final String indexPage) throws IOException { StorageFacet storageFacet = facet(StorageFacet.class); try (TempBlob tempBlob = storageFacet.createTempBlob(new StringPayload(indexPage, TEXT_HTML), HASH_ALGORITHMS)) { return saveAsset(tx, asset, tempBlob, TEXT_HTML, null); } }
Example 12
Source File: RProxyFacetImpl.java From nexus-repository-r with Eclipse Public License 1.0 | 5 votes |
private Content putMetadata(final String path, final Content content) throws IOException { StorageFacet storageFacet = facet(StorageFacet.class); try (TempBlob tempBlob = storageFacet.createTempBlob(content.openInputStream(), RFacetUtils.HASH_ALGORITHMS)) { return doPutMetadata(path, tempBlob, content); } }
Example 13
Source File: HelmProxyFacetImpl.java From nexus-repository-helm with Eclipse Public License 1.0 | 5 votes |
private Content putMetadata(final String path, final Content content, final AssetKind assetKind) throws IOException { StorageFacet storageFacet = facet(StorageFacet.class); try (TempBlob tempBlob = storageFacet.createTempBlob(content.openInputStream(), HASH_ALGORITHMS)) { try (TempBlob newTempBlob = indexYamlAbsoluteUrlRewriter.removeUrlsFromIndexYamlAndWriteToTempBlob(tempBlob, getRepository()) ) { return saveMetadataAsAsset(path, newTempBlob, content, assetKind); } } }
Example 14
Source File: GolangHostedFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
private void storeContent(final String path, final GolangAttributes golangAttributes, final Payload payload, final AssetKind assetKind) throws IOException { StorageFacet storageFacet = facet(StorageFacet.class); try (TempBlob tempBlob = storageFacet.createTempBlob(payload.openInputStream(), HASH_ALGORITHMS)) { golangDataAccess .maybeCreateAndSaveComponent(getRepository(), golangAttributes, path, tempBlob, payload, assetKind); } }
Example 15
Source File: RawContentFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override public Content put(final String path, final Payload content) throws IOException { StorageFacet storageFacet = facet(StorageFacet.class); try (TempBlob tempBlob = storageFacet.createTempBlob(content, hashAlgorithms)) { return doPutContent(path, tempBlob, content); } }
Example 16
Source File: IndexYamlBuilder.java From nexus-repository-helm with Eclipse Public License 1.0 | 4 votes |
private TempBlob createTempBlob(final InputStream inputStream, final StorageFacet storageFacet) { return storageFacet.createTempBlob(inputStream, HelmFormat.HASH_ALGORITHMS); }
Example 17
Source File: MavenUploadHandler.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
private UploadResponse doUpload(final Repository repository, final ComponentUpload componentUpload) throws IOException { MavenFacet facet = repository.facet(MavenFacet.class); StorageFacet storageFacet = repository.facet(StorageFacet.class); if (VersionPolicy.SNAPSHOT.equals(facet.getVersionPolicy())) { throw new ValidationErrorsException("Upload to snapshot repositories not supported, use the maven client."); } ContentAndAssetPathResponseData responseData; AssetUpload pomAsset = findPomAsset(componentUpload); //purposefully not using a try with resources, as this will only be used in case of an included pom file, which //isn't required TempBlob pom = null; try { if (pomAsset != null) { PartPayload payload = pomAsset.getPayload(); pom = storageFacet.createTempBlob(payload, HashType.ALGORITHMS); pomAsset.setPayload(new TempBlobPartPayload(payload, pom)); } String basePath = getBasePath(componentUpload, pom); doValidation(repository, basePath, componentUpload.getAssetUploads()); UnitOfWork.begin(storageFacet.txSupplier()); try { responseData = createAssets(repository, basePath, componentUpload.getAssetUploads()); if (isGeneratePom(componentUpload.getField(GENERATE_POM))) { String pomPath = generatePom(repository, basePath, componentUpload.getFields().get(GROUP_ID), componentUpload.getFields().get(ARTIFACT_ID), componentUpload.getFields().get(VERSION), componentUpload.getFields().get(PACKAGING)); responseData.addAssetPath(pomPath); } updateMetadata(repository, responseData.coordinates); } finally { UnitOfWork.end(); } return new UploadResponse(responseData.getContent(), responseData.getAssetPaths()); } finally { if (pom != null) { pom.close(); } } }
Example 18
Source File: HelmUploadHandler.java From nexus-repository-helm with Eclipse Public License 1.0 | 4 votes |
@Override public UploadResponse handle(Repository repository, ComponentUpload upload) throws IOException { HelmHostedFacet facet = repository.facet(HelmHostedFacet.class); StorageFacet storageFacet = repository.facet(StorageFacet.class); PartPayload payload = upload.getAssetUploads().get(0).getPayload(); String fileName = payload.getName() != null ? payload.getName() : StringUtils.EMPTY; AssetKind assetKind = AssetKind.getAssetKindByFileName(fileName); if (assetKind != AssetKind.HELM_PROVENANCE && assetKind != AssetKind.HELM_PACKAGE) { throw new IllegalArgumentException("Unsupported extension. Extension must be .tgz or .tgz.prov"); } try (TempBlob tempBlob = storageFacet.createTempBlob(payload, HASH_ALGORITHMS)) { HelmAttributes attributesFromInputStream = helmPackageParser.getAttributes(assetKind, tempBlob.get()); String extension = assetKind.getExtension(); String name = attributesFromInputStream.getName(); String version = attributesFromInputStream.getVersion(); if (StringUtils.isBlank(name)) { throw new ValidationErrorsException("Metadata is missing the name attribute"); } if (StringUtils.isBlank(version)) { throw new ValidationErrorsException("Metadata is missing the version attribute"); } String path = String.format("%s-%s%s", name, version, extension); ensurePermitted(repository.getName(), NAME, path, Collections.emptyMap()); try { UnitOfWork.begin(storageFacet.txSupplier()); Asset asset = facet.upload(path, tempBlob, payload, assetKind); return new UploadResponse(asset); } finally { UnitOfWork.end(); } } }
Example 19
Source File: OrientPyPiHostedHandlers.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
private TempBlobPartPayload createBlobFromPayload( final PartPayload payload, final Repository repository) throws IOException { StorageFacet storageFacet = repository.facet(StorageFacet.class); return new TempBlobPartPayload(payload, storageFacet.createTempBlob(payload, HASH_ALGORITHMS)); }
Example 20
Source File: P2ProxyFacetImpl.java From nexus-repository-p2 with Eclipse Public License 1.0 | 4 votes |
private Content putMetadata(final String path, final Content content, final AssetKind assetKind) throws IOException { StorageFacet storageFacet = facet(StorageFacet.class); try (TempBlob tempBlob = storageFacet.createTempBlob(content.openInputStream(), HASH_ALGORITHMS)) { return removeMirrorUrlFromArtifactsAndSaveMetadataAsAsset(path, tempBlob, content, assetKind); } }