Make ConnectionFactory more amenable to DI by changing SetXXX methods (even with multiple arguments) to properties.

This commit is contained in:
markpollack
2009-06-18 04:45:40 +00:00
parent 24d072a879
commit 89c7e246a9
7 changed files with 234 additions and 30 deletions

View File

@@ -18,15 +18,24 @@
#endregion
using System;
using System.IO;
using System.Runtime.Serialization;
using Spring.Objects.Factory;
using TIBCO.EMS;
namespace Spring.Messaging.Ems.Common
{
public class EmsConnectionFactory : IConnectionFactory
public class EmsConnectionFactory : IConnectionFactory, IInitializingObject
{
private ConnectionFactory nativeConnectionFactory;
private string sslProxyAuthUsername;
private string sslProxyAuthPassword;
private string sslProxyHost;
private int sslProxyPort;
public EmsConnectionFactory(ConnectionFactory nativeConnectionFactory)
{
@@ -78,7 +87,8 @@ namespace Spring.Messaging.Ems.Common
public string SSLProxyHost
{
get { return nativeConnectionFactory.GetSSLProxyHost(); }
get { return this.sslProxyHost; }
set { this.sslProxyHost = value; }
}
public string SSLProxyPassword
@@ -88,7 +98,8 @@ namespace Spring.Messaging.Ems.Common
public int SSLProxyPort
{
get { return nativeConnectionFactory.GetSSLProxyPort(); }
get { return this.sslProxyPort; }
set { this.sslProxyPort = value; }
}
public string SSLProxyUser
@@ -96,9 +107,23 @@ namespace Spring.Messaging.Ems.Common
get { return nativeConnectionFactory.GetSSLProxyUser(); }
}
public void SetCertificateStoreType(EMSSSLStoreType type, object storeInfo)
public IEmsSSLStoreType CertificateStoreType
{
nativeConnectionFactory.SetCertificateStoreType(type, storeInfo);
set
{
if (value is EmsSSLFileStoreInfo)
{
EmsSSLFileStoreInfo emsSslFileStoreInfo = (EmsSSLFileStoreInfo) value;
nativeConnectionFactory.SetCertificateStoreType(EMSSSLStoreType.EMSSSL_STORE_TYPE_FILE, emsSslFileStoreInfo.NativeEmsSslFileStoreInfo);
} else if (value is EmsSSLSystemStoreInfo)
{
EmsSSLSystemStoreInfo info = (EmsSSLSystemStoreInfo) value;
nativeConnectionFactory.SetCertificateStoreType(EMSSSLStoreType.EMSSSL_STORE_TYPE_SYSTEM, info.NativeEmssslSystemStoreInfo);
} else
{
throw new ArgumentException("IEmsSSLStoreType of type [" + value.GetType() + "], not supported.");
}
}
}
public string ClientID
@@ -176,9 +201,16 @@ namespace Spring.Messaging.Ems.Common
nativeConnectionFactory.SetSSLProxy(host, port);
}
public string[] SSLProxyAuth
public string SSLProxyAuthUsername
{
set { nativeConnectionFactory.SetSSLProxyAuth(value[0], value[1]); }
set { this.sslProxyAuthUsername = value; }
get { return this.sslProxyAuthUsername; }
}
public string SSLProxyAuthPassword
{
set { this.sslProxyAuthPassword = value; }
get { return this.sslProxyAuthPassword; }
}
public bool SSLTrace
@@ -213,5 +245,15 @@ namespace Spring.Messaging.Ems.Common
}
#endregion
#region Implementation of IInitializingObject
public void AfterPropertiesSet()
{
nativeConnectionFactory.SetSSLProxyAuth(this.sslProxyAuthUsername, this.sslProxyAuthPassword);
nativeConnectionFactory.SetSSLProxy(this.sslProxyHost, this.sslProxyPort);
}
#endregion
}
}

View File

