Now checks the StatusLine object which will be null if the validation failed badly.

This prevents an unexpected NPE when checking the status code.
PR: MAVEN-943


git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@114218 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
bwalding committed 2003-10-17 14:15:01 +00:00
1 parent 5d38fdf022
commit 582557428b
2 files changed
+38 -1

No files matched your search

@@ -60,6 +60,7 @@ import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HostConfiguration;
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.logging.Log;
@@ -68,7 +69,7 @@ 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.8 2003/09/13 21:48:08 bwalding Exp $
* @version $Id: HTTPLinkValidator.java,v 1.9 2003/10/17 14:15:01 bwalding Exp $
*/
public class HTTPLinkValidator implements LinkValidator
{
@@ -135,6 +136,12 @@ public class HTTPLinkValidator implements LinkValidator
// execute the GET
GetMethod gm = checkLink(cl, link);
StatusLine sl = gm.getStatusLine();
if (sl == null) {
LOG.info("Unknown error validating link : " + link);
return LVR_VALID;
}
if (gm.getStatusCode() == 302)
{
@@ -0,0 +1,30 @@
package org.apache.maven.linkcheck.validation;
import java.io.File;
import junit.framework.TestCase;
/**
* @author <a href="bwalding@apache.org">Ben Walding</a>
* @version $Id: HTTPLinkValidatorTest.java,v 1.1 2003/10/17 14:15:01 bwalding Exp $
*/
public class HTTPLinkValidatorTest extends TestCase
{
public void testValidateLink()
{
//I've disabled these as they require access to the net. Ultimately
//I'd like to setup a temporary internal webserver during testing.
//Probably a test repository so it can be used for a variety of things.
//checkLink("http://www.example.com");
//checkLink("http://www.example.com>);");
}
protected LinkValidationResult checkLink(String link)
{
HTTPLinkValidator hlv = new HTTPLinkValidator(null, null, null, null);
LinkValidationItem lvi = new LinkValidationItem(new File("."), link);
return hlv.validateLink(lvi);
}
}