提交 c7d30a00 编写于 作者: K kohsuke

adding validation to check the top page of another Hudson.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@7541 71c3de6d-444a-0410-be80-ed276b4c234a
上级 51715586
......@@ -16,6 +16,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.net.HttpURLConnection;
/**
* Base class that provides the framework for doing on-the-fly form field validation.
......@@ -200,6 +201,41 @@ public abstract class FormFieldValidator {
}
}
/**
* Checks if the given value is an URL to some Hudson's top page.
* @since 1.192
*/
public static class HudsonURL extends URLCheck {
public HudsonURL(StaplerRequest request, StaplerResponse response) {
super(request, response);
}
protected void check() throws IOException, ServletException {
String value = fixEmpty(request.getParameter("value"));
if(value==null) {// nothing entered yet
ok();
return;
}
if(!value.endsWith("/")) value+='/';
try {
URL url = new URL(value);
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.connect();
if(con.getResponseCode()!=200
|| con.getHeaderField("X-Hudson")==null) {
error(value+" is not Hudson ("+con.getResponseMessage()+")");
return;
}
ok();
} catch (IOException e) {
handleIOException(value,e);
}
}
}
/**
* Checks the file mask (specified in the 'value' query parameter) against
* the current workspace.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册