Remove calls to deprecated URL constructor (#4551)
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>pull/4558/head
parent
229d87263f
commit
9ad83bada4
|
@ -12,13 +12,13 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.core.addon.marketplace.karaf.internal.community;
|
package org.openhab.core.addon.marketplace.karaf.internal.community;
|
||||||
|
|
||||||
import static org.openhab.core.addon.marketplace.MarketplaceConstants.KAR_CONTENT_TYPE;
|
import static org.openhab.core.addon.marketplace.MarketplaceConstants.*;
|
||||||
import static org.openhab.core.addon.marketplace.MarketplaceConstants.KAR_DOWNLOAD_URL_PROPERTY;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
@ -108,13 +108,14 @@ public class CommunityKarafAddonHandler implements MarketplaceAddonHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void install(Addon addon) throws MarketplaceHandlerException {
|
public void install(Addon addon) throws MarketplaceHandlerException {
|
||||||
|
URL sourceUrl;
|
||||||
try {
|
try {
|
||||||
URL sourceUrl = new URL((String) addon.getProperties().get(KAR_DOWNLOAD_URL_PROPERTY));
|
sourceUrl = (new URI((String) addon.getProperties().get(KAR_DOWNLOAD_URL_PROPERTY))).toURL();
|
||||||
addKarToCache(addon.getUid(), sourceUrl);
|
} catch (IllegalArgumentException | MalformedURLException | URISyntaxException e) {
|
||||||
installFromCache(addon.getUid());
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
throw new MarketplaceHandlerException("Malformed source URL: " + e.getMessage(), e);
|
throw new MarketplaceHandlerException("Malformed source URL: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
addKarToCache(addon.getUid(), sourceUrl);
|
||||||
|
installFromCache(addon.getUid());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -12,12 +12,13 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.core.addon.marketplace.internal.community;
|
package org.openhab.core.addon.marketplace.internal.community;
|
||||||
|
|
||||||
import static org.openhab.core.addon.marketplace.MarketplaceConstants.BLOCKLIBRARIES_CONTENT_TYPE;
|
import static org.openhab.core.addon.marketplace.MarketplaceConstants.*;
|
||||||
import static org.openhab.core.addon.marketplace.MarketplaceConstants.YAML_DOWNLOAD_URL_PROPERTY;
|
|
||||||
import static org.openhab.core.addon.marketplace.internal.community.CommunityMarketplaceAddonService.YAML_CONTENT_PROPERTY;
|
import static org.openhab.core.addon.marketplace.internal.community.CommunityMarketplaceAddonService.YAML_CONTENT_PROPERTY;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
@ -102,7 +103,12 @@ public class CommunityBlockLibaryAddonHandler implements MarketplaceAddonHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getWidgetFromURL(String urlString) throws IOException {
|
private String getWidgetFromURL(String urlString) throws IOException {
|
||||||
URL u = new URL(urlString);
|
URL u;
|
||||||
|
try {
|
||||||
|
u = (new URI(urlString)).toURL();
|
||||||
|
} catch (IllegalArgumentException | URISyntaxException e) {
|
||||||
|
throw new IOException(e);
|
||||||
|
}
|
||||||
try (InputStream in = u.openStream()) {
|
try (InputStream in = u.openStream()) {
|
||||||
return new String(in.readAllBytes(), StandardCharsets.UTF_8);
|
return new String(in.readAllBytes(), StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,10 +12,11 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.core.addon.marketplace.internal.community;
|
package org.openhab.core.addon.marketplace.internal.community;
|
||||||
|
|
||||||
import static org.openhab.core.addon.marketplace.MarketplaceConstants.JAR_CONTENT_TYPE;
|
import static org.openhab.core.addon.marketplace.MarketplaceConstants.*;
|
||||||
import static org.openhab.core.addon.marketplace.MarketplaceConstants.JAR_DOWNLOAD_URL_PROPERTY;
|
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
@ -73,13 +74,14 @@ public class CommunityBundleAddonHandler extends MarketplaceBundleInstaller impl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void install(Addon addon) throws MarketplaceHandlerException {
|
public void install(Addon addon) throws MarketplaceHandlerException {
|
||||||
|
URL sourceUrl;
|
||||||
try {
|
try {
|
||||||
URL sourceUrl = new URL((String) addon.getProperties().get(JAR_DOWNLOAD_URL_PROPERTY));
|
sourceUrl = (new URI((String) addon.getProperties().get(JAR_DOWNLOAD_URL_PROPERTY))).toURL();
|
||||||
addBundleToCache(addon.getUid(), sourceUrl);
|
} catch (IllegalArgumentException | MalformedURLException | URISyntaxException e) {
|
||||||
installFromCache(bundleContext, addon.getUid());
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
throw new MarketplaceHandlerException("Malformed source URL: " + e.getMessage(), e);
|
throw new MarketplaceHandlerException("Malformed source URL: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
addBundleToCache(addon.getUid(), sourceUrl);
|
||||||
|
installFromCache(bundleContext, addon.getUid());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -163,7 +163,7 @@ public class CommunityMarketplaceAddonService extends AbstractRemoteAddonService
|
||||||
try {
|
try {
|
||||||
List<DiscourseCategoryResponseDTO> pages = new ArrayList<>();
|
List<DiscourseCategoryResponseDTO> pages = new ArrayList<>();
|
||||||
|
|
||||||
URL url = new URL(COMMUNITY_MARKETPLACE_URL);
|
URL url = URI.create(COMMUNITY_MARKETPLACE_URL).toURL();
|
||||||
int pageNb = 1;
|
int pageNb = 1;
|
||||||
while (url != null) {
|
while (url != null) {
|
||||||
URLConnection connection = url.openConnection();
|
URLConnection connection = url.openConnection();
|
||||||
|
@ -180,7 +180,7 @@ public class CommunityMarketplaceAddonService extends AbstractRemoteAddonService
|
||||||
|
|
||||||
if (parsed.topicList.moreTopicsUrl != null) {
|
if (parsed.topicList.moreTopicsUrl != null) {
|
||||||
// Discourse URL for next page is wrong
|
// Discourse URL for next page is wrong
|
||||||
url = new URL(COMMUNITY_MARKETPLACE_URL + "?page=" + pageNb++);
|
url = URI.create(COMMUNITY_MARKETPLACE_URL + "?page=" + pageNb++).toURL();
|
||||||
} else {
|
} else {
|
||||||
url = null;
|
url = null;
|
||||||
}
|
}
|
||||||
|
@ -215,7 +215,7 @@ public class CommunityMarketplaceAddonService extends AbstractRemoteAddonService
|
||||||
|
|
||||||
// retrieve from remote
|
// retrieve from remote
|
||||||
try {
|
try {
|
||||||
URL url = new URL(String.format("%s%s", COMMUNITY_TOPIC_URL, uid.replace(ADDON_ID_PREFIX, "")));
|
URL url = URI.create(COMMUNITY_TOPIC_URL + uid.replace(ADDON_ID_PREFIX, "")).toURL();
|
||||||
URLConnection connection = url.openConnection();
|
URLConnection connection = url.openConnection();
|
||||||
connection.addRequestProperty("Accept", "application/json");
|
connection.addRequestProperty("Accept", "application/json");
|
||||||
if (this.apiKey != null) {
|
if (this.apiKey != null) {
|
||||||
|
|
|
@ -17,6 +17,8 @@ import static org.openhab.core.addon.marketplace.internal.community.CommunityMar
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
@ -99,7 +101,12 @@ public class CommunityRuleTemplateAddonHandler implements MarketplaceAddonHandle
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getTemplateFromURL(String urlString) throws IOException {
|
private String getTemplateFromURL(String urlString) throws IOException {
|
||||||
URL u = new URL(urlString);
|
URL u;
|
||||||
|
try {
|
||||||
|
u = (new URI(urlString)).toURL();
|
||||||
|
} catch (IllegalArgumentException | URISyntaxException e) {
|
||||||
|
throw new IOException(e);
|
||||||
|
}
|
||||||
try (InputStream in = u.openStream()) {
|
try (InputStream in = u.openStream()) {
|
||||||
return new String(in.readAllBytes(), StandardCharsets.UTF_8);
|
return new String(in.readAllBytes(), StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@ import static org.openhab.core.addon.marketplace.internal.community.CommunityMar
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
@ -131,7 +133,12 @@ public class CommunityTransformationAddonHandler implements MarketplaceAddonHand
|
||||||
}
|
}
|
||||||
|
|
||||||
private String downloadTransformation(String urlString) throws IOException {
|
private String downloadTransformation(String urlString) throws IOException {
|
||||||
URL u = new URL(urlString);
|
URL u;
|
||||||
|
try {
|
||||||
|
u = (new URI(urlString)).toURL();
|
||||||
|
} catch (IllegalArgumentException | URISyntaxException e) {
|
||||||
|
throw new IOException(e);
|
||||||
|
}
|
||||||
try (InputStream in = u.openStream()) {
|
try (InputStream in = u.openStream()) {
|
||||||
return new String(in.readAllBytes(), StandardCharsets.UTF_8);
|
return new String(in.readAllBytes(), StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,12 +12,13 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.core.addon.marketplace.internal.community;
|
package org.openhab.core.addon.marketplace.internal.community;
|
||||||
|
|
||||||
import static org.openhab.core.addon.marketplace.MarketplaceConstants.UIWIDGETS_CONTENT_TYPE;
|
import static org.openhab.core.addon.marketplace.MarketplaceConstants.*;
|
||||||
import static org.openhab.core.addon.marketplace.MarketplaceConstants.YAML_DOWNLOAD_URL_PROPERTY;
|
|
||||||
import static org.openhab.core.addon.marketplace.internal.community.CommunityMarketplaceAddonService.YAML_CONTENT_PROPERTY;
|
import static org.openhab.core.addon.marketplace.internal.community.CommunityMarketplaceAddonService.YAML_CONTENT_PROPERTY;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
@ -106,7 +107,12 @@ public class CommunityUIWidgetAddonHandler implements MarketplaceAddonHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getWidgetFromURL(String urlString) throws IOException {
|
private String getWidgetFromURL(String urlString) throws IOException {
|
||||||
URL u = new URL(urlString);
|
URL u;
|
||||||
|
try {
|
||||||
|
u = (new URI(urlString)).toURL();
|
||||||
|
} catch (IllegalArgumentException | URISyntaxException e) {
|
||||||
|
throw new IOException(e);
|
||||||
|
}
|
||||||
try (InputStream in = u.openStream()) {
|
try (InputStream in = u.openStream()) {
|
||||||
return new String(in.readAllBytes(), StandardCharsets.UTF_8);
|
return new String(in.readAllBytes(), StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,9 @@ import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -91,13 +93,23 @@ public class JsonAddonService extends AbstractRemoteAddonService {
|
||||||
public void modified(@Nullable Map<String, Object> config) {
|
public void modified(@Nullable Map<String, Object> config) {
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
String urls = ConfigParser.valueAsOrElse(config.get(CONFIG_URLS), String.class, "");
|
String urls = ConfigParser.valueAsOrElse(config.get(CONFIG_URLS), String.class, "");
|
||||||
addonServiceUrls = Arrays.asList(urls.split("\\|"));
|
addonServiceUrls = Arrays.asList(urls.split("\\|")).stream().filter(this::isValidUrl).toList();
|
||||||
showUnstable = ConfigParser.valueAsOrElse(config.get(CONFIG_SHOW_UNSTABLE), Boolean.class, false);
|
showUnstable = ConfigParser.valueAsOrElse(config.get(CONFIG_SHOW_UNSTABLE), Boolean.class, false);
|
||||||
cachedRemoteAddons.invalidateValue();
|
cachedRemoteAddons.invalidateValue();
|
||||||
refreshSource();
|
refreshSource();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isValidUrl(String urlString) {
|
||||||
|
try {
|
||||||
|
(new URI(urlString)).toURL();
|
||||||
|
} catch (IllegalArgumentException | URISyntaxException | MalformedURLException e) {
|
||||||
|
logger.warn("JSON Addon Service invalid URL: {}", urlString);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Reference(cardinality = ReferenceCardinality.AT_LEAST_ONE, policy = ReferencePolicy.DYNAMIC)
|
@Reference(cardinality = ReferenceCardinality.AT_LEAST_ONE, policy = ReferencePolicy.DYNAMIC)
|
||||||
protected void addAddonHandler(MarketplaceAddonHandler handler) {
|
protected void addAddonHandler(MarketplaceAddonHandler handler) {
|
||||||
|
@ -124,7 +136,7 @@ public class JsonAddonService extends AbstractRemoteAddonService {
|
||||||
protected List<Addon> getRemoteAddons() {
|
protected List<Addon> getRemoteAddons() {
|
||||||
return addonServiceUrls.stream().map(urlString -> {
|
return addonServiceUrls.stream().map(urlString -> {
|
||||||
try {
|
try {
|
||||||
URL url = new URL(urlString);
|
URL url = URI.create(urlString).toURL();
|
||||||
URLConnection connection = url.openConnection();
|
URLConnection connection = url.openConnection();
|
||||||
connection.addRequestProperty("Accept", "application/json");
|
connection.addRequestProperty("Accept", "application/json");
|
||||||
try (Reader reader = new InputStreamReader(connection.getInputStream())) {
|
try (Reader reader = new InputStreamReader(connection.getInputStream())) {
|
||||||
|
@ -139,7 +151,7 @@ public class JsonAddonService extends AbstractRemoteAddonService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the addon UID is present and the entry is eitehr stable or unstable add-ons are requested
|
* Check if the addon UID is present and the entry is either stable or unstable add-ons are requested
|
||||||
*
|
*
|
||||||
* @param addonEntry the add-on entry to check
|
* @param addonEntry the add-on entry to check
|
||||||
* @return {@code true} if the add-on entry should be processed, {@code false otherwise}
|
* @return {@code true} if the add-on entry should be processed, {@code false otherwise}
|
||||||
|
|
|
@ -16,6 +16,8 @@ import static org.openhab.core.auth.oauth2client.internal.Keyword.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
@ -168,7 +170,7 @@ public class OAuthClientServiceImpl implements OAuthClientService {
|
||||||
public String extractAuthCodeFromAuthResponse(String redirectURLwithParams) throws OAuthException {
|
public String extractAuthCodeFromAuthResponse(String redirectURLwithParams) throws OAuthException {
|
||||||
// parse the redirectURL
|
// parse the redirectURL
|
||||||
try {
|
try {
|
||||||
URL redirectURLObject = new URL(redirectURLwithParams);
|
URL redirectURLObject = (new URI(redirectURLwithParams)).toURL();
|
||||||
UrlEncoded urlEncoded = new UrlEncoded(redirectURLObject.getQuery());
|
UrlEncoded urlEncoded = new UrlEncoded(redirectURLObject.getQuery());
|
||||||
|
|
||||||
String stateFromRedirectURL = urlEncoded.getValue(STATE, 0); // may contain multiple...
|
String stateFromRedirectURL = urlEncoded.getValue(STATE, 0); // may contain multiple...
|
||||||
|
@ -186,7 +188,7 @@ public class OAuthClientServiceImpl implements OAuthClientService {
|
||||||
throw new OAuthException(String.format("state from redirectURL is incorrect. Expected: %s Found: %s",
|
throw new OAuthException(String.format("state from redirectURL is incorrect. Expected: %s Found: %s",
|
||||||
persistedParams.state, stateFromRedirectURL));
|
persistedParams.state, stateFromRedirectURL));
|
||||||
}
|
}
|
||||||
} catch (MalformedURLException e) {
|
} catch (IllegalArgumentException | MalformedURLException | URISyntaxException e) {
|
||||||
throw new OAuthException("Redirect URL is malformed", e);
|
throw new OAuthException("Redirect URL is malformed", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@ package org.openhab.core.automation.internal.commands;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
@ -101,13 +103,13 @@ public class AutomationCommandImport extends AutomationCommand {
|
||||||
*/
|
*/
|
||||||
private @Nullable URL initURL(String parameterValue) {
|
private @Nullable URL initURL(String parameterValue) {
|
||||||
try {
|
try {
|
||||||
return new URL(parameterValue);
|
return (new URI(parameterValue)).toURL();
|
||||||
} catch (MalformedURLException mue) {
|
} catch (MalformedURLException | URISyntaxException mue) {
|
||||||
File f = new File(parameterValue);
|
File f = new File(parameterValue);
|
||||||
if (f.isFile()) {
|
if (f.isFile()) {
|
||||||
try {
|
try {
|
||||||
return f.toURI().toURL();
|
return f.toURI().toURL();
|
||||||
} catch (MalformedURLException e) {
|
} catch (IllegalArgumentException | MalformedURLException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@ package org.openhab.core.automation.internal.commands;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
@ -96,13 +98,13 @@ public class AutomationCommandRemove extends AutomationCommand {
|
||||||
*/
|
*/
|
||||||
private @Nullable URL initURL(String parameterValue) {
|
private @Nullable URL initURL(String parameterValue) {
|
||||||
try {
|
try {
|
||||||
return new URL(parameterValue);
|
return (new URI(parameterValue)).toURL();
|
||||||
} catch (MalformedURLException mue) {
|
} catch (MalformedURLException | URISyntaxException mue) {
|
||||||
File f = new File(parameterValue);
|
File f = new File(parameterValue);
|
||||||
if (f.isFile()) {
|
if (f.isFile()) {
|
||||||
try {
|
try {
|
||||||
return f.toURI().toURL();
|
return f.toURI().toURL();
|
||||||
} catch (MalformedURLException e) {
|
} catch (IllegalArgumentException | MalformedURLException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,16 +12,12 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.core.config.discovery.addon.upnp.tests;
|
package org.openhab.core.config.discovery.addon.upnp.tests;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.mockito.Mockito.*;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -85,7 +81,7 @@ public class UpnpAddonFinderTests {
|
||||||
upnpService = mock(UpnpService.class, Mockito.RETURNS_DEEP_STUBS);
|
upnpService = mock(UpnpService.class, Mockito.RETURNS_DEEP_STUBS);
|
||||||
URL url = null;
|
URL url = null;
|
||||||
try {
|
try {
|
||||||
url = new URL("http://www.openhab.org/");
|
url = URI.create("http://www.openhab.org/").toURL();
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
fail("MalformedURLException");
|
fail("MalformedURLException");
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
@ -224,8 +225,8 @@ public class EphemerisManagerImpl implements EphemerisManager, ConfigOptionProvi
|
||||||
private URL getUrl(String filename) throws FileNotFoundException {
|
private URL getUrl(String filename) throws FileNotFoundException {
|
||||||
if (Files.exists(Paths.get(filename))) {
|
if (Files.exists(Paths.get(filename))) {
|
||||||
try {
|
try {
|
||||||
return new URL("file:" + filename);
|
return (new URI("file:" + filename)).toURL();
|
||||||
} catch (MalformedURLException e) {
|
} catch (IllegalArgumentException | MalformedURLException | URISyntaxException e) {
|
||||||
throw new FileNotFoundException(e.getMessage());
|
throw new FileNotFoundException(e.getMessage());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -19,6 +19,8 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
@ -113,7 +115,11 @@ public final class PEMTrustManager extends X509ExtendedTrustManager {
|
||||||
* @throws CertificateInstantiationException
|
* @throws CertificateInstantiationException
|
||||||
*/
|
*/
|
||||||
public static PEMTrustManager getInstanceFromServer(String url) throws MalformedURLException, CertificateException {
|
public static PEMTrustManager getInstanceFromServer(String url) throws MalformedURLException, CertificateException {
|
||||||
return getInstanceFromServer(new URL(url));
|
try {
|
||||||
|
return getInstanceFromServer((new URI(url)).toURL());
|
||||||
|
} catch (IllegalArgumentException | URISyntaxException e) {
|
||||||
|
throw new MalformedURLException(e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,6 +18,8 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
@ -306,8 +308,8 @@ public class JsonStorageTest extends JavaTest {
|
||||||
|
|
||||||
private static URL newURL(String url) {
|
private static URL newURL(String url) {
|
||||||
try {
|
try {
|
||||||
return new URL(url);
|
return (new URI(url)).toURL();
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException | URISyntaxException e) {
|
||||||
throw new IllegalArgumentException(e);
|
throw new IllegalArgumentException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ import java.io.Serial;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -295,9 +294,15 @@ public class ProxyServletService extends HttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
private URI createURIFromString(String url) throws MalformedURLException, URISyntaxException {
|
private URI createURIFromString(String url) throws MalformedURLException, URISyntaxException {
|
||||||
// URI in this context should be valid URL. Therefore before creating URI, create URL,
|
URI uri = new URI(url);
|
||||||
|
// URI in this context should be valid URL. Therefore before returning URI, create URL,
|
||||||
// which validates the string.
|
// which validates the string.
|
||||||
return new URL(url).toURI();
|
try {
|
||||||
|
uri.toURL();
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new MalformedURLException(e.getMessage());
|
||||||
|
}
|
||||||
|
return uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -20,6 +20,7 @@ import java.io.BufferedInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -91,7 +92,7 @@ public class FirmwareTest extends JavaOSGiTest {
|
||||||
String description = "description";
|
String description = "description";
|
||||||
String model = "model";
|
String model = "model";
|
||||||
boolean modelRestricted = true;
|
boolean modelRestricted = true;
|
||||||
URL onlineChangelog = new URL("http://online.changelog");
|
URL onlineChangelog = URI.create("http://online.changelog").toURL();
|
||||||
String prerequisiteVersion = "0.0.9";
|
String prerequisiteVersion = "0.0.9";
|
||||||
String md5hash = "123abc";
|
String md5hash = "123abc";
|
||||||
String vendor = "vendor";
|
String vendor = "vendor";
|
||||||
|
@ -304,7 +305,7 @@ public class FirmwareTest extends JavaOSGiTest {
|
||||||
String description = "description";
|
String description = "description";
|
||||||
String model = "model";
|
String model = "model";
|
||||||
boolean modelRestricted = true;
|
boolean modelRestricted = true;
|
||||||
URL onlineChangelog = new URL("https://secure.com/changelog");
|
URL onlineChangelog = URI.create("https://secure.com/changelog").toURL();
|
||||||
String prerequisiteVersion = "0.1";
|
String prerequisiteVersion = "0.1";
|
||||||
String vendor = "vendor";
|
String vendor = "vendor";
|
||||||
Map<String, String> properties = Map.of("prop1", "val1", "prop2", "val2");
|
Map<String, String> properties = Map.of("prop1", "val1", "prop2", "val2");
|
||||||
|
@ -330,7 +331,7 @@ public class FirmwareTest extends JavaOSGiTest {
|
||||||
String description = "description";
|
String description = "description";
|
||||||
String model = "model";
|
String model = "model";
|
||||||
boolean modelRestricted = true;
|
boolean modelRestricted = true;
|
||||||
URL onlineChangelog = new URL("https://secure.com/changelog");
|
URL onlineChangelog = URI.create("https://secure.com/changelog").toURL();
|
||||||
String prerequisiteVersion = "0.1";
|
String prerequisiteVersion = "0.1";
|
||||||
String vendor = "vendor";
|
String vendor = "vendor";
|
||||||
Map<String, String> properties = Map.of("prop1", "val1", "prop2", "val2");
|
Map<String, String> properties = Map.of("prop1", "val1", "prop2", "val2");
|
||||||
|
|
|
@ -133,7 +133,7 @@ public class Constants {
|
||||||
|
|
||||||
private static URL newURL(String url) {
|
private static URL newURL(String url) {
|
||||||
try {
|
try {
|
||||||
return new URL(url);
|
return URI.create(url).toURL();
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
throw new UncheckedIOException(e);
|
throw new UncheckedIOException(e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue