PR: MPLINKCHECK-13

use HEAD instead of GET


git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@115110 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
brett committed 2004-05-01 01:46:09 +00:00
1 parent af5e092988
commit 514a74d3c9
1 file changed
+14 -14
@@ -23,14 +23,14 @@ import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.StatusLine;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.HeadMethod;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Checks links which are normal URLs
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
* @version $Id: HTTPLinkValidator.java,v 1.10 2004/03/02 15:09:17 evenisse Exp $
* @version $Id: HTTPLinkValidator.java,v 1.11 2004/05/01 01:46:09 brett Exp $
*/
public class HTTPLinkValidator implements LinkValidator
{
@@ -96,34 +96,34 @@ public class HTTPLinkValidator implements LinkValidator
cl.setState(state);
// execute the GET
GetMethod gm = checkLink(cl, link);
StatusLine sl = gm.getStatusLine();
HeadMethod hm = checkLink(cl, link);
StatusLine sl = hm.getStatusLine();
if (sl == null) {
LOG.info("Unknown error validating link : " + link);
return LVR_VALID;
}
if (gm.getStatusCode() == 302)
if (hm.getStatusCode() == 302)
{
Header locationHeader = gm.getResponseHeader("Location");
Header locationHeader = hm.getResponseHeader("Location");
if (locationHeader == null) {
LOG.info("Site sent redirect, but did not set Location header");
} else {
String newLink = locationHeader.getValue();
LOG.debug("Following 1 redirect to " + newLink);
gm = checkLink(cl, newLink);
hm = checkLink(cl, newLink);
}
}
//FIXME: This constant is defined somewhere, but I can't remember where...
if (gm.getStatusCode() == 200)
if (hm.getStatusCode() == 200)
{
return LVR_VALID;
}
else
{
String msg = "Received: [" + gm.getStatusCode() + "] for " + link;
String msg = "Received: [" + hm.getStatusCode() + "] for " + link;
LOG.info(msg);
System.out.println(msg);
return LVR_INVALID;
@@ -139,21 +139,21 @@ public class HTTPLinkValidator implements LinkValidator
}
private GetMethod checkLink(HttpClient cl, String link)
private HeadMethod checkLink(HttpClient cl, String link)
{
GetMethod gm = new GetMethod(link);
HeadMethod hm = new HeadMethod(link);
try
{
LOG.info("Checking link " + link);
gm.setFollowRedirects(true);
cl.executeMethod(gm);
hm.setFollowRedirects(true);
cl.executeMethod(hm);
LOG.debug("Checked link " + link);
}
catch (Exception e)
{
LOG.warn("Error validating " + link, e);
}
return gm;
return hm;
}
/**