diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/serverconnection/impl/HttpTransportImpl.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/serverconnection/impl/HttpTransportImpl.java index 1c63bb82b8130..ff8adab9bef9d 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/serverconnection/impl/HttpTransportImpl.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/serverconnection/impl/HttpTransportImpl.java @@ -43,6 +43,7 @@ import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; +import org.apache.commons.lang3.StringUtils; import org.openhab.binding.digitalstrom.internal.lib.config.Config; import org.openhab.binding.digitalstrom.internal.lib.manager.ConnectionManager; import org.openhab.binding.digitalstrom.internal.lib.serverconnection.HttpTransport; @@ -333,8 +334,7 @@ private String checkSessionToken(String request) { } private boolean checkNeededSessionToken(String request) { - String requestFirstPart = request.substring(0, request.indexOf("?")); - String functionName = requestFirstPart.substring(requestFirstPart.lastIndexOf("/") + 1); + String functionName = StringUtils.substringAfterLast(StringUtils.substringBefore(request, "?"), "/"); return !DsAPIImpl.METHODS_MUST_NOT_BE_LOGGED_IN.contains(functionName); } @@ -347,10 +347,8 @@ private String addSessionToken(String request, String sessionToken) { correctedRequest = correctedRequest + "?" + ParameterKeys.TOKEN + "=" + sessionToken; } } else { - String strippedRequest = correctedRequest - .substring(correctedRequest.indexOf(ParameterKeys.TOKEN + "=") + ParameterKeys.TOKEN.length() + 1); - strippedRequest = strippedRequest.substring(0, strippedRequest.lastIndexOf("&")); - correctedRequest = correctedRequest.replaceFirst(strippedRequest, sessionToken); + correctedRequest = StringUtils.replaceOnce(correctedRequest, StringUtils.substringBefore( + StringUtils.substringAfter(correctedRequest, ParameterKeys.TOKEN + "="), "&"), sessionToken); } return correctedRequest; }