From 34cf0ef9728a942929bc2dce7a03b331f13fc18a Mon Sep 17 00:00:00 2001 From: Gang Li Date: Tue, 7 Nov 2023 17:53:57 +0800 Subject: [PATCH 1/2] Fix the malform content for maven content retrieving When do content retrieving from backend content fetch API by JAXRS Rest client, if we do direct send back of the reponse with no change, it will cause malformed content. Not sure why this happen. This fix will re-wrap the content stream as StremingOutput. --- .../content/MavenContentAccessResource.java | 28 ++++++------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/commonjava/indy/service/ui/jaxrs/content/MavenContentAccessResource.java b/src/main/java/org/commonjava/indy/service/ui/jaxrs/content/MavenContentAccessResource.java index 587e7df..0b932cf 100644 --- a/src/main/java/org/commonjava/indy/service/ui/jaxrs/content/MavenContentAccessResource.java +++ b/src/main/java/org/commonjava/indy/service/ui/jaxrs/content/MavenContentAccessResource.java @@ -15,6 +15,7 @@ */ package org.commonjava.indy.service.ui.jaxrs.content; +import org.apache.commons.io.IOUtils; import org.commonjava.indy.service.ui.client.content.MavenContentAccessServiceClient; import org.commonjava.indy.service.ui.models.repository.StoreType; import org.eclipse.microprofile.openapi.annotations.Operation; @@ -37,14 +38,13 @@ import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; import javax.ws.rs.core.StreamingOutput; import javax.ws.rs.core.UriInfo; +import java.io.InputStream; -import static javax.ws.rs.core.MediaType.MEDIA_TYPE_WILDCARD; import static org.commonjava.indy.service.ui.client.Constants.CHECK_CACHE_ONLY; import static org.eclipse.microprofile.openapi.annotations.enums.ParameterIn.PATH; import static org.eclipse.microprofile.openapi.annotations.enums.ParameterIn.QUERY; @@ -60,9 +60,6 @@ public class MavenContentAccessResource @RestClient MavenContentAccessServiceClient client; - // @Inject - // ContentBrowseReGenClient browseClient; - @Operation( description = "Store Maven artifact content under the given artifact store (type/name) and path." ) @Parameters( { @Parameter( name = "type", in = PATH, description = "The type of the repository.", content = @Content( schema = @Schema( implementation = StoreType.class ) ), @@ -135,29 +132,23 @@ public Response doHead( final @PathParam( "type" ) String type, final @PathParam description = "Rendered content listing (when path ends with '/index.html' or '/') or Content stream" ) } ) @GET @Path( "/{path: (.*)}" ) - @Produces( MEDIA_TYPE_WILDCARD ) public Response doGet( final @PathParam( "type" ) String type, final @PathParam( "name" ) String name, final @PathParam( "path" ) String path, @Context final UriInfo uriInfo, @Context final HttpServletRequest request ) { - // Response response = client.doGet( type, name, path, uriInfo, request ); - // - // Response.ResponseBuilder builder = Response.ok(response.getEntity()); - // response.getHeaders().forEach( builder::header ); - // builder.header( CONTENT_TYPE, TEXT_XML ); - // - // return builder.build(); - // System.out.println(response.getHeaders()); - // return response; if ( uriInfo.getAbsolutePath().toString().trim().endsWith( "/" ) ) { - // return browseClient.browseDirectory( PackageTypeConstants.PKG_TYPE_MAVEN, type, name, path, uriInfo ); return Response.seeOther( uriInfo.getBaseUriBuilder().path( "browse/maven" ).path( type ).path( name ).path( path ).build() ) .build(); } - - return client.doGet( type, name, path, uriInfo, request ); + // When direct send back the origin Response from client, not sure why it will cause encoding issue which will + // send back the malformed content. So here we re-wrapped the original response content from client to a streamed + // content. + final Response response = client.doGet( type, name, path, uriInfo, request ); + 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(); } @Operation( description = "Retrieve root listing under the given artifact store (type/name)." ) @@ -178,7 +169,6 @@ public Response doGet( final @PathParam( "type" ) String type, final @PathParam( public Response doGet( final @PathParam( "type" ) String type, final @PathParam( "name" ) String name, @Context final UriInfo uriInfo, @Context final HttpServletRequest request ) { - // return browseClient.browseRoot( PackageTypeConstants.PKG_TYPE_MAVEN, type, name, uriInfo ); return Response.seeOther( uriInfo.getBaseUriBuilder().path( "browse/maven" ).path( type ).path( name ).build() ) .build(); } From 53da3c437d561e8b92c08a519bbb8c393a161f5f Mon Sep 17 00:00:00 2001 From: Gang Li Date: Wed, 8 Nov 2023 10:06:32 +0800 Subject: [PATCH 2/2] Some update for webpack build --- src/main/webui/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/webui/package.json b/src/main/webui/package.json index 6ef456e..5664bc8 100644 --- a/src/main/webui/package.json +++ b/src/main/webui/package.json @@ -49,8 +49,8 @@ "build-dev": "npm run clean && npm run compile-dev && npm run test && npm run deploy && cp ./src/content-browse/html/* ./dist/content-browse/", "build": "npm run clean && npm run compile && npm run test && npm run deploy && cp ./src/content-browse/html/* ./dist/content-browse/", "clean": "rm -rf ./dist/*", - "compile-dev": "NODE_ENV=development webpack --config ./webpack.config.js --progress && webpack --config ./webpack-content-browse.dev.config.js --progress", - "compile": "NODE_ENV=production webpack --config ./webpack.config-prod.js --progress && webpack --config ./webpack-content-browse.prod.config.js --progress", + "compile-dev": "NODE_ENV=development webpack --config ./webpack.config.js && webpack --config ./webpack-content-browse.dev.config.js", + "compile": "NODE_ENV=production webpack --config ./webpack.config-prod.js && webpack --config ./webpack-content-browse.prod.config.js", "deploy": "cp -r ./src/app/html/* ./dist/", "dev": "webpack-dev-server --open --hot", "lint": "eslint './src/**'",