Return-Path: Delivered-To: apmail-activemq-camel-commits-archive@locus.apache.org Received: (qmail 45871 invoked from network); 10 Nov 2008 15:08:01 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 10 Nov 2008 15:08:01 -0000 Received: (qmail 52934 invoked by uid 500); 10 Nov 2008 15:08:09 -0000 Delivered-To: apmail-activemq-camel-commits-archive@activemq.apache.org Received: (qmail 52906 invoked by uid 500); 10 Nov 2008 15:08:09 -0000 Mailing-List: contact camel-commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: camel-dev@activemq.apache.org Delivered-To: mailing list camel-commits@activemq.apache.org Received: (qmail 52897 invoked by uid 99); 10 Nov 2008 15:08:08 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Nov 2008 07:08:08 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Nov 2008 15:06:57 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 1AF772388999; Mon, 10 Nov 2008 07:07:41 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r712671 - in /activemq/camel/branches/camel-1.x: ./ components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsEndpointConfigurationTest.java Date: Mon, 10 Nov 2008 15:07:40 -0000 To: camel-commits@activemq.apache.org From: ningjiang@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081110150741.1AF772388999@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: ningjiang Date: Mon Nov 10 07:07:40 2008 New Revision: 712671 URL: http://svn.apache.org/viewvc?rev=712671&view=rev Log: Merged revisions 712662 via svnmerge from https://svn.apache.org/repos/asf/activemq/camel/trunk ........ r712662 | ningjiang | 2008-11-10 22:10:16 +0800 (Mon, 10 Nov 2008) | 1 line CAMEL-246 allow the username and password to be specified on the JMSComponent / JMSConfiguration ........ Modified: activemq/camel/branches/camel-1.x/ (props changed) activemq/camel/branches/camel-1.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java activemq/camel/branches/camel-1.x/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsEndpointConfigurationTest.java Propchange: activemq/camel/branches/camel-1.x/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Mon Nov 10 07:07:40 2008 @@ -1 +1 @@ -/activemq/camel/trunk:709850,711200,711206,711219-711220,711523,711531,711756,711784,711859,711874,711962,711971,712064,712119,712148 +/activemq/camel/trunk:709850,711200,711206,711219-711220,711523,711531,711756,711784,711859,711874,711962,711971,712064,712119,712148,712662 Propchange: activemq/camel/branches/camel-1.x/ ------------------------------------------------------------------------------ --- svnmerge-integrated (original) +++ svnmerge-integrated Mon Nov 10 07:07:40 2008 @@ -1 +1 @@ -/activemq/camel/trunk:1-708421,708553-709447,709449-709612,709614-709634,709636-710013,711200,711206,711219-711220,711523,711531,711599,711655-711656,711756,711784,711859,711874,711962,711971,712064,712119,712148 +/activemq/camel/trunk:1-708421,708553-709447,709449-709612,709614-709634,709636-710013,711200,711206,711219-711220,711523,711531,711599,711655-711656,711756,711784,711859,711874,711962,711971,712064,712119,712148,712662 Modified: activemq/camel/branches/camel-1.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java URL: http://svn.apache.org/viewvc/activemq/camel/branches/camel-1.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java?rev=712671&r1=712670&r2=712671&view=diff ============================================================================== --- activemq/camel/branches/camel-1.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java (original) +++ activemq/camel/branches/camel-1.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java Mon Nov 10 07:07:40 2008 @@ -23,6 +23,7 @@ import javax.jms.Session; import org.apache.camel.CamelContext; +import org.apache.camel.CamelException; import org.apache.camel.Endpoint; import org.apache.camel.HeaderFilterStrategyAware; import org.apache.camel.component.jms.requestor.Requestor; @@ -36,6 +37,7 @@ import org.springframework.context.ApplicationContextAware; import org.springframework.core.task.TaskExecutor; import org.springframework.jms.connection.JmsTransactionManager; +import org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter; import org.springframework.jms.core.JmsOperations; import org.springframework.jms.listener.serversession.ServerSessionFactory; import org.springframework.jms.support.converter.MessageConverter; @@ -407,6 +409,20 @@ if (selector != null) { endpoint.setSelector(selector); } + String username = getAndRemoveParameter(parameters, "username", String.class); + String password = getAndRemoveParameter(parameters, "password", String.class); + if (username != null && password != null) { + ConnectionFactory cf = endpoint.getConfiguration().getConnectionFactory(); + UserCredentialsConnectionFactoryAdapter ucfa = new UserCredentialsConnectionFactoryAdapter(); + ucfa.setTargetConnectionFactory(cf); + ucfa.setPassword(password); + ucfa.setUsername(username); + endpoint.getConfiguration().setConnectionFactory(ucfa); + } else { + if (username != null || password != null) { + throw new CamelException("The JmsComponent's username or password is null"); + } + } setProperties(endpoint.getConfiguration(), parameters); return endpoint; } Modified: activemq/camel/branches/camel-1.x/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsEndpointConfigurationTest.java URL: http://svn.apache.org/viewvc/activemq/camel/branches/camel-1.x/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsEndpointConfigurationTest.java?rev=712671&r1=712670&r2=712671&view=diff ============================================================================== --- activemq/camel/branches/camel-1.x/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsEndpointConfigurationTest.java (original) +++ activemq/camel/branches/camel-1.x/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsEndpointConfigurationTest.java Mon Nov 10 07:07:40 2008 @@ -22,9 +22,12 @@ import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.camel.CamelContext; +import org.apache.camel.CamelException; import org.apache.camel.ContextTestSupport; import org.apache.camel.Exchange; import org.apache.camel.Processor; +import org.apache.camel.ResolveEndpointFailedException; +import org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter; import org.springframework.jms.core.JmsOperations; import org.springframework.jms.core.JmsTemplate; import org.springframework.jms.listener.AbstractMessageListenerContainer; @@ -52,6 +55,31 @@ JmsEndpoint endpoint = (JmsEndpoint) resolveMandatoryEndpoint("jms:topic:Foo.Bar?durableSubscriptionName=James&clientId=ABC"); assertDurableSubscriberEndpointIsValid(endpoint); } + + public void testSetUsernameAndPassword() throws Exception { + JmsEndpoint endpoint = (JmsEndpoint) resolveMandatoryEndpoint("jms:topic:Foo.Bar?username=James&password=ABC"); + 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); + } + + public void testNotSetUsernameOrPassword() { + try { + JmsEndpoint endpoint = (JmsEndpoint) resolveMandatoryEndpoint("jms:topic:Foo.Bar?username=James"); + fail("Expect the exception here"); + } catch (ResolveEndpointFailedException exception) { + // Expect the exception here + } + + try { + JmsEndpoint endpoint = (JmsEndpoint) resolveMandatoryEndpoint("jms:topic:Foo.Bar?password=ABC"); + fail("Expect the exception here"); + } catch (ResolveEndpointFailedException exception) { + // Expect the exception here + } + + } public void testSelector() throws Exception { JmsEndpoint endpoint = (JmsEndpoint) resolveMandatoryEndpoint("jms:Foo.Bar?selector=foo%3D'ABC'");