Source:
private void writeMetadata( final Transfer target, final ObjectMapper mapper, final Map<String, List<String>> requestHeaders ) { Timer.Context writeTimer = metricRegistry == null ? null : metricRegistry.timer( HTTP_METADATA_WRITE ).time(); try { Transfer metaTxfr = target.getSiblingMeta( FILE_EXTENSION ); if ( metaTxfr == null ) { if ( target.isDirectory() ) { logger.trace( "DIRECTORY. Using HTTP exchange metadata file INSIDE directory called: {}", FILE_EXTENSION ); metaTxfr = target.getChild( FILE_EXTENSION ); } else { logger.trace( "SKIP: Cannot retrieve HTTP exchange metadata Transfer instance for: {}", target ); return; } } final HttpExchangeMetadata metadata = new HttpExchangeMetadataFromRequestHeader( requestHeaders ); final Transfer finalMeta = metaTxfr; Timer.Context openTimer = metricRegistry == null ? null : metricRegistry.timer( HTTP_METADATA_WRITE ).time(); try(OutputStream out = metaTxfr.openOutputStream( TransferOperation.GENERATE, false ) ) { openTimer.stop(); logger.trace( "Writing HTTP exchange metadata:\n\n{}\n\n", new Object() { @Override public String toString() { try { return mapper.writeValueAsString( metadata ); } catch ( final JsonProcessingException e ) { logger.warn( String.format("Failed to write HTTP exchange metadata: %s. Reason: %s", finalMeta, e.getMessage()), e ); } return "ERROR RENDERING METADATA"; } } ); mapper.writeValue( out, metadata ); } catch ( final IOException e ) { if ( logger.isTraceEnabled() ) { logger.trace( String.format( "Failed to write metadata for HTTP exchange to: %s. Reason: %s", metaTxfr, e.getMessage() ), e ); } else { logger.warn( "Failed to write metadata for HTTP exchange to: {}. Reason: {}", metaTxfr, e.getMessage() ); } } } finally { if ( writeTimer != null ) { writeTimer.stop(); } } }

Target:
private void writeMetadata( final Transfer target, final ObjectMapper mapper, final Map<String, List<String>> requestHeaders ) { Timer.Context writeTimer = timerProvider.apply( HTTP_METADATA_WRITE ); logger.debug( "http-metadata write-timer is: {}", writeTimer ); try { Transfer metaTxfr = target.getSiblingMeta( FILE_EXTENSION ); if ( metaTxfr == null ) { if ( target.isDirectory() ) { logger.trace( "DIRECTORY. Using HTTP exchange metadata file INSIDE directory called: {}", FILE_EXTENSION ); metaTxfr = target.getChild( FILE_EXTENSION ); } else { logger.trace( "SKIP: Cannot retrieve HTTP exchange metadata Transfer instance for: {}", target ); return; } } final HttpExchangeMetadata metadata = new HttpExchangeMetadataFromRequestHeader( requestHeaders ); final Transfer finalMeta = metaTxfr; Timer.Context openTimer = timerProvider.apply( HTTP_METADATA_WRITE_OPEN ); logger.debug( "http-metadata open-timer is: {}", openTimer ); try(OutputStream out = metaTxfr.openOutputStream( TransferOperation.GENERATE, false ) ) { if ( openTimer != null ) { openTimer.stop(); } logger.trace( "Writing HTTP exchange metadata:\n\n{}\n\n", new Object() { @Override public String toString() { try { return mapper.writeValueAsString( metadata ); } catch ( final JsonProcessingException e ) { logger.warn( String.format("Failed to write HTTP exchange metadata: %s. Reason: %s", finalMeta, e.getMessage()), e ); } return "ERROR RENDERING METADATA"; } } ); mapper.writeValue( out, metadata ); } catch ( final IOException e ) { if ( logger.isTraceEnabled() ) { logger.trace( String.format( "Failed to write metadata for HTTP exchange to: %s. Reason: %s", metaTxfr, e.getMessage() ), e ); } else { logger.warn( "Failed to write metadata for HTTP exchange to: {}. Reason: {}", metaTxfr, e.getMessage() ); } } } finally { if ( writeTimer != null ) { writeTimer.stop(); } } }