use of org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter in project camel by apache.
the class JmsEndpointConfigurationTest method testSetConnectionFactoryAndUsernameAndPassword.
@Test
public void testSetConnectionFactoryAndUsernameAndPassword() throws Exception {
JmsEndpoint endpoint = resolveMandatoryEndpoint("jms:topic:Foo.Bar?connectionFactory=#myConnectionFactory&username=James&password=ABC", JmsEndpoint.class);
ConnectionFactory cf = endpoint.getConfiguration().getConnectionFactory();
assertNotNull("The connectionFactory should not be null", cf);
assertTrue("The connectionFactory should be the instance of UserCredentialsConnectionFactoryAdapter", cf instanceof UserCredentialsConnectionFactoryAdapter);
}
use of org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter in project camel by apache.
the class JmsEndpointConfigurationTest method testSetUsernameAndPassword.
@Test
public void testSetUsernameAndPassword() throws Exception {
JmsEndpoint endpoint = resolveMandatoryEndpoint("jms:topic:Foo.Bar?username=James&password=ABC", JmsEndpoint.class);
ConnectionFactory cf = endpoint.getConfiguration().getConnectionFactory();
assertNotNull("The connectionFactory should not be null", cf);
assertTrue("The connectionFactory should be the instance of UserCredentialsConnectionFactoryAdapter", cf instanceof UserCredentialsConnectionFactoryAdapter);
}
use of org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter in project camel by apache.
the class JmsComponent method createEndpoint.
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
boolean pubSubDomain = false;
boolean tempDestination = false;
if (ObjectHelper.isNotEmpty(remaining)) {
if (remaining.startsWith(JmsConfiguration.QUEUE_PREFIX)) {
pubSubDomain = false;
remaining = removeStartingCharacters(remaining.substring(JmsConfiguration.QUEUE_PREFIX.length()), '/');
} else if (remaining.startsWith(JmsConfiguration.TOPIC_PREFIX)) {
pubSubDomain = true;
remaining = removeStartingCharacters(remaining.substring(JmsConfiguration.TOPIC_PREFIX.length()), '/');
} else if (remaining.startsWith(JmsConfiguration.TEMP_QUEUE_PREFIX)) {
pubSubDomain = false;
tempDestination = true;
remaining = removeStartingCharacters(remaining.substring(JmsConfiguration.TEMP_QUEUE_PREFIX.length()), '/');
} else if (remaining.startsWith(JmsConfiguration.TEMP_TOPIC_PREFIX)) {
pubSubDomain = true;
tempDestination = true;
remaining = removeStartingCharacters(remaining.substring(JmsConfiguration.TEMP_TOPIC_PREFIX.length()), '/');
}
}
final String subject = convertPathToActualDestination(remaining, parameters);
// lets make sure we copy the configuration as each endpoint can
// customize its own version
JmsConfiguration newConfiguration = getConfiguration().copy();
JmsEndpoint endpoint;
if (pubSubDomain) {
if (tempDestination) {
endpoint = createTemporaryTopicEndpoint(uri, this, subject, newConfiguration);
} else {
endpoint = createTopicEndpoint(uri, this, subject, newConfiguration);
}
} else {
QueueBrowseStrategy strategy = getQueueBrowseStrategy();
if (tempDestination) {
endpoint = createTemporaryQueueEndpoint(uri, this, subject, newConfiguration, strategy);
} else {
endpoint = createQueueEndpoint(uri, this, subject, newConfiguration, strategy);
}
}
// resolve any custom connection factory first
ConnectionFactory cf = resolveAndRemoveReferenceParameter(parameters, "connectionFactory", ConnectionFactory.class);
if (cf != null) {
endpoint.getConfiguration().setConnectionFactory(cf);
}
// if username or password provided then wrap the connection factory
String cfUsername = getAndRemoveParameter(parameters, "username", String.class, getConfiguration().getUsername());
String cfPassword = getAndRemoveParameter(parameters, "password", String.class, getConfiguration().getPassword());
if (cfUsername != null && cfPassword != null) {
cf = endpoint.getConfiguration().getConnectionFactory();
ObjectHelper.notNull(cf, "ConnectionFactory");
LOG.debug("Wrapping existing ConnectionFactory with UserCredentialsConnectionFactoryAdapter using username: {} and password: ******", cfUsername);
UserCredentialsConnectionFactoryAdapter ucfa = new UserCredentialsConnectionFactoryAdapter();
ucfa.setTargetConnectionFactory(cf);
ucfa.setPassword(cfPassword);
ucfa.setUsername(cfUsername);
endpoint.getConfiguration().setConnectionFactory(ucfa);
} else {
// if only username or password was provided then fail
if (cfUsername != null || cfPassword != null) {
if (cfUsername == null) {
throw new IllegalArgumentException("Username must also be provided when using username/password as credentials.");
} else {
throw new IllegalArgumentException("Password must also be provided when using username/password as credentials.");
}
}
}
// jms header strategy
String strategyVal = getAndRemoveParameter(parameters, KEY_FORMAT_STRATEGY_PARAM, String.class);
JmsKeyFormatStrategy strategy = resolveStandardJmsKeyFormatStrategy(strategyVal);
if (strategy != null) {
endpoint.setJmsKeyFormatStrategy(strategy);
} else {
// its not a standard, but a reference
parameters.put(KEY_FORMAT_STRATEGY_PARAM, strategyVal);
endpoint.setJmsKeyFormatStrategy(resolveAndRemoveReferenceParameter(parameters, KEY_FORMAT_STRATEGY_PARAM, JmsKeyFormatStrategy.class));
}
MessageListenerContainerFactory messageListenerContainerFactory = resolveAndRemoveReferenceParameter(parameters, "messageListenerContainerFactoryRef", MessageListenerContainerFactory.class);
if (messageListenerContainerFactory == null) {
messageListenerContainerFactory = resolveAndRemoveReferenceParameter(parameters, "messageListenerContainerFactory", MessageListenerContainerFactory.class);
}
if (messageListenerContainerFactory != null) {
endpoint.setMessageListenerContainerFactory(messageListenerContainerFactory);
}
setProperties(endpoint.getConfiguration(), parameters);
endpoint.setHeaderFilterStrategy(getHeaderFilterStrategy());
return endpoint;
}
Aggregations