@@ -0,0 +1,62 @@
#region License
/*
* Copyright <20> 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System.Security.Cryptography.X509Certificates;
using TIBCO.EMS;
namespace Spring.Messaging.Ems.Common
{
public class EmsSSLFileStoreInfo : IEmsSSLStoreType
{
private EMSSSLFileStoreInfo nativeEmsSSLFileStoreInfo;
public virtual EMSSSLFileStoreInfo NativeEmsSslFileStoreInfo
{
get { return nativeEmsSSLFileStoreInfo; }
set { nativeEmsSSLFileStoreInfo = value; }
}
public X509Certificate SslClientIdentity
{
set { NativeEmsSslFileStoreInfo.SetSSLClientIdentity(value); }
}
public string SslClientIdentityAsString
{
set { NativeEmsSslFileStoreInfo.SetSSLClientIdentity(value); }
}
public string SslPassword
{
set { NativeEmsSslFileStoreInfo.SetSSLPassword(value.ToCharArray()); }
}
public X509Certificate SslTrustedCertificate
{
set { NativeEmsSslFileStoreInfo.SetSSLTrustedCertificate(value); }
}
public string SslTrustedCertificateAsString
{
set { NativeEmsSslFileStoreInfo.SetSSLTrustedCertificate(value); }
}
}
}

View File

@@ -0,0 +1,58 @@
#region License
/*
* Copyright <20> 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System.Security.Cryptography.X509Certificates;
using TIBCO.EMS;
namespace Spring.Messaging.Ems.Common
{
public class EmsSSLSystemStoreInfo : IEmsSSLStoreType
{
private EMSSSLSystemStoreInfo emssslSystemStoreInfo;
public EMSSSLSystemStoreInfo NativeEmssslSystemStoreInfo
{
get { return emssslSystemStoreInfo; }
set { emssslSystemStoreInfo = value; }
}
public virtual EMSSSLSystemStoreInfo EmssslSystemStoreInfo
{
get { return emssslSystemStoreInfo; }
set { emssslSystemStoreInfo = value; }
}
public string CertificateNameAsFullSubjectDn
{
set { EmssslSystemStoreInfo.SetCertificateNameAsFullSubjectDN(value); }
}
public StoreLocation CertificateStoreLocation {
set { EmssslSystemStoreInfo.SetCertificateStoreLocation(value); }
}
public string CertificateStoreName
{
set { EmssslSystemStoreInfo.SetCertificateStoreName(value); }
}
}
}

View File

@@ -32,13 +32,12 @@ namespace Spring.Messaging.Ems.Common
IConnection CreateConnection();
IConnection CreateConnection(string userName, string password);
object CertificateStore { get; }
string SSLProxyHost { get; }
string SSLProxyHost { set; get; }
int SSLProxyPort { set; get; }
string SSLProxyPassword { get; }
int SSLProxyPort { get; }
string SSLProxyUser { get; }
void SetCertificateStoreType(EMSSSLStoreType type, object storeInfo);
IEmsSSLStoreType CertificateStoreType { set; }
string ClientID { set; }
StreamWriter ClientTracer { set; }
int ConnAttemptCount { set; }
@@ -56,10 +55,10 @@ namespace Spring.Messaging.Ems.Common
int ReconnAttemptTimeout { set; }
string ServerUrl { set; }
bool SSLAuthOnly { set; }
void SetSSLProxy(string host, int port);
string[] SSLProxyAuth { set; }
string SSLProxyAuthUsername { set; get; }
string SSLProxyAuthPassword { set; get; }
bool SSLTrace { set; }
string TargetHostName { set; }

View File

@@ -0,0 +1,30 @@
#region License
/*
* Copyright <20> 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
namespace Spring.Messaging.Ems.Common
{
/// <summary>
/// Market interface for EMS SSL store types
/// </summary>
public interface IEmsSSLStoreType
{
}
}

View File

@@ -98,7 +98,6 @@ namespace Spring.Messaging.Ems.Connections
/// </summary>
private object connectionMonitor = new object();
#endregion
#region Constructors
@@ -259,29 +258,20 @@ namespace Spring.Messaging.Ems.Connections
get { return TargetConnectionFactory.CertificateStore; }
}
public string SSLProxyHost
{
get { return TargetConnectionFactory.SSLProxyHost; }
}
public string SSLProxyPassword
{
get { return TargetConnectionFactory.SSLProxyPassword; }
}
public int SSLProxyPort
{
get { return TargetConnectionFactory.SSLProxyPort; }
}
public string SSLProxyUser
{
get { return TargetConnectionFactory.SSLProxyUser; }
}
public void SetCertificateStoreType(EMSSSLStoreType type, object storeInfo)
public IEmsSSLStoreType CertificateStoreType
{
TargetConnectionFactory.SetCertificateStoreType(type, storeInfo);
set { TargetConnectionFactory.CertificateStoreType = value; }
}
public string ClientID
@@ -358,14 +348,28 @@ namespace Spring.Messaging.Ems.Connections
set { TargetConnectionFactory.SSLAuthOnly = value; }
}
public void SetSSLProxy(string host, int port)
public string SSLProxyHost
{
TargetConnectionFactory.SetSSLProxy(host, port);
get { return TargetConnectionFactory.SSLProxyHost; }
set { TargetConnectionFactory.SSLProxyHost = value; }
}
public int SSLProxyPort
{
get { return TargetConnectionFactory.SSLProxyPort;}
set { TargetConnectionFactory.SSLProxyPort = value; }
}
public string[] SSLProxyAuth
public string SSLProxyAuthUsername
{
set { TargetConnectionFactory.SSLProxyAuth = value; }
set { TargetConnectionFactory.SSLProxyAuthUsername = value; }
get { return TargetConnectionFactory.SSLProxyAuthUsername; }
}
public string SSLProxyAuthPassword
{
set { TargetConnectionFactory.SSLProxyAuthPassword = value; }
get { return TargetConnectionFactory.SSLProxyAuthPassword; }
}
public bool SSLTrace
@@ -396,6 +400,8 @@ namespace Spring.Messaging.Ems.Connections
#endregion
#region Implementation of ISerializable
public void GetObjectData(SerializationInfo info, StreamingContext context)
@@ -537,6 +543,10 @@ namespace Spring.Messaging.Ems.Connections
{
throw new ArgumentException("Connection or 'TargetConnectionFactory' is required.");
}
// Note this is repeated in EmsConnectionFactory as this class only referes to IConnectionFactory and
// IConnectionFactory does not implement the spring specific lifecycle interface IInitializingObject
TargetConnectionFactory.NativeConnectionFactory.SetSSLProxyAuth(SSLProxyAuthUsername, SSLProxyAuthPassword);
TargetConnectionFactory.NativeConnectionFactory.SetSSLProxy(SSLProxyHost, SSLProxyPort);
}
#endregion

View File

@@ -76,12 +76,15 @@
<Compile Include="Messaging\Ems\Common\EmsMessageConsumer.cs" />
<Compile Include="Messaging\Ems\Common\EmsMessageProducer.cs" />
<Compile Include="Messaging\Ems\Common\EmsSession.cs" />
<Compile Include="Messaging\Ems\Common\EmsSSLFileStoreInfo.cs" />
<Compile Include="Messaging\Ems\Common\EmsSSLSystemStoreInfo.cs" />
<Compile Include="Messaging\Ems\Common\EmsTopicSubscriber.cs" />
<Compile Include="Messaging\Ems\Common\IConnection.cs" />
<Compile Include="Messaging\Ems\Common\IConnectionFactory.cs" />
<Compile Include="Messaging\Ems\Common\IMessageConsumer.cs" />
<Compile Include="Messaging\Ems\Common\IMessageProducer.cs" />
<Compile Include="Messaging\Ems\Common\ISession.cs" />
<Compile Include="Messaging\Ems\Common\IEmsSSLStoreType.cs" />
<Compile Include="Messaging\Ems\Common\ITopicSubscriber.cs" />
<Compile Include="Messaging\Ems\Config\MessageListenerContainerObjectDefinitionParser.cs" />
<Compile Include="Messaging\Ems\Config\EmsNamespaceParser.cs" />