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.
| Method from org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter Detail: |
public void afterPropertiesSet() {
if (this.targetConnectionFactory == null) {
throw new IllegalArgumentException("Property 'targetConnectionFactory' is required");
}
}
|
public final Connection createConnection() throws JMSException {
JmsUserCredentials threadCredentials = (JmsUserCredentials) this.threadBoundCredentials.get();
if (threadCredentials != null) {
return doCreateConnection(threadCredentials.username, threadCredentials.password);
}
else {
return doCreateConnection(this.username, this.password);
}
}
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. |
public Connection createConnection(String username,
String password) throws JMSException {
return doCreateConnection(username, password);
}
Delegate the call straight to the target ConnectionFactory. |
public final QueueConnection createQueueConnection() throws JMSException {
JmsUserCredentials threadCredentials = (JmsUserCredentials) this.threadBoundCredentials.get();
if (threadCredentials != null) {
return doCreateQueueConnection(threadCredentials.username, threadCredentials.password);
}
else {
return doCreateQueueConnection(this.username, this.password);
}
}
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. |
public QueueConnection createQueueConnection(String username,
String password) throws JMSException {
return doCreateQueueConnection(username, password);
}
Delegate the call straight to the target QueueConnectionFactory. |
public final TopicConnection createTopicConnection() throws JMSException {
JmsUserCredentials threadCredentials = (JmsUserCredentials) this.threadBoundCredentials.get();
if (threadCredentials != null) {
return doCreateTopicConnection(threadCredentials.username, threadCredentials.password);
}
else {
return doCreateTopicConnection(this.username, this.password);
}
}
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. |
public TopicConnection createTopicConnection(String username,
String password) throws JMSException {
return doCreateTopicConnection(username, password);
}
Delegate the call straight to the target TopicConnectionFactory. |
protected Connection doCreateConnection(String username,
String password) throws JMSException {
Assert.state(this.targetConnectionFactory != null, "'targetConnectionFactory' is required");
if (StringUtils.hasLength(username)) {
return this.targetConnectionFactory.createConnection(username, password);
}
else {
return this.targetConnectionFactory.createConnection();
}
}
This implementation delegates to the createConnection(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 standard
createConnection() method of the target ConnectionFactory. |
protected QueueConnection doCreateQueueConnection(String username,
String password) throws JMSException {
Assert.state(this.targetConnectionFactory != null, "'targetConnectionFactory' is required");
if (!(this.targetConnectionFactory instanceof QueueConnectionFactory)) {
throw new javax.jms.IllegalStateException("'targetConnectionFactory' is not a QueueConnectionFactory");
}
QueueConnectionFactory queueFactory = (QueueConnectionFactory) this.targetConnectionFactory;
if (StringUtils.hasLength(username)) {
return queueFactory.createQueueConnection(username, password);
}
else {
return queueFactory.createQueueConnection();
}
}
This implementation delegates to the createQueueConnection(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 standard
createQueueConnection() method of the target ConnectionFactory. |
protected TopicConnection doCreateTopicConnection(String username,
String password) throws JMSException {
Assert.state(this.targetConnectionFactory != null, "'targetConnectionFactory' is required");
if (!(this.targetConnectionFactory instanceof TopicConnectionFactory)) {
throw new javax.jms.IllegalStateException("'targetConnectionFactory' is not a TopicConnectionFactory");
}
TopicConnectionFactory queueFactory = (TopicConnectionFactory) this.targetConnectionFactory;
if (StringUtils.hasLength(username)) {
return queueFactory.createTopicConnection(username, password);
}
else {
return queueFactory.createTopicConnection();
}
}
This implementation delegates to the createTopicConnection(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 standard
createTopicConnection() method of the target ConnectionFactory. |
public void removeCredentialsFromCurrentThread() {
this.threadBoundCredentials.set(null);
}
Remove any user credentials for this proxy from the current thread.
Statically specified user credentials apply again afterwards. |
public void setCredentialsForCurrentThread(String username,
String password) {
this.threadBoundCredentials.set(new JmsUserCredentials(username, password));
}
Set user credententials for this proxy and the current thread.
The given username and password will be applied to all subsequent
createConnection() calls on this ConnectionFactory proxy.
This will override any statically specified user credentials,
that is, values of the "username" and "password" bean properties. |
public void setPassword(String password) {
this.password = password;
}
Set the password that this adapter should use for retrieving Connections.
Default is no specific password. |
public void setTargetConnectionFactory(ConnectionFactory targetConnectionFactory) {
Assert.notNull(targetConnectionFactory, "'targetConnectionFactory' must not be null");
this.targetConnectionFactory = targetConnectionFactory;
}
Set the target ConnectionFactory that this ConnectionFactory should delegate to. |
public void setUsername(String username) {
this.username = username;
}
Set the username that this adapter should use for retrieving Connections.
Default is no specific user. |