Adapt resource root URL form validation to new Jetty
@@ -33,6 +33,7 @@ import jenkins.model.Jenkins;
import jenkins.model.JenkinsLocationConfiguration;
import jenkins.model.identity.InstanceIdentityProvider;
import jenkins.util.UrlHelper;
+import org.apache.commons.io.IOUtils;
import org.jenkinsci.Symbol;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.Beta;
@@ -48,6 +49,7 @@ import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
+import java.nio.charset.StandardCharsets;
import java.security.interfaces.RSAPublicKey;
import java.util.Base64;
import java.util.logging.Level;
@@ -168,9 +170,12 @@ public final class ResourceDomainConfiguration extends GlobalConfiguration {
}
// response is error
String responseMessage = httpURLConnection.getResponseMessage();
- if (responseCode == 404 && responseMessage.equals(ERROR_RESPONSE)) {
+ if (responseCode == 404) {
+ String responseBody = String.join("", IOUtils.readLines(httpURLConnection.getErrorStream(), StandardCharsets.UTF_8));
+ if (responseMessage.contains(ERROR_RESPONSE) || responseBody.contains(ERROR_RESPONSE)) {
return FormValidation.ok(Messages.ResourceDomainConfiguration_ResourceResponse());
}
+ }
return FormValidation.error(Messages.ResourceDomainConfiguration_FailedIdentityCheck(responseCode, responseMessage));
}
return FormValidation.error(Messages.ResourceDomainConfiguration_Invalid()); // unlikely to ever be hit
