Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Fix URL constructor deprecation warning (#2961)

Wouter Borna4255b6e28e9
diff --git a/container/src/main/java/org/openremote/container/web/RealmPathExtractorFilter.java b/container/src/main/java/org/openremote/container/web/RealmPathExtractorFilter.java
index 683f7b73a..0af6b8767 100644
--- a/container/src/main/java/org/openremote/container/web/RealmPathExtractorFilter.java
+++ b/container/src/main/java/org/openremote/container/web/RealmPathExtractorFilter.java
@@ -27,6 +27,8 @@ import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.*;
@@ -129,11 +131,11 @@ public class RealmPathExtractorFilter implements Filter {
// Rebuild from original URL but swap path. Keep scheme/host/port.
StringBuffer original = super.getRequestURL();
try {
- URL url = new URL(original.toString());
+ URL url = new URI(original.toString()).toURL();
int port = url.getPort();
String authority = port == -1 ? url.getHost() : (url.getHost() + ":" + port);
return new StringBuffer(url.getProtocol() + "://" + authority + getRequestURI());
- } catch (MalformedURLException ex) {
+ } catch (MalformedURLException | URISyntaxException ex) {
// Fallback: best-effort
return new StringBuffer(original.substring(0, original.indexOf(super.getRequestURI())) + getRequestURI());
}