Added Confluence V2 support, preferring this and using fall back to V1 if this doesn't work at the login.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1944 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-07-12 14:11:47 +00:00
parent d28bea64a7
commit 5c038ed1da
4 changed files with 23 additions and 11 deletions

View file

@ -95,6 +95,7 @@ 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 const string V2_FAILED = "AXIS";
private static ConfluenceConfiguration config = IniConfig.GetIniSection<ConfluenceConfiguration>();
private string credentials = null;
private DateTime loggedInTime = DateTime.Now;
@ -105,8 +106,12 @@ namespace Confluence {
private Cache<string, RemotePage> pageCache = new Cache<string, RemotePage>(60 * config.Timeout);
public ConfluenceConnector(string url, int timeout) {
this.url = url;
this.timeout = timeout;
init(url);
}
private void init(string url) {
this.url = url;
confluence = new ConfluenceSoapServiceService();
confluence.Url = url;
confluence.Proxy = NetworkHelper.CreateProxy(new Uri(url));
@ -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,7 +154,8 @@ namespace Confluence {
logout();
try {
// Get the system name, so the user knows where to login to
string systemName = url.Replace(ConfluenceConfiguration.DEFAULT_POSTFIX,"");
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) {

View file

@ -29,7 +29,8 @@ 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_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";

View file

@ -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);
}
}
}