Return-Path: X-Original-To: apmail-activemq-dev-archive@www.apache.org Delivered-To: apmail-activemq-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9724410674 for ; Thu, 11 Jul 2013 16:23:48 +0000 (UTC) Received: (qmail 49565 invoked by uid 500); 11 Jul 2013 16:23:48 -0000 Delivered-To: apmail-activemq-dev-archive@activemq.apache.org Received: (qmail 49341 invoked by uid 500); 11 Jul 2013 16:23:47 -0000 Mailing-List: contact dev-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list dev@activemq.apache.org Received: (qmail 49333 invoked by uid 99); 11 Jul 2013 16:23:46 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Jul 2013 16:23:46 +0000 X-ASF-Spam-Status: No, hits=2.8 required=5.0 tests=HTML_MESSAGE,NORMAL_HTTP_TO_IP,RCVD_IN_DNSWL_LOW,SPF_PASS,URI_HEX,WEIRD_PORT X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of christian.posta@gmail.com designates 209.85.217.171 as permitted sender) Received: from [209.85.217.171] (HELO mail-lb0-f171.google.com) (209.85.217.171) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Jul 2013 16:23:43 +0000 Received: by mail-lb0-f171.google.com with SMTP id 13so6990373lba.30 for ; Thu, 11 Jul 2013 09:23:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=2DTaMsATbh0rDKbkdTSrT/sJKegaNRNG2m7OMcWSOFw=; b=01SNlG4KS2oSbJzXqDNZbxIW+1K9kTqS+WHJ8w+1glOC/x07CvQ52xE7GnYeXRit3d PWFFYAQaioXm02j5tcz+pTTZdCo7VVotkAlY1QLvp0u8DD8uGSeozgvnPERWvaGC092i z4+XhnhKwd+tcZJzW1v7lplI05oKO0LS+TSmwVApM8zERLcwk1VTqX79RMtXhiJDQwQ2 VSuhiv3KRx0hNZb9YmG77/BqTVpLr/ibRRu85Yh1+qAXAeJhcL/8RwzAn9peOrN4ToI4 m2+F26nrK10xZznzh0UYCsqUCHPy3SC/PdghRq/NzZnvRn7RH8IKpT3ZQ8z7DaUwfcq1 gCyA== MIME-Version: 1.0 X-Received: by 10.152.26.40 with SMTP id i8mr16257715lag.22.1373559801327; Thu, 11 Jul 2013 09:23:21 -0700 (PDT) Received: by 10.114.185.37 with HTTP; Thu, 11 Jul 2013 09:23:21 -0700 (PDT) In-Reply-To: <1373469393764-4669091.post@n4.nabble.com> References: <1373469393764-4669091.post@n4.nabble.com> Date: Thu, 11 Jul 2013 12:23:21 -0400 Message-ID: Subject: Re: problems setting username and password on the ActiveMQComponent using Java From: Christian Posta To: dev@activemq.apache.org Content-Type: multipart/alternative; boundary=089e0160bc500937c504e13ed07a X-Virus-Checked: Checked by ClamAV on apache.org --089e0160bc500937c504e13ed07a Content-Type: text/plain; charset=ISO-8859-1 the static method ActiveMQComponent.activeMQComponent(brokerUrl) creates the connection factory and sets it, so the code that uses "userName" and "password" from the JmsConfiguration doesn't get used because the conn factory is already created. You could do it just like you do in the spring file and create the component, and then inject the specific connection factory you want to use. On Wed, Jul 10, 2013 at 11:16 AM, mike_pone wrote: > I need to manually create an authenticated connection to an activemq broker > using only Java. Setting the username and password on the > ActiveMQComponent > does not seem to be working in Java as it does in spring. I have a simple > test program that shows a spring configured ActiveMQComponent and a Java > Configured ActiveMQComponent. Both are connecting to an embedded broker > with the same credentials. The Spring component will work fine and let the > message go through, but the Java configured component throws the following > exception, " java.lang.SecurityException: User name [null] or password is > invalid." > > public class TestApp { > > @Produce(uri = "direct:test") > protected ProducerTemplate template; > @Produce(uri = "direct:test2") > protected ProducerTemplate template2; > > private static final Log log = LogFactory.getLog(TestApp.class); > public static void main(final String[] args) throws Exception { > > log.info("Initializing Spring"); > final ClassPathXmlApplicationContext springContext = new > ClassPathXmlApplicationContext("spring-context.xml"); > springContext.registerShutdownHook(); > final CamelContext camelContext = > springContext.getBean("camelContext", CamelContext.class); > final TestApp app =springContext.getBean("testApp", TestApp.class); > > String brokerUrl = brokerUrl = String.format("%s://%s:%d", "tcp", > "localhost", 61616); > final ActiveMQComponent component = > ActiveMQComponent.activeMQComponent(brokerUrl); > component.setUserName("sa"); > component.setPassword("manager"); > > ActiveMQConfiguration config = (ActiveMQConfiguration) > component.getConfiguration(); > log.info("username : " + config.getUserName()); > log.info("username : " + config.getPassword()); > camelContext.addComponent("activemq2", component); > > //simply creates a route from the direct parameter to the activemq > topic using the passed in activemq prefix. > camelContext.addRoutes(new TestRouteBuilder("activemq", > "direct:test", "topic:test")) ; > camelContext.addRoutes(new TestRouteBuilder("activemq2", > "direct:test2", "topic:test2")) ; > camelContext.start(); > > app.start(); > } > > private void start() throws Exception{ > final String message = new String("hello"); > > log.info("sending first message."); > template.sendBody(message); //works > log.info("first message sent."); > log.info("sending second message."); > template2.sendBody(message); //throws Exception > log.info("second message sent."); > > } > } > > Here is my spring config : > > > xmlns:camel="http://camel.apache.org/schema/spring" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation=" > http://www.springframework.org/schema/beans > http://www.springframework.org/schema/beans/spring-beans.xsd > http://camel.apache.org/schema/spring > http://camel.apache.org/schema/spring/camel-spring.xsd"> > > xmlns:tfm="http://tfm.faa.gov/tfms/TFMS_XIS" id="camelContext" > autoStartup="false" trace="false"> > > > > > > > value="classpath:activemq/activemq-broker.xml" > /> > > > > class="org.apache.activemq.camel.component.ActiveMQComponent" > > > > > > > > > > > > > Here is the config for the embedded broker. I've also tried this with a > standalone broker instance and see the same issue : > > xmlns:amq="http://activemq.apache.org/schema/core" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://www.springframework.org/schema/beans > http://www.springframework.org/schema/beans/spring-beans-2.0.xsd > http://activemq.apache.org/schema/core > http://activemq.apache.org/schema/core/activemq-core.xsd"> > > > brokerName="broker1" dataDirectory="target/activemq-data" > start="false"> > > > > > producerFlowControl="true" > memoryLimit="1mb"> > > > > > producerFlowControl="true" > memoryLimit="1mb"> > > > > > > > > > > > > > > > > > > > > password="manager" > > groups="producers,consumers,admins" /> > > > > > > > > > > read="consumers,admins" admin="admins" /> > > > read="consumers,admins" admin="admins" /> > > > read="admins,publishers,consumers" > > write="admins,publishers,consumers" > > admin="admins,publishers,consumers"/> > > > > > > > > > > > Here is the TestRouteBuilder for completeness sake : > > public final class TestRouteBuilder extends RouteBuilder { > > private final String activeMqPrefix; > private final String from; > private final String to; > > public TestRouteBuilder(final String activeMqPrefix, String from, > String > to) { > this.activeMqPrefix = activeMqPrefix; > this.from=from; > this.to=to; > } > > @Override > public void configure() throws Exception { > from(from).to(activeMqPrefix +":" + to); > } > } > > > > > -- > View this message in context: > http://activemq.2283324.n4.nabble.com/problems-setting-username-and-password-on-the-ActiveMQComponent-using-Java-tp4669091.html > Sent from the ActiveMQ - Dev mailing list archive at Nabble.com. > -- *Christian Posta* http://www.christianposta.com/blog twitter: @christianposta --089e0160bc500937c504e13ed07a--