diff --git a/GreenshotConfluencePlugin/Confluence.cs b/GreenshotConfluencePlugin/Confluence.cs index a8d69d96b..b9bb2db12 100644 --- a/GreenshotConfluencePlugin/Confluence.cs +++ b/GreenshotConfluencePlugin/Confluence.cs @@ -95,7 +95,8 @@ namespace Confluence { public class ConfluenceConnector { private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ConfluenceConnector)); private const string AUTH_FAILED_EXCEPTION_NAME = "com.atlassian.confluence.rpc.AuthenticationFailedException"; - private static ConfluenceConfiguration config = IniConfig.GetIniSection(); + private const string V2_FAILED = "AXIS"; + private static ConfluenceConfiguration config = IniConfig.GetIniSection(); private string credentials = null; private DateTime loggedInTime = DateTime.Now; private bool loggedIn = false; @@ -105,13 +106,17 @@ namespace Confluence { private Cache pageCache = new Cache(60 * config.Timeout); public ConfluenceConnector(string url, int timeout) { - this.url = url; this.timeout = timeout; - confluence = new ConfluenceSoapServiceService(); - confluence.Url = url; - confluence.Proxy = NetworkHelper.CreateProxy(new Uri(url)); + init(url); } + private void init(string url) { + this.url = url; + confluence = new ConfluenceSoapServiceService(); + confluence.Url = url; + confluence.Proxy = NetworkHelper.CreateProxy(new Uri(url)); + } + ~ConfluenceConnector() { logout(); } @@ -126,6 +131,11 @@ namespace Confluence { this.loggedInTime = DateTime.Now; this.loggedIn = true; } catch (Exception e) { + // Check if confluence-v2 caused an error, use v1 instead + if (e.Message.Contains(V2_FAILED) && url.Contains("v2")) { + init(url.Replace("v2", "v1")); + return doLogin(user, password); + } // check if auth failed if (e.Message.Contains(AUTH_FAILED_EXCEPTION_NAME)) { return false; @@ -144,8 +154,9 @@ namespace Confluence { logout(); try { // Get the system name, so the user knows where to login to - string systemName = url.Replace(ConfluenceConfiguration.DEFAULT_POSTFIX,""); - CredentialsDialog dialog = new CredentialsDialog(systemName); + string systemName = url.Replace(ConfluenceConfiguration.DEFAULT_POSTFIX1,""); + systemName = url.Replace(ConfluenceConfiguration.DEFAULT_POSTFIX2, ""); + CredentialsDialog dialog = new CredentialsDialog(systemName); dialog.Name = null; while (dialog.Show(dialog.Name) == DialogResult.OK) { if (doLogin(dialog.Name, dialog.Password)) { diff --git a/GreenshotConfluencePlugin/ConfluenceConfiguration.cs b/GreenshotConfluencePlugin/ConfluenceConfiguration.cs index d458ef5e3..ff7319c2a 100644 --- a/GreenshotConfluencePlugin/ConfluenceConfiguration.cs +++ b/GreenshotConfluencePlugin/ConfluenceConfiguration.cs @@ -29,8 +29,9 @@ namespace GreenshotConfluencePlugin { [Serializable] [IniSection("Confluence", Description="Greenshot Confluence Plugin configuration")] public class ConfluenceConfiguration : IniSection { - public const string DEFAULT_POSTFIX = "/rpc/soap-axis/confluenceservice-v1?wsdl"; - public const string DEFAULT_PREFIX = "http://"; + public const string DEFAULT_POSTFIX1 = "/rpc/soap-axis/confluenceservice-v1?wsdl"; + public const string DEFAULT_POSTFIX2 = "/rpc/soap-axis/confluenceservice-v2?wsdl"; + public const string DEFAULT_PREFIX = "http://"; private const string DEFAULT_URL = DEFAULT_PREFIX + "confluence"; [IniProperty("Url", Description="Url to Confluence system, including wsdl.", DefaultValue=DEFAULT_URL)] diff --git a/GreenshotConfluencePlugin/ConfluencePlugin.cs b/GreenshotConfluencePlugin/ConfluencePlugin.cs index 42a123314..ce0bc45ee 100644 --- a/GreenshotConfluencePlugin/ConfluencePlugin.cs +++ b/GreenshotConfluencePlugin/ConfluencePlugin.cs @@ -48,7 +48,7 @@ namespace GreenshotConfluencePlugin { if (config.Url.Contains("soap-axis")) { confluenceConnector = new ConfluenceConnector(config.Url, config.Timeout); } else { - confluenceConnector = new ConfluenceConnector(config.Url + ConfluenceConfiguration.DEFAULT_POSTFIX, config.Timeout); + confluenceConnector = new ConfluenceConnector(config.Url + ConfluenceConfiguration.DEFAULT_POSTFIX2, config.Timeout); } } } diff --git a/GreenshotConfluencePlugin/ConfluenceUtils.cs b/GreenshotConfluencePlugin/ConfluenceUtils.cs index c52e88b41..76309bc9f 100644 --- a/GreenshotConfluencePlugin/ConfluenceUtils.cs +++ b/GreenshotConfluencePlugin/ConfluenceUtils.cs @@ -38,7 +38,7 @@ namespace GreenshotConfluencePlugin { List pages = new List(); Regex pageIdRegex = new Regex(@"pageId=(\d+)"); Regex spacePageRegex = new Regex(@"\/display\/([^\/]+)\/([^#]+)"); - foreach(string browserurl in GetBrowserUrls()) { + foreach(string browserurl in GetBrowserUrls()) { string url = null; try { url = Uri.UnescapeDataString(browserurl).Replace("+", " ");