Search in sources :

Example 1 with StoreHttpExchangeMetadata

use of org.commonjava.indy.core.model.StoreHttpExchangeMetadata in project indy by Commonjava.

the class NPMContentAccessHandler method generateHttpMetadataHeaders.

private void generateHttpMetadataHeaders(final Transfer transfer, final List<Transfer> generated, final HttpServletRequest request, final Response response) {
    if (transfer == null || !transfer.exists() || request == null || response == null) {
        return;
    }
    Response customizedResponse = Response.fromResponse(response).header(ApplicationHeader.content_length.upperKey(), transfer.length()).header(ApplicationHeader.indy_origin.upperKey(), null).header(ApplicationHeader.transfer_encoding.upperKey(), null).lastModified(new Date(transfer.lastModified())).build();
    Transfer metaTxfr = transfer.getSiblingMeta(HttpExchangeMetadata.FILE_EXTENSION);
    if (metaTxfr == null) {
        if (transfer.isDirectory()) {
            metaTxfr = transfer.getChild(HttpExchangeMetadata.FILE_EXTENSION);
        } else {
            return;
        }
    }
    final HttpExchangeMetadata metadata = new StoreHttpExchangeMetadata(request, customizedResponse);
    try (OutputStream out = metaTxfr.openOutputStream(TransferOperation.GENERATE, false)) {
        if (out != null) {
            out.write(mapper.writeValueAsBytes(metadata));
        }
    } catch (final IOException e) {
        logger.error("Failed to write metadata for HTTP exchange to: {}. Reason: {}", metaTxfr, e);
    }
    if (generated == null) {
        return;
    }
    for (Transfer t : generated) {
        generateHttpMetadataHeaders(t, request, response);
    }
}
Also used : Response(javax.ws.rs.core.Response) StoreHttpExchangeMetadata(org.commonjava.indy.core.model.StoreHttpExchangeMetadata) OutputStream(java.io.OutputStream) Transfer(org.commonjava.maven.galley.model.Transfer) IOException(java.io.IOException) StoreHttpExchangeMetadata(org.commonjava.indy.core.model.StoreHttpExchangeMetadata) HttpExchangeMetadata(org.commonjava.maven.galley.transport.htcli.model.HttpExchangeMetadata) Date(java.util.Date)

Aggregations

IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Date (java.util.Date)1 Response (javax.ws.rs.core.Response)1 StoreHttpExchangeMetadata (org.commonjava.indy.core.model.StoreHttpExchangeMetadata)1 Transfer (org.commonjava.maven.galley.model.Transfer)1 HttpExchangeMetadata (org.commonjava.maven.galley.transport.htcli.model.HttpExchangeMetadata)1