Search in sources :

Example 1 with TransferCountingInputStream

use of org.commonjava.indy.core.bind.jaxrs.util.TransferCountingInputStream in project indy by Commonjava.

the class ContentAccessHandler method doCreate.

public Response doCreate(final String packageType, final String type, final String name, final String path, final HttpServletRequest request, EventMetadata eventMetadata, final Supplier<URI> uriBuilder, final Consumer<ResponseBuilder> builderModifier) {
    setContext(PACKAGE_TYPE, packageType);
    setContext(PATH, path);
    final StoreType st = StoreType.get(type);
    StoreKey sk = new StoreKey(packageType, st, name);
    eventMetadata = eventMetadata.set(ContentManager.ENTRY_POINT_STORE, sk);
    setContext(CONTENT_ENTRY_POINT, sk.toString());
    Response response;
    final Transfer transfer;
    try {
        TransferCountingInputStream streamingInputStream = new TransferCountingInputStream(request.getInputStream(), metricsManager, metricsConfig);
        transfer = contentController.store(sk, path, streamingInputStream, eventMetadata);
        addFieldToActiveSpan(TRANSFER_SIZE, transfer.length());
        final StoreKey storageKey = LocationUtils.getKey(transfer);
        logger.info("Key for storage location: {}", storageKey);
        final URI uri = uriBuilder.get();
        setContext(HTTP_STATUS, String.valueOf(201));
        ResponseBuilder builder = Response.created(uri);
        if (builderModifier != null) {
            builderModifier.accept(builder);
        }
        response = builder.build();
    } catch (final IndyWorkflowException | IOException e) {
        logger.error(String.format("Failed to upload: %s to: %s. Reason: %s", path, name, e.getMessage()), e);
        response = responseHelper.formatResponse(e, builderModifier);
    }
    return response;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) Response(javax.ws.rs.core.Response) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) IOException(java.io.IOException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) StoreKey(org.commonjava.indy.model.core.StoreKey) URI(java.net.URI) TransferCountingInputStream(org.commonjava.indy.core.bind.jaxrs.util.TransferCountingInputStream)

Aggregations

IOException (java.io.IOException)1 URI (java.net.URI)1 Response (javax.ws.rs.core.Response)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)1 TransferCountingInputStream (org.commonjava.indy.core.bind.jaxrs.util.TransferCountingInputStream)1 StoreKey (org.commonjava.indy.model.core.StoreKey)1 StoreType (org.commonjava.indy.model.core.StoreType)1 Transfer (org.commonjava.maven.galley.model.Transfer)1