Skip to content

Commit

Permalink
Merge pull request #106 from ligangty/main
Browse files Browse the repository at this point in the history
Wrap the diagnostics bundle file content with StreamOutput
  • Loading branch information
ligangty authored Nov 27, 2023
2 parents 5a805f0 + 38477f1 commit 29e1192
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.commonjava.indy.service.ui.jaxrs.diag;

import org.apache.commons.io.IOUtils;
import org.commonjava.indy.service.ui.client.diag.DiagnosticsServiceClient;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
Expand All @@ -27,6 +28,9 @@
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;

import java.io.InputStream;

import static javax.ws.rs.core.MediaType.TEXT_PLAIN;

Expand Down Expand Up @@ -60,7 +64,7 @@ public Response getThreadDump()
@Produces( "application/zip" )
public Response getBundle()
{
return client.getBundle();
return streamBinContent( client.getBundle() );
}

@Operation( description = "Retrieve a ZIP-compressed file containing all repository definitions." )
Expand All @@ -71,7 +75,14 @@ public Response getBundle()
@Produces( "application/zip" )
public Response getRepoBundle()
{
return client.getRepoBundle();
return streamBinContent( client.getRepoBundle() );
}

private Response streamBinContent( final Response response )
{
final InputStream clientIn = response.readEntity( InputStream.class );
StreamingOutput out = output -> IOUtils.copy( clientIn, output );
return Response.status( response.getStatus() ).entity( out ).replaceAll( response.getHeaders() ).build();
}

}

0 comments on commit 29e1192

Please sign in to comment.