Avoid UnsupportedEncodingException & use const from StandardCharsets (#11948)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
Christoph Weitkamp
2022-01-03 16:05:08 +01:00
committed by GitHub
parent 3f54327d5a
commit 167f8ebc49
52 changed files with 180 additions and 414 deletions

View File

@@ -12,8 +12,8 @@
*/
package org.openhab.binding.evohome.internal.api;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
@@ -200,17 +200,9 @@ public class EvohomeApiClient {
}
private boolean authenticateWithUsername() {
boolean result = false;
try {
String credentials = "Username=" + URLEncoder.encode(configuration.username, "UTF-8") + "&" + "Password="
+ URLEncoder.encode(configuration.password, "UTF-8");
result = authenticate(credentials, "password");
} catch (UnsupportedEncodingException e) {
logger.error("Credential conversion failed", e);
}
return result;
String credentials = "Username=" + URLEncoder.encode(configuration.username, StandardCharsets.UTF_8) + "&"
+ "Password=" + URLEncoder.encode(configuration.password, StandardCharsets.UTF_8);
return authenticate(credentials, "password");
}
private boolean authenticateWithToken(String accessToken) {