modules/enterprise/server/plugins/jboss-software/src/main/java/org/rhq/enterprise/server/plugins/jboss/software/JBossSoftwareContentSourceAdapter.java | 21 +++++++++-
1 file changed, 19 insertions(+), 2 deletions(-)
New commits:
commit 5055dca9b0d0bfde336be48704d50628663bd804
Author: Simeon Pinder <spinder(a)redhat.com>
Date: Wed Jun 30 18:06:30 2010 -0400
BZ:607799 modifed content source to detect redirects, reinitialize and log occurrence.
diff --git a/modules/enterprise/server/plugins/jboss-software/src/main/java/org/rhq/enterprise/server/plugins/jboss/software/JBossSoftwareContentSourceAdapter.java b/modules/enterprise/server/plugins/jboss-software/src/main/java/org/rhq/enterprise/server/plugins/jboss/software/JBossSoftwareContentSourceAdapter.java
index 788961e..2758e2b 100644
--- a/modules/enterprise/server/plugins/jboss-software/src/main/java/org/rhq/enterprise/server/plugins/jboss/software/JBossSoftwareContentSourceAdapter.java
+++ b/modules/enterprise/server/plugins/jboss-software/src/main/java/org/rhq/enterprise/server/plugins/jboss/software/JBossSoftwareContentSourceAdapter.java
@@ -23,8 +23,6 @@ import java.net.URI;
import java.net.URL;
import java.util.Collection;
-import javax.xml.parsers.ParserConfigurationException;
-
import churchillobjects.rss4j.RssDocument;
import churchillobjects.rss4j.parser.RssParser;
@@ -216,8 +214,27 @@ public class JBossSoftwareContentSourceAdapter implements ContentProvider, Packa
// Perform the connection and capture its response XML
String rawFeed = null;
try {
+ //store off original url to detect forwarding as 401 results otherwise
+ //url forwarding is true by default.
+ String originalUrl = method.getURI().getURI();
+
int status = client.executeMethod(method);
+ //Check to see if redirection has occurred
+ String currentUrl = method.getURI().getURI();
+ //if redirection has occurred, reconnect with correct address.
+ if (!originalUrl.trim().equalsIgnoreCase(currentUrl.trim())) {
+ method = new GetMethod(currentUrl);
+ method.setDoAuthentication(true);
+ if (username != null && password != null) {
+ UsernamePasswordCredentials upc = new UsernamePasswordCredentials(username, password);
+ client.getState().setCredentials("users", method.getHostConfiguration().getHost(), upc);
+ }
+ log.warn("Following redirect to [" + currentUrl
+ + "]. You may need to update your feed URL if redirect is permanent.");
+ status = client.executeMethod(method);
+ }
+
if (status == 404) {
throw new SyncException("Could not find the feed at URL [" + url
+ "]. Make sure the URL field correctly refers to the CSP feed location.");