Skip to content

Commit

Permalink
fix: do not remove GenericUrlResolver from PolarionUrlResolver single…
Browse files Browse the repository at this point in the history
…ton (#229)

Refs: #228
  • Loading branch information
grigoriev authored Sep 25, 2024
1 parent fcbaaac commit a409e33
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
3 changes: 0 additions & 3 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1478,9 +1478,6 @@
"type": "string"
}
},
"required": [
"documentType"
],
"type": "object"
},
"FormDataBodyPart": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class PdfExporterFileResourceProvider implements FileResourceProvider {
private final List<IUrlResolver> resolvers;

public PdfExporterFileResourceProvider() {
this.resolvers = Arrays.asList(removeGenericUrlResolver(PolarionUrlResolver.getInstance()), new CustomResourceUrlResolver());
this.resolvers = Arrays.asList(getPolarionUrlResolverWithoutGenericUrlChildResolver(), new CustomResourceUrlResolver());
}

@VisibleForTesting
Expand Down Expand Up @@ -105,13 +105,21 @@ public byte[] processPossibleSvgImage(byte[] possibleSvgImageBytes) {
* Remove GenericUrlResolver because it has no explicit timeouts declared
*/
@SneakyThrows
private IUrlResolver removeGenericUrlResolver(IAttachmentUrlResolver urlResolver) {
if (urlResolver instanceof ParentUrlResolver parentUrlResolver) {
private IAttachmentUrlResolver getPolarionUrlResolverWithoutGenericUrlChildResolver() {
IAttachmentUrlResolver attachmentUrlResolver = PolarionUrlResolver.getInstance();

if (attachmentUrlResolver instanceof ParentUrlResolver parentUrlResolver) {
Field childResolversField = ParentUrlResolver.class.getDeclaredField("childResolvers");
childResolversField.setAccessible(true);
((List<?>) childResolversField.get(parentUrlResolver)).removeIf(resolver -> resolver instanceof GenericUrlResolver);

@SuppressWarnings("unchecked")
List<IUrlResolver> childResolvers = ((List<IUrlResolver>) childResolversField.get(parentUrlResolver)).stream()
.filter(resolver -> !(resolver instanceof GenericUrlResolver))
.toList();

return new ParentUrlResolver(childResolvers);
}
return urlResolver;

return attachmentUrlResolver;
}
}

0 comments on commit a409e33

Please sign in to comment.