diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/util/CommandAgent.java b/activemq-broker/src/main/java/org/apache/activemq/broker/util/CommandAgent.java deleted file mode 100644 index 59b7857bf5..0000000000 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/util/CommandAgent.java +++ /dev/null @@ -1,175 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.activemq.broker.util; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.Destination; -import javax.jms.ExceptionListener; -import javax.jms.JMSException; -import javax.jms.MessageConsumer; -import javax.jms.Session; -import org.apache.activemq.ActiveMQConnectionFactory; -import org.apache.activemq.Service; -import org.apache.activemq.advisory.AdvisorySupport; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * An agent which listens to commands on a JMS destination - * - * - * @org.apache.xbean.XBean - */ -public class CommandAgent implements Service, ExceptionListener { - private static final Logger LOG = LoggerFactory.getLogger(CommandAgent.class); - - private String brokerUrl = "vm://localhost"; - private String username; - private String password; - private ConnectionFactory connectionFactory; - private Connection connection; - private Destination commandDestination; - private CommandMessageListener listener; - private Session session; - private MessageConsumer consumer; - - /** - * - * @throws Exception - * @org.apache.xbean.InitMethod - */ - @PostConstruct - public void start() throws Exception { - session = getConnection().createSession(false, Session.AUTO_ACKNOWLEDGE); - listener = new CommandMessageListener(session); - Destination destination = getCommandDestination(); - if (LOG.isDebugEnabled()) { - LOG.debug("Agent subscribing to control destination: " + destination); - } - consumer = session.createConsumer(destination); - consumer.setMessageListener(listener); - } - - /** - * - * @throws Exception - * @org.apache.xbean.DestroyMethod - */ - @PreDestroy - public void stop() throws Exception { - if (consumer != null) { - try { - consumer.close(); - consumer = null; - } catch (JMSException ignored) { - } - } - if (session != null) { - try { - session.close(); - session = null; - } catch (JMSException ignored) { - } - } - if (connection != null) { - try { - connection.close(); - connection = null; - } catch (JMSException ignored) { - } - } - } - - // Properties - // ------------------------------------------------------------------------- - public String getBrokerUrl() { - return brokerUrl; - } - - public void setBrokerUrl(String brokerUrl) { - this.brokerUrl = brokerUrl; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public ConnectionFactory getConnectionFactory() { - if (connectionFactory == null) { - connectionFactory = new ActiveMQConnectionFactory(brokerUrl); - } - return connectionFactory; - } - - public void setConnectionFactory(ConnectionFactory connectionFactory) { - this.connectionFactory = connectionFactory; - } - - public Connection getConnection() throws JMSException { - if (connection == null) { - connection = createConnection(); - connection.setExceptionListener(this); - connection.start(); - } - return connection; - } - - public void setConnection(Connection connection) { - this.connection = connection; - } - - public Destination getCommandDestination() { - if (commandDestination == null) { - commandDestination = createCommandDestination(); - } - return commandDestination; - } - - public void setCommandDestination(Destination commandDestination) { - this.commandDestination = commandDestination; - } - - protected Connection createConnection() throws JMSException { - return getConnectionFactory().createConnection(username, password); - } - - protected Destination createCommandDestination() { - return AdvisorySupport.getAgentDestination(); - } - - public void onException(JMSException exception) { - try { - stop(); - } catch (Exception e) { - } - } -} diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/util/CommandHandler.java b/activemq-broker/src/main/java/org/apache/activemq/broker/util/CommandHandler.java deleted file mode 100644 index 2f2366729d..0000000000 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/util/CommandHandler.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.activemq.broker.util; - -import javax.jms.TextMessage; - -/** - * Represents a processor of text based commands - * - * - */ -public interface CommandHandler { - void processCommand(TextMessage request, TextMessage response) throws Exception; -} diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/util/CommandMessageListener.java b/activemq-broker/src/main/java/org/apache/activemq/broker/util/CommandMessageListener.java deleted file mode 100644 index 5711886bf5..0000000000 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/util/CommandMessageListener.java +++ /dev/null @@ -1,121 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.activemq.broker.util; - -import java.io.IOException; - -import javax.jms.Destination; -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageListener; -import javax.jms.MessageProducer; -import javax.jms.Session; -import javax.jms.TextMessage; - -import org.apache.activemq.command.ActiveMQTextMessage; -import org.apache.activemq.util.FactoryFinder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * - */ -public class CommandMessageListener implements MessageListener { - private static final Logger LOG = LoggerFactory.getLogger(CommandMessageListener.class); - - private Session session; - private MessageProducer producer; - private CommandHandler handler; - - public CommandMessageListener(Session session) { - this.session = session; - } - - public void onMessage(Message message) { - if (LOG.isDebugEnabled()) { - LOG.debug("Received command: " + message); - } - if (message instanceof TextMessage) { - TextMessage request = (TextMessage)message; - try { - Destination replyTo = message.getJMSReplyTo(); - if (replyTo == null) { - LOG.warn("Ignored message as no JMSReplyTo set: " + message); - return; - } - Message response = processCommand(request); - addReplyHeaders(request, response); - getProducer().send(replyTo, response); - } catch (Exception e) { - LOG.error("Failed to process message due to: " + e + ". Message: " + message, e); - } - } else { - LOG.warn("Ignoring invalid message: " + message); - } - } - - protected void addReplyHeaders(TextMessage request, Message response) throws JMSException { - String correlationID = request.getJMSCorrelationID(); - if (correlationID != null) { - response.setJMSCorrelationID(correlationID); - } - } - - /** - * Processes an incoming JMS message returning the response message - */ - public Message processCommand(TextMessage request) throws Exception { - TextMessage response = session.createTextMessage(); - getHandler().processCommand(request, response); - return response; - } - - /** - * Processes an incoming command from a console and returning the text to - * output - */ - public String processCommandText(String line) throws Exception { - TextMessage request = new ActiveMQTextMessage(); - request.setText(line); - TextMessage response = new ActiveMQTextMessage(); - getHandler().processCommand(request, response); - return response.getText(); - } - - public Session getSession() { - return session; - } - - public MessageProducer getProducer() throws JMSException { - if (producer == null) { - producer = getSession().createProducer(null); - } - return producer; - } - - public CommandHandler getHandler() throws IllegalAccessException, IOException, InstantiationException, ClassNotFoundException { - if (handler == null) { - handler = createHandler(); - } - return handler; - } - - private CommandHandler createHandler() throws IllegalAccessException, IOException, ClassNotFoundException, InstantiationException { - FactoryFinder factoryFinder = new FactoryFinder("META-INF/services/org/apache/activemq/broker/"); - return (CommandHandler)factoryFinder.newInstance("agent"); - } -} diff --git a/activemq-console/src/main/java/org/apache/activemq/console/ConsoleCommandHandler.java b/activemq-console/src/main/java/org/apache/activemq/console/ConsoleCommandHandler.java deleted file mode 100644 index 0e4d93256b..0000000000 --- a/activemq-console/src/main/java/org/apache/activemq/console/ConsoleCommandHandler.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.activemq.console; - -import java.io.ByteArrayOutputStream; -import java.util.ArrayList; -import java.util.List; -import java.util.StringTokenizer; - -import javax.jms.TextMessage; - -import org.apache.activemq.broker.util.CommandHandler; -import org.apache.activemq.console.command.ShellCommand; -import org.apache.activemq.console.formatter.CommandShellOutputFormatter; - -/** - * A default implementation of the @{link CommandHandler} interface - * - * - */ -public class ConsoleCommandHandler implements CommandHandler { - - private ShellCommand command = new ShellCommand(true); - - public void processCommand(TextMessage request, TextMessage response) throws Exception { - - ByteArrayOutputStream out = new ByteArrayOutputStream(); - CommandContext ctx = new CommandContext(); - ctx.setFormatter(new CommandShellOutputFormatter(out)); - - // lets turn the text into a list of arguments - String requestText = request.getText(); - - List tokens = tokenize(requestText); - command.setCommandContext(ctx); - command.execute(tokens); - - out.flush(); - byte[] bytes = out.toByteArray(); - - String answer = new String(bytes); - - response.setText(answer); - } - - protected List tokenize(String text) { - List answer = new ArrayList(); - StringTokenizer iter = new StringTokenizer(text); - while (iter.hasMoreTokens()) { - answer.add(iter.nextToken()); - } - return answer; - } -} diff --git a/activemq-console/src/main/java/org/apache/activemq/console/util/SimpleConsole.java b/activemq-console/src/main/java/org/apache/activemq/console/util/SimpleConsole.java deleted file mode 100644 index c660f8a38a..0000000000 --- a/activemq-console/src/main/java/org/apache/activemq/console/util/SimpleConsole.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.activemq.console.util; - -import java.io.BufferedReader; -import java.io.InputStreamReader; - -import org.apache.activemq.broker.util.CommandMessageListener; - -/** - * A simple interactive console which can be used to communicate with a running - * broker assuming that the classpath is fully setup - * - * - */ -public final class SimpleConsole { - - private SimpleConsole() { - } - - public static void main(String[] args) { - CommandMessageListener listener = new CommandMessageListener(null); - - try { - BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); - while (true) { - String line = reader.readLine(); - if (line == null || "quit".equalsIgnoreCase(line)) { - break; - } - line = line.trim(); - if (line.length() == 0) { - continue; - } - - System.out.println(listener.processCommandText(line)); - } - } catch (Exception e) { - System.out.println("Caught: " + e); - e.printStackTrace(); - } - } -} diff --git a/activemq-console/src/main/resources/META-INF/services/org/apache/activemq/broker/agent b/activemq-console/src/main/resources/META-INF/services/org/apache/activemq/broker/agent deleted file mode 100644 index 614b162023..0000000000 --- a/activemq-console/src/main/resources/META-INF/services/org/apache/activemq/broker/agent +++ /dev/null @@ -1,17 +0,0 @@ -## --------------------------------------------------------------------------- -## Licensed to the Apache Software Foundation (ASF) under one or more -## contributor license agreements. See the NOTICE file distributed with -## this work for additional information regarding copyright ownership. -## The ASF licenses this file to You under the Apache License, Version 2.0 -## (the "License"); you may not use this file except in compliance with -## the License. You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## --------------------------------------------------------------------------- -class=org.apache.activemq.console.ConsoleCommandHandler diff --git a/assembly/src/sample-conf/activemq-command.xml b/assembly/src/sample-conf/activemq-command.xml deleted file mode 100644 index e1cf9bf06e..0000000000 --- a/assembly/src/sample-conf/activemq-command.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/assembly/src/sample-conf/activemq-security.xml b/assembly/src/sample-conf/activemq-security.xml index 84f1c6dd85..6a1445c623 100644 --- a/assembly/src/sample-conf/activemq-security.xml +++ b/assembly/src/sample-conf/activemq-security.xml @@ -124,12 +124,6 @@ - - -