Fix deprecations (#2163)

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born 2021-01-30 12:22:31 +01:00 committed by GitHub
parent 49e148ad7d
commit 46666eb169
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 21 additions and 22 deletions

View File

@ -367,7 +367,7 @@ public class ReferenceResolver {
throws NoSuchFieldException, SecurityException {
try {
Field f = objClass.getDeclaredField(fieldName);
if (!f.isAccessible()) {
if (!f.canAccess(bean)) {
f.setAccessible(true);
}
return f.get(bean);

View File

@ -24,6 +24,7 @@ import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.List;
import java.util.Optional;
import java.util.Properties;
@ -42,8 +43,6 @@ import org.eclipse.jetty.client.util.InputStreamContentProvider;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.util.B64Code;
import org.eclipse.jetty.util.StringUtil;
import org.openhab.core.library.types.RawType;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
@ -227,7 +226,8 @@ public class HttpUtil {
String user = userInfo[0];
String password = userInfo[1];
String basicAuthentication = "Basic " + B64Code.encode(user + ":" + password, StringUtil.__ISO_8859_1);
String basicAuthentication = "Basic "
+ Base64.getEncoder().encodeToString((user + ":" + password).getBytes());
request.header(HttpHeader.AUTHORIZATION, basicAuthentication);
}
} catch (URISyntaxException e) {

View File

@ -334,7 +334,7 @@ public class WebClientFactoryImpl implements HttpClientFactory, WebSocketFactory
}
private SslContextFactory createSslContextFactory() {
SslContextFactory sslContextFactory = new SslContextFactory();
SslContextFactory sslContextFactory = new SslContextFactory.Client();
sslContextFactory.setEndpointIdentificationAlgorithm("HTTPS");
try {

View File

@ -49,7 +49,7 @@ public class AsyncProxyServlet extends org.eclipse.jetty.proxy.AsyncProxyServlet
*/
@Override
protected HttpClient newHttpClient() {
return new HttpClient(new SslContextFactory());
return new HttpClient(new SslContextFactory.Client());
}
@Override

View File

@ -49,7 +49,7 @@ public class BlockingProxyServlet extends HttpServlet {
private final ProxyServletService service;
private static HttpClient httpClient = new HttpClient(new SslContextFactory());
private static HttpClient httpClient = new HttpClient(new SslContextFactory.Client());
/** Timeout for HTTP requests in ms */
private static final int TIMEOUT = 15000;

View File

@ -17,6 +17,7 @@ import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Base64;
import java.util.Hashtable;
import java.util.Map;
@ -29,8 +30,6 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.util.B64Code;
import org.eclipse.jetty.util.StringUtil;
import org.openhab.core.library.types.StringType;
import org.openhab.core.model.core.ModelRepository;
import org.openhab.core.model.sitemap.sitemap.Image;
@ -317,7 +316,7 @@ public class ProxyServletService extends HttpServlet {
String password = userInfo.length >= 2 ? userInfo[1] : null;
String authString = password != null ? user + ":" + password : user + ":";
String basicAuthentication = "Basic " + B64Code.encode(authString, StringUtil.__ISO_8859_1);
String basicAuthentication = "Basic " + Base64.getEncoder().encodeToString(authString.getBytes());
request.header(HttpHeader.AUTHORIZATION, basicAuthentication);
}
}

View File

@ -18,13 +18,12 @@ import static org.mockito.Mockito.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Base64;
import javax.servlet.http.HttpServletRequest;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.util.B64Code;
import org.eclipse.jetty.util.StringUtil;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.core.library.types.OnOffType;
@ -111,7 +110,7 @@ public class ProxyServletServiceTest {
URI uri = new URI("http://testuser:testpassword@127.0.0.1:8080/content");
service.maybeAppendAuthHeader(uri, request);
verify(request).header(HttpHeader.AUTHORIZATION,
"Basic " + B64Code.encode("testuser:testpassword", StringUtil.__ISO_8859_1));
"Basic " + Base64.getEncoder().encodeToString("testuser:testpassword".getBytes()));
}
@Test
@ -120,7 +119,7 @@ public class ProxyServletServiceTest {
URI uri = new URI("http://testuser@127.0.0.1:8080/content");
service.maybeAppendAuthHeader(uri, request);
verify(request).header(HttpHeader.AUTHORIZATION,
"Basic " + B64Code.encode("testuser:", StringUtil.__ISO_8859_1));
"Basic " + Base64.getEncoder().encodeToString("testuser:".getBytes()));
}
@Test

View File

@ -60,14 +60,15 @@ public class ItemUpdater extends AbstractItemEventSubscriber {
// Look for class hierarchy
for (Class<? extends State> state : item.getAcceptedDataTypes()) {
try {
if (!state.isEnum() && state.newInstance().getClass().isAssignableFrom(newState.getClass())) {
if (!state.isEnum() && state.getDeclaredConstructor().newInstance().getClass()
.isAssignableFrom(newState.getClass())) {
isAccepted = true;
break;
}
} catch (InstantiationException e) {
logger.warn("InstantiationException on {}", e.getMessage()); // Should never happen
} catch (IllegalAccessException e) {
logger.warn("IllegalAccessException on {}", e.getMessage()); // Should never happen
} catch (ReflectiveOperationException e) {
// Should never happen
logger.warn("{} while creating {} instance: {}", e.getClass().getSimpleName(),
state.getClass().getSimpleName(), e.getMessage());
}
}
}

View File

@ -40,7 +40,7 @@ public class ResourceBundleClassLoaderTest {
File file = new File(root.toFile(), relativeFile);
file.createNewFile();
return file.toURL();
return file.toURI().toURL();
}
@Test

View File

@ -35,7 +35,7 @@ import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.MethodOrderer.Alphanumeric;
import org.junit.jupiter.api.MethodOrderer.MethodName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.io.TempDir;
@ -48,7 +48,7 @@ import org.osgi.service.cm.ConfigurationAdmin;
/**
* @author Petar Valchev - Initial contribution
*/
@TestMethodOrder(Alphanumeric.class)
@TestMethodOrder(MethodName.class)
public class ConfigDispatcherOSGiTest extends JavaOSGiTest {
public @TempDir File tmpBaseFolder;