Skip to content

bitmag-1243-upgrade-java#84

Open
Knud-Aage wants to merge 8 commits intomasterfrom
bitmag-1243-upgrade-java
Open

bitmag-1243-upgrade-java#84
Knud-Aage wants to merge 8 commits intomasterfrom
bitmag-1243-upgrade-java

Conversation

@Knud-Aage
Copy link
Copy Markdown
Contributor

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.

…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
@Knud-Aage Knud-Aage requested review from Thommelise and ole-v-v April 28, 2026 11:34
messageBus.close();
// TODO Kill any lingering timer threads
} catch (JMSException e) {
} catch (jakarta.jms.JMSException e) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps nit-picking, for my part I would prefer an import over using the fully qualified name here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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();
Copy link
Copy Markdown
Contributor

@ole-v-v ole-v-v Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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");
Copy link
Copy Markdown
Contributor

@ole-v-v ole-v-v Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted the lines

import org.bitrepository.bitrepositorymessages.Message;
import org.bitrepository.protocol.MessageContext;
import org.bitrepository.protocol.messagebus.MessageListener;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might have wanted to keep this empty line since it separate the import of out own classes from those of JUnit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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("\\", "/");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is because setDirectoriesListed is deprecated.

Comment on lines -64 to +63
resource_handler.setResourceBase(httpServerDir.getPath());
resource_handler.setBaseResource(ResourceFactory.root().newResource(httpServerDir.toPath()));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here, which advantage is this change giving us?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elegant.

URL uploadUrl = new URL(fileAddress);
FileExchange fileExchange = FileExchangeResolver.getBasicFileExchangeFromURL(uploadUrl);
fileExchange.putFile(is, uploadUrl);
final URI uploadUri = URI.create(fileAddress);
Copy link
Copy Markdown
Contributor

@ole-v-v ole-v-v May 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use constructor? (And if so, add any exceptions from it to the catch clause below.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

try {
File fileToUpload = createAuditTrailFile(message, extractedAuditTrails);
URL uploadUrl = new URL(message.getResultAddress());
URI uploadUri = new URI(message.getResultAddress());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May convert to URL at once?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Knud-Aage Knud-Aage requested a review from Asger-KB May 7, 2026 09:31
output.error("Issue regarding removing file from server: " + e.getMessage());
}
}
} }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, lines inadvertently joined.

Comment on lines -351 to -352
// Test if URL can actually be opened to exit early
// - otherwise checksum pillars will still receive and store checksum.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn’t the comment fine and helpful?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants