类 UserCredentialsConnectionFactoryAdapter
- java.lang.Object
- org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter
public class UserCredentialsConnectionFactoryAdapter extends Object implements ConnectionFactory, QueueConnectionFactory, TopicConnectionFactory, InitializingBean
An adapter for a target JMSConnectionFactory
, applying the given user credentials to every standardcreateConnection()
call, that is, implicitly invokingcreateConnection(username, password)
on the target. All other methods simply delegate to the corresponding methods of the target ConnectionFactory.Can be used to proxy a target JNDI ConnectionFactory that does not have user credentials configured. Client code can work with the ConnectionFactory without passing in username and password on every
createConnection()
call.In the following example, client code can simply transparently work with the preconfigured "myConnectionFactory", implicitly accessing "myTargetConnectionFactory" with the specified user credentials.
<bean id="myTargetConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="java:comp/env/jms/mycf"/> </bean> <bean id="myConnectionFactory" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter"> <property name="targetConnectionFactory" ref="myTargetConnectionFactory"/> <property name="username" value="myusername"/> <property name="password" value="mypassword"/> </bean>
If the "username" is empty, this proxy will simply delegate to the standard
createConnection()
method of the target ConnectionFactory. This can be used to keep a UserCredentialsConnectionFactoryAdapter bean definition just for the option of implicitly passing in user credentials if the particular target ConnectionFactory requires it.- 从以下版本开始:
- 1.2
- 作者:
- Juergen Hoeller
- 另请参阅:
createConnection()
,createQueueConnection()
,createTopicConnection()
构造器概要
构造器 构造器 说明 UserCredentialsConnectionFactoryAdapter()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
afterPropertiesSet()
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.Connection
createConnection()
Determine whether there are currently thread-bound credentials, using them if available, falling back to the statically specified username and password (i.e. values of the bean properties) else.Connection
createConnection(String username, String password)
Delegate the call straight to the target ConnectionFactory.QueueConnection
createQueueConnection()
Determine whether there are currently thread-bound credentials, using them if available, falling back to the statically specified username and password (i.e. values of the bean properties) else.QueueConnection
createQueueConnection(String username, String password)
Delegate the call straight to the target QueueConnectionFactory.TopicConnection
createTopicConnection()
Determine whether there are currently thread-bound credentials, using them if available, falling back to the statically specified username and password (i.e. values of the bean properties) else.TopicConnection
createTopicConnection(String username, String password)
Delegate the call straight to the target TopicConnectionFactory.protected Connection
doCreateConnection(String username, String password)
This implementation delegates to thecreateConnection(username, password)
method of the target ConnectionFactory, passing in the specified user credentials.protected QueueConnection
doCreateQueueConnection(String username, String password)
This implementation delegates to thecreateQueueConnection(username, password)
method of the target QueueConnectionFactory, passing in the specified user credentials.protected TopicConnection
doCreateTopicConnection(String username, String password)
This implementation delegates to thecreateTopicConnection(username, password)
method of the target TopicConnectionFactory, passing in the specified user credentials.void
removeCredentialsFromCurrentThread()
Remove any user credentials for this proxy from the current thread.void
setCredentialsForCurrentThread(String username, String password)
Set user credententials for this proxy and the current thread.void
setPassword(String password)
Set the password that this adapter should use for retrieving Connections.void
setTargetConnectionFactory(ConnectionFactory targetConnectionFactory)
Set the target ConnectionFactory that this ConnectionFactory should delegate to.void
setUsername(String username)
Set the username that this adapter should use for retrieving Connections.
构造器详细资料
UserCredentialsConnectionFactoryAdapter
public UserCredentialsConnectionFactoryAdapter()
方法详细资料
setTargetConnectionFactory
public void setTargetConnectionFactory(ConnectionFactory targetConnectionFactory)
Set the target ConnectionFactory that this ConnectionFactory should delegate to.
setUsername
public void setUsername(String username)
Set the username that this adapter should use for retrieving Connections. Default is no specific user.
setPassword
public void setPassword(String password)
Set the password that this adapter should use for retrieving Connections. Default is no specific password.
afterPropertiesSet
public void afterPropertiesSet()
从接口复制的说明:InitializingBean
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
- 指定者:
afterPropertiesSet
在接口中InitializingBean
setCredentialsForCurrentThread
public void setCredentialsForCurrentThread(String username, String password)
Set user credententials for this proxy and the current thread. The given username and password will be applied to all subsequentcreateConnection()
calls on this ConnectionFactory proxy.This will override any statically specified user credentials, that is, values of the "username" and "password" bean properties.
- 参数:
username
- the username to applypassword
- the password to apply- 另请参阅:
removeCredentialsFromCurrentThread()
removeCredentialsFromCurrentThread
public void removeCredentialsFromCurrentThread()
Remove any user credentials for this proxy from the current thread. Statically specified user credentials apply again afterwards.
createConnection
public final Connection createConnection() throws JMSException
Determine whether there are currently thread-bound credentials, using them if available, falling back to the statically specified username and password (i.e. values of the bean properties) else.
createConnection
public Connection createConnection(String username, String password) throws JMSException
Delegate the call straight to the target ConnectionFactory.- 指定者:
createConnection
在接口中ConnectionFactory
- 抛出:
JMSException
doCreateConnection
protected Connection doCreateConnection(String username, String password) throws JMSException
This implementation delegates to thecreateConnection(username, password)
method of the target ConnectionFactory, passing in the specified user credentials. If the specified username is empty, it will simply delegate to the standardcreateConnection()
method of the target ConnectionFactory.- 参数:
username
- the username to usepassword
- the password to use- 返回:
- the Connection
- 抛出:
JMSException
- 另请参阅:
ConnectionFactory.createConnection(String, String)
,ConnectionFactory.createConnection()
createQueueConnection
public final QueueConnection createQueueConnection() throws JMSException
Determine whether there are currently thread-bound credentials, using them if available, falling back to the statically specified username and password (i.e. values of the bean properties) else.
createQueueConnection
public QueueConnection createQueueConnection(String username, String password) throws JMSException
Delegate the call straight to the target QueueConnectionFactory.
doCreateQueueConnection
protected QueueConnection doCreateQueueConnection(String username, String password) throws JMSException
This implementation delegates to thecreateQueueConnection(username, password)
method of the target QueueConnectionFactory, passing in the specified user credentials. If the specified username is empty, it will simply delegate to the standardcreateQueueConnection()
method of the target ConnectionFactory.- 参数:
username
- the username to usepassword
- the password to use- 返回:
- the Connection
- 抛出:
JMSException
- 另请参阅:
QueueConnectionFactory.createQueueConnection(String, String)
,QueueConnectionFactory.createQueueConnection()
createTopicConnection
public final TopicConnection createTopicConnection() throws JMSException
Determine whether there are currently thread-bound credentials, using them if available, falling back to the statically specified username and password (i.e. values of the bean properties) else.
createTopicConnection
public TopicConnection createTopicConnection(String username, String password) throws JMSException
Delegate the call straight to the target TopicConnectionFactory.
doCreateTopicConnection
protected TopicConnection doCreateTopicConnection(String username, String password) throws JMSException
This implementation delegates to thecreateTopicConnection(username, password)
method of the target TopicConnectionFactory, passing in the specified user credentials. If the specified username is empty, it will simply delegate to the standardcreateTopicConnection()
method of the target ConnectionFactory.- 参数:
username
- the username to usepassword
- the password to use- 返回:
- the Connection
- 抛出:
JMSException
- 另请参阅:
TopicConnectionFactory.createTopicConnection(String, String)
,TopicConnectionFactory.createTopicConnection()