Conversation
…e were some other minor changes like URL to URI.toURL.
…-java # Conflicts: # bitrepository-alarm-service/src/main/java/org/bitrepository/alarm/BasicAlarmService.java # bitrepository-audit-trail-service/src/main/java/org/bitrepository/audittrails/AuditTrailService.java # bitrepository-core/src/test/java/org/bitrepository/common/settings/SettingsLoaderTest.java # bitrepository-core/src/test/java/org/bitrepository/protocol/fileexchange/LocalFileExchangeTest.java # bitrepository-core/src/test/java/org/bitrepository/protocol/http/HttpFileExchangeTest.java # bitrepository-core/src/test/java/org/bitrepository/protocol/utils/FileExchangeResolverTest.java # bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/store/ChecksumStorageModel.java
| messageBus.close(); | ||
| // TODO Kill any lingering timer threads | ||
| } catch (JMSException e) { | ||
| } catch (jakarta.jms.JMSException e) { |
There was a problem hiding this comment.
Perhaps nit-picking, for my part I would prefer an import over using the fully qualified name here.
| URI baseURI = new URI(settings.getProtocolType().value(), null, settings.getServerName(), | ||
| settings.getPort().intValue(), path, null, null); | ||
| // Then append the manually encoded filename. toASCIIString() ensures we don't double-encode. | ||
| return baseURI.resolve(encodedFilename).toURL(); |
There was a problem hiding this comment.
As far as I have been able to tell, resolve() throws away the path and replaces it with the encoded filename that we pass. If this is correct, we will have to concatenate path and file name manually as in the old code.
There was a problem hiding this comment.
Kept the replacement and avoided the resolve
| // However, it does NOT encode characters like '+' if they are part of the path segment, as they are technically allowed. | ||
| // But the existing tests and many WebDAV servers expect '+' to be encoded as %2B in the filename. | ||
| // Therefore, we manually encode the filename and then construct the full URI. | ||
| String encodedFilename = URLEncoder.encode(filename, StandardCharsets.UTF_8).replace("+", "%20"); |
There was a problem hiding this comment.
It seems to me that .replace("+", "%20") is superfluous? Encoding a space a + is very standard, so WebDAV servers should expect it that way? Also I didn’t find any failing test when I left it out?
I can confirm that the URI#URI(String, String, String, int, String, String, String) constructor keeps a + in the path unchanged.
| import org.bitrepository.bitrepositorymessages.Message; | ||
| import org.bitrepository.protocol.MessageContext; | ||
| import org.bitrepository.protocol.messagebus.MessageListener; | ||
|
|
There was a problem hiding this comment.
We might have wanted to keep this empty line since it separate the import of out own classes from those of JUnit.
There was a problem hiding this comment.
A stupid intellij reformatiitng rule makes it that way
| String path = getHttpServerPath() + "/" + filename; | ||
| String scheme = getProtocol().toLowerCase(); | ||
| if (getHttpServerName() == null) { | ||
| String absolutePath = Paths.get(path).toAbsolutePath().normalize().toString().replace("\\", "/"); |
There was a problem hiding this comment.
If we want or need to take running on a Windows computer into account (which makes sense), shouldn’t we then also use the platform specific path separator when concatenating getHttpServerPath() and filename above? Asked without being sure what the bullet-proof solution is.
There was a problem hiding this comment.
Changed to a version that hopefully works on both windows and linux
|
|
||
| ResourceHandler resource_handler = new ResourceHandler(); | ||
| resource_handler.setDirectoriesListed(true); | ||
| resource_handler.setDirAllowed(true); |
There was a problem hiding this comment.
Why this change? The way I read the docs (without really understanding), these are two different methods, so I had not expected them to be interchangeable??
There was a problem hiding this comment.
It is because setDirectoriesListed is deprecated.
| resource_handler.setResourceBase(httpServerDir.getPath()); | ||
| resource_handler.setBaseResource(ResourceFactory.root().newResource(httpServerDir.toPath())); |
There was a problem hiding this comment.
Same question here, which advantage is this change giving us?
There was a problem hiding this comment.
It is because of deprecation
|
|
||
| HandlerList handlers = new HandlerList(); | ||
| handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() }); | ||
| Handler.Sequence handlers = new Handler.Sequence(resource_handler, new DefaultHandler()); |
| URL uploadUrl = new URL(fileAddress); | ||
| FileExchange fileExchange = FileExchangeResolver.getBasicFileExchangeFromURL(uploadUrl); | ||
| fileExchange.putFile(is, uploadUrl); | ||
| final URI uploadUri = URI.create(fileAddress); |
There was a problem hiding this comment.
Use constructor? (And if so, add any exceptions from it to the catch clause below.)
| try { | ||
| File fileToUpload = createAuditTrailFile(message, extractedAuditTrails); | ||
| URL uploadUrl = new URL(message.getResultAddress()); | ||
| URI uploadUri = new URI(message.getResultAddress()); |
There was a problem hiding this comment.
May convert to URL at once?
| output.error("Issue regarding removing file from server: " + e.getMessage()); | ||
| } | ||
| } | ||
| } } |
There was a problem hiding this comment.
Oops, lines inadvertently joined.
| // Test if URL can actually be opened to exit early | ||
| // - otherwise checksum pillars will still receive and store checksum. |
There was a problem hiding this comment.
Wasn’t the comment fine and helpful?
Upgrading to java 21 resolves all vulnerabilities in pom.xml for all modules. There were some changes necessary primarily because of deprecated methods, but there weren't many.