You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by cs...@apache.org on 2016/07/15 14:13:26 UTC
[1/3] karaf git commit: [KARAF-4624] Karaf component to create
ConnectionFactories out of configs
Repository: karaf
Updated Branches:
refs/heads/master 4854661f0 -> 6d46540ff
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/src/main/java/org/apache/karaf/jms/command/completers/ConnectionFactoriesFileNameCompleter.java
----------------------------------------------------------------------
diff --git a/jms/src/main/java/org/apache/karaf/jms/command/completers/ConnectionFactoriesFileNameCompleter.java b/jms/src/main/java/org/apache/karaf/jms/command/completers/ConnectionFactoriesFileNameCompleter.java
deleted file mode 100644
index c33ff62..0000000
--- a/jms/src/main/java/org/apache/karaf/jms/command/completers/ConnectionFactoriesFileNameCompleter.java
+++ /dev/null
@@ -1,59 +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.karaf.jms.command.completers;
-
-import java.util.List;
-
-import org.apache.karaf.jms.JmsService;
-import org.apache.karaf.shell.api.action.lifecycle.Reference;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.apache.karaf.shell.api.console.CommandLine;
-import org.apache.karaf.shell.api.console.Completer;
-import org.apache.karaf.shell.api.console.Session;
-import org.apache.karaf.shell.support.completers.StringsCompleter;
-
-/**
- * Completer on the JMS connection factory file names.
- */
-@Service
-public class ConnectionFactoriesFileNameCompleter implements Completer {
-
- @Reference
- private JmsService jmsService;
-
- @Override
- public int complete(Session session, CommandLine commandLine, List<String> candidates) {
- StringsCompleter delegate = new StringsCompleter();
- try {
- for (String connectionFactory : jmsService.connectionFactoryFileNames()) {
- delegate.getStrings().add(connectionFactory.replace("connectionfactory-", "").replace(".xml", ""));
- }
- } catch (Exception e) {
- // nothing to do
- }
- return delegate.complete(session, commandLine, candidates);
- }
-
- public JmsService getJmsService() {
- return jmsService;
- }
-
- public void setJmsService(JmsService jmsService) {
- this.jmsService = jmsService;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/src/main/java/org/apache/karaf/jms/command/completers/ConnectionFactoriesNameCompleter.java
----------------------------------------------------------------------
diff --git a/jms/src/main/java/org/apache/karaf/jms/command/completers/ConnectionFactoriesNameCompleter.java b/jms/src/main/java/org/apache/karaf/jms/command/completers/ConnectionFactoriesNameCompleter.java
deleted file mode 100644
index 98f97b3..0000000
--- a/jms/src/main/java/org/apache/karaf/jms/command/completers/ConnectionFactoriesNameCompleter.java
+++ /dev/null
@@ -1,59 +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.karaf.jms.command.completers;
-
-import java.util.List;
-
-import org.apache.karaf.jms.JmsService;
-import org.apache.karaf.shell.api.action.lifecycle.Reference;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.apache.karaf.shell.api.console.CommandLine;
-import org.apache.karaf.shell.api.console.Completer;
-import org.apache.karaf.shell.api.console.Session;
-import org.apache.karaf.shell.support.completers.StringsCompleter;
-
-/**
- * Completer on the JMS connection factories name.
- */
-@Service
-public class ConnectionFactoriesNameCompleter implements Completer {
-
- @Reference
- private JmsService jmsService;
-
- @Override
- public int complete(Session session, CommandLine commandLine, List<String> candidates) {
- StringsCompleter delegate = new StringsCompleter();
- try {
- for (String connectionFactory : jmsService.connectionFactories()) {
- delegate.getStrings().add(connectionFactory);
- }
- } catch (Exception e) {
- // nothing to do
- }
- return delegate.complete(session, commandLine, candidates);
- }
-
- public JmsService getJmsService() {
- return jmsService;
- }
-
- public void setJmsService(JmsService jmsService) {
- this.jmsService = jmsService;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/src/main/java/org/apache/karaf/jms/internal/JmsConnector.java
----------------------------------------------------------------------
diff --git a/jms/src/main/java/org/apache/karaf/jms/internal/JmsConnector.java b/jms/src/main/java/org/apache/karaf/jms/internal/JmsConnector.java
deleted file mode 100644
index 80eb457..0000000
--- a/jms/src/main/java/org/apache/karaf/jms/internal/JmsConnector.java
+++ /dev/null
@@ -1,109 +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.karaf.jms.internal;
-
-import java.io.Closeable;
-import java.io.IOException;
-import java.util.Collection;
-
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.JMSException;
-import javax.jms.Session;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-
-public class JmsConnector implements Closeable {
- private BundleContext bc;
- private ServiceReference<ConnectionFactory> reference;
- private Connection connection;
- private Session session;
- private String connectionFactoryName;
- private String username;
- private String password;
-
- public JmsConnector(BundleContext bc, String connectionFactoryName, String username, String password) throws JMSException {
- this.bc = bc;
- this.connectionFactoryName = connectionFactoryName;
- this.username = username;
- this.password = password;
- }
-
- private ServiceReference<ConnectionFactory> lookupConnectionFactory(String name) {
- Collection<ServiceReference<ConnectionFactory>> references;
- try {
- references = bc.getServiceReferences(ConnectionFactory.class, "(|(osgi.jndi.service.name=" + name + ")(name=" + name + ")(service.id=" + name + "))");
- } catch (InvalidSyntaxException e) {
- throw new RuntimeException("Error finding connection factory service " + name, e);
- }
- if (references == null || references.size() == 0) {
- throw new IllegalArgumentException("No JMS connection factory found for " + name);
- }
- if (references.size() > 1) {
- throw new IllegalArgumentException("Multiple JMS connection factories found for " + name);
- }
- return references.iterator().next();
- }
-
- @Override
- public void close() throws IOException {
- if (session != null) {
- try {
- session.close();
- } catch (JMSException e) {
- // Ignore
- }
- }
- if (connection != null) {
- try {
- connection.close();
- } catch (JMSException e) {
- // Ignore
- }
- }
- if (reference != null) {
- bc.ungetService(reference);
- }
- }
-
- public Connection connect() throws JMSException {
- reference = this.lookupConnectionFactory(connectionFactoryName);
- ConnectionFactory cf = (ConnectionFactory) bc.getService(reference);
- connection = cf.createConnection(username, password);
- connection.start();
- return connection;
- }
-
- public Session createSession() throws JMSException {
- return createSession(Session.AUTO_ACKNOWLEDGE);
- }
-
- public Session createSession(int acknowledgeMode) throws JMSException {
- if (connection == null) {
- connect();
- }
- if (acknowledgeMode == Session.SESSION_TRANSACTED) {
- session = connection.createSession(true, acknowledgeMode);
- } else {
- session = connection.createSession(false, acknowledgeMode);
- }
- return session;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/src/main/java/org/apache/karaf/jms/internal/JmsMBeanImpl.java
----------------------------------------------------------------------
diff --git a/jms/src/main/java/org/apache/karaf/jms/internal/JmsMBeanImpl.java b/jms/src/main/java/org/apache/karaf/jms/internal/JmsMBeanImpl.java
deleted file mode 100644
index e3b7801..0000000
--- a/jms/src/main/java/org/apache/karaf/jms/internal/JmsMBeanImpl.java
+++ /dev/null
@@ -1,164 +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.karaf.jms.internal;
-
-import org.apache.karaf.jms.JmsMBean;
-import org.apache.karaf.jms.JmsMessage;
-import org.apache.karaf.jms.JmsService;
-
-import javax.management.MBeanException;
-import javax.management.openmbean.*;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Default implementation of the JMS MBean.
- */
-public class JmsMBeanImpl implements JmsMBean {
-
- private JmsService jmsService;
-
- @Override
- public List<String> getConnectionfactories() throws MBeanException {
- try {
- return jmsService.connectionFactories();
- } catch (Throwable t) {
- throw new MBeanException(null, t.getMessage());
- }
- }
-
- @Override
- public void create(String name, String type, String url) throws MBeanException {
- try {
- jmsService.create(name, type, url);
- } catch (Throwable t) {
- throw new MBeanException(null, t.getMessage());
- }
- }
-
- @Override
- public void create(String name, String type, String url, String username, String password) throws MBeanException {
- try {
- jmsService.create(name, type, url, username, password);
- } catch (Throwable t) {
- throw new MBeanException(null, t.getMessage());
- }
- }
-
- @Override
- public void delete(String name) throws MBeanException {
- try {
- jmsService.delete(name);
- } catch (Throwable t) {
- throw new MBeanException(null, t.getMessage());
- }
- }
-
- @Override
- public Map<String, String> info(String connectionFactory, String username, String password) throws MBeanException {
- try {
- return jmsService.info(connectionFactory, username, password);
- } catch (Throwable t) {
- throw new MBeanException(null, t.getMessage());
- }
- }
-
- @Override
- public int count(String connectionFactory, String queue, String username, String password) throws MBeanException {
- try {
- return jmsService.count(connectionFactory, queue, username, password);
- } catch (Throwable t) {
- throw new MBeanException(null, t.getMessage());
- }
- }
-
- @Override
- public List<String> queues(String connectionFactory, String username, String password) throws MBeanException {
- try {
- return jmsService.queues(connectionFactory, username, password);
- } catch (Throwable t) {
- throw new MBeanException(null, t.getMessage());
- }
- }
-
- @Override
- public List<String> topics(String connectionFactory, String username, String password) throws MBeanException {
- try {
- return jmsService.topics(connectionFactory, username, password);
- } catch (Throwable t) {
- throw new MBeanException(null, t.getMessage());
- }
- }
-
- @Override
- public void send(String connectionFactory, String queue, String content, String replyTo, String username, String password) throws MBeanException {
- try {
- jmsService.send(connectionFactory, queue, content, replyTo, username, password);
- } catch (Throwable t) {
- throw new MBeanException(null, t.getMessage());
- }
- }
-
- @Override
- public int consume(String connectionFactory, String queue, String selector, String username, String password) throws MBeanException {
- try {
- return jmsService.consume(connectionFactory, queue, selector, username, password);
- } catch (Throwable t) {
- throw new MBeanException(null, t.getMessage());
- }
- }
-
- @Override
- public int move(String connectionFactory, String source, String destination, String selector, String username, String password) throws MBeanException {
- try {
- return jmsService.move(connectionFactory, source, destination, selector, username, password);
- } catch (Throwable t) {
- throw new MBeanException(null, t.getMessage());
- }
- }
-
- @Override
- public TabularData browse(String connectionFactory, String queue, String selector, String username, String password) throws MBeanException {
- try {
- CompositeType type = new CompositeType("message", "JMS Message",
- new String[]{ "id", "content", "charset", "type", "correlation", "delivery", "destination", "expiration", "priority", "redelivered", "replyto", "timestamp" },
- new String[]{ "Message ID", "Content", "Charset", "Type", "Correlation ID", "Delivery Mode", "Destination", "Expiration Date", "Priority", "Redelivered", "Reply-To", "Timestamp" },
- new OpenType[]{ SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.INTEGER, SimpleType.BOOLEAN, SimpleType.STRING, SimpleType.STRING });
- TabularType tableType = new TabularType("messages", "JMS Messages", type, new String[]{ "id" });
- TabularData table = new TabularDataSupport(tableType);
- for (JmsMessage message : getJmsService().browse(connectionFactory, queue, selector, username, password)) {
- CompositeData data = new CompositeDataSupport(type,
- new String[]{ "id", "content", "charset", "type", "correlation", "delivery", "destination", "expiration", "priority", "redelivered", "replyto", "timestamp" },
- new Object[]{ message.getMessageId(), message.getContent(), message.getCharset(), message.getType(), message.getCorrelationID(), message.getDeliveryMode(), message.getDestination(), message.getExpiration(), message.getPriority(), message.isRedelivered(), message.getReplyTo(), message.getTimestamp() }
- );
- table.put(data);
- }
- return table;
- } catch (Throwable t) {
- throw new MBeanException(null, t.getMessage());
- }
- }
-
- public JmsService getJmsService() {
- return jmsService;
- }
-
- public void setJmsService(JmsService jmsService) {
- this.jmsService = jmsService;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/src/main/java/org/apache/karaf/jms/internal/JmsServiceImpl.java
----------------------------------------------------------------------
diff --git a/jms/src/main/java/org/apache/karaf/jms/internal/JmsServiceImpl.java b/jms/src/main/java/org/apache/karaf/jms/internal/JmsServiceImpl.java
deleted file mode 100644
index b4f394a..0000000
--- a/jms/src/main/java/org/apache/karaf/jms/internal/JmsServiceImpl.java
+++ /dev/null
@@ -1,308 +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.karaf.jms.internal;
-
-import org.apache.activemq.ActiveMQConnection;
-import org.apache.activemq.advisory.DestinationSource;
-import org.apache.activemq.command.ActiveMQQueue;
-import org.apache.activemq.command.ActiveMQTopic;
-import org.apache.activemq.pool.PooledConnection;
-import org.apache.karaf.jms.JmsMessage;
-import org.apache.karaf.jms.JmsService;
-import org.apache.karaf.util.TemplateUtils;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-
-import javax.jms.*;
-
-import java.io.*;
-import java.lang.IllegalStateException;
-import java.util.*;
-
-/**
- * Default implementation of the JMS Service.
- */
-public class JmsServiceImpl implements JmsService {
-
- private BundleContext bundleContext;
- private File deployFolder;
-
- public JmsServiceImpl() {
- File karafBase = new File(System.getProperty("karaf.base"));
- deployFolder = new File(karafBase, "deploy");
- }
-
- @Override
- public void create(String name, String type, String url) throws Exception {
- create(name, type, url, null, null);
- }
-
- @Override
- public void create(String name, String type, String url, String username, String password) throws Exception {
- if (!type.equalsIgnoreCase("activemq") && !type.equalsIgnoreCase("webspheremq")) {
- throw new IllegalArgumentException("JMS connection factory type not known");
- }
-
- File outFile = getConnectionFactoryFile(name);
- String template;
- HashMap<String, String> properties = new HashMap<String, String>();
- properties.put("name", name);
-
- if (type.equalsIgnoreCase("activemq")) {
- // activemq
- properties.put("url", url);
- properties.put("username", username);
- properties.put("password", password);
- template = "connectionfactory-activemq.xml";
- } else {
- // webspheremq
- String[] splitted = url.split("/");
- if (splitted.length != 4) {
- throw new IllegalStateException("WebsphereMQ URI should be in the following format: host/port/queuemanager/channel");
- }
-
- properties.put("host", splitted[0]);
- properties.put("port", splitted[1]);
- properties.put("queuemanager", splitted[2]);
- properties.put("channel", splitted[3]);
- template = "connectionfactory-webspheremq.xml";
- }
- InputStream is = this.getClass().getResourceAsStream(template);
- if (is == null) {
- throw new IllegalArgumentException("Template resource " + template + " doesn't exist");
- }
- TemplateUtils.createFromTemplate(outFile, is, properties);
- }
-
- private File getConnectionFactoryFile(String name) {
- return new File(deployFolder, "connectionfactory-" + name + ".xml");
- }
-
- @Override
- public void delete(String name) throws Exception {
- File connectionFactoryFile = getConnectionFactoryFile(name);
- if (!connectionFactoryFile.exists()) {
- throw new IllegalStateException("The JMS connection factory file " + connectionFactoryFile.getPath() + " doesn't exist");
- }
- connectionFactoryFile.delete();
- }
-
- @SuppressWarnings("rawtypes")
- @Override
- public List<String> connectionFactories() throws Exception {
- List<String> connectionFactories = new ArrayList<String>();
- ServiceReference[] references = bundleContext.getServiceReferences(ConnectionFactory.class.getName(), null);
- if (references != null) {
- for (ServiceReference reference : references) {
- if (reference.getProperty("osgi.jndi.service.name") != null) {
- connectionFactories.add((String) reference.getProperty("osgi.jndi.service.name"));
- } else if (reference.getProperty("name") != null) {
- connectionFactories.add((String) reference.getProperty("name"));
- } else {
- connectionFactories.add(reference.getProperty(Constants.SERVICE_ID).toString());
- }
- }
- }
- return connectionFactories;
- }
-
- @Override
- public List<String> connectionFactoryFileNames() throws Exception {
- String[] connectionFactoryFileNames = deployFolder.list(new FilenameFilter() {
-
- @Override
- public boolean accept(File dir, String name) {
- return name.startsWith("connectionfactory-") && name.endsWith(".xml");
- }
- });
-
- return Arrays.asList(connectionFactoryFileNames);
- }
-
- @Override
- public Map<String, String> info(String connectionFactory, String username, String password) throws IOException, JMSException {
- JmsConnector connector = new JmsConnector(bundleContext, connectionFactory, username, password);
- try {
- ConnectionMetaData metaData = connector.connect().getMetaData();
- Map<String, String> map = new HashMap<String, String>();
- map.put("product", metaData.getJMSProviderName());
- map.put("version", metaData.getProviderVersion());
- return map;
- } finally {
- connector.close();
- }
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public int count(String connectionFactory, final String destination, String username, String password) throws IOException, JMSException {
- JmsConnector connector = new JmsConnector(bundleContext, connectionFactory, username, password);
- try {
- Session session = connector.createSession();
- QueueBrowser browser = session.createBrowser(session.createQueue(destination));
- Enumeration<Message> enumeration = browser.getEnumeration();
- int count = 0;
- while (enumeration.hasMoreElements()) {
- enumeration.nextElement();
- count++;
- }
- browser.close();
- return count;
- } finally {
- connector.close();
- }
- }
-
- private DestinationSource getDestinationSource(Connection connection) throws JMSException {
- if (connection instanceof PooledConnection) {
- connection = ((PooledConnection) connection).getConnection();
- }
- if (connection instanceof ActiveMQConnection) {
- return ((ActiveMQConnection) connection).getDestinationSource();
- } else {
- return null;
- }
- }
-
- @Override
- public List<String> queues(String connectionFactory, String username, String password) throws JMSException, IOException {
- JmsConnector connector = new JmsConnector(bundleContext, connectionFactory, username, password);
- try {
- List<String> queues = new ArrayList<String>();
- DestinationSource destinationSource = getDestinationSource(connector.connect());
- if (destinationSource != null) {
- Set<ActiveMQQueue> activeMQQueues = destinationSource.getQueues();
- for (ActiveMQQueue activeMQQueue : activeMQQueues) {
- queues.add(activeMQQueue.getQueueName());
- }
- }
- return queues;
- } finally {
- connector.close();
- }
- }
-
- @Override
- public List<String> topics(String connectionFactory, String username, String password) throws IOException, JMSException {
- JmsConnector connector = new JmsConnector(bundleContext, connectionFactory, username, password);
- try {
- DestinationSource destinationSource = getDestinationSource(connector.connect());
- List<String> topics = new ArrayList<String>();
- if (destinationSource != null) {
- Set<ActiveMQTopic> activeMQTopics = destinationSource.getTopics();
- for (ActiveMQTopic activeMQTopic : activeMQTopics) {
- topics.add(activeMQTopic.getTopicName());
- }
- }
- return topics;
- } finally {
- connector.close();
- }
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public List<JmsMessage> browse(String connectionFactory, final String queue, final String filter,
- String username, String password) throws JMSException, IOException {
- JmsConnector connector = new JmsConnector(bundleContext, connectionFactory, username, password);
- try {
- List<JmsMessage> messages = new ArrayList<JmsMessage>();
- Session session = connector.createSession();
- QueueBrowser browser = session.createBrowser(session.createQueue(queue), filter);
- Enumeration<Message> enumeration = browser.getEnumeration();
- while (enumeration.hasMoreElements()) {
- Message message = enumeration.nextElement();
-
- messages.add(new JmsMessage(message));
- }
- browser.close();
- return messages;
- } finally {
- connector.close();
- }
- }
-
- @Override
- public void send(String connectionFactory, final String queue, final String body, final String replyTo,
- String username, String password) throws IOException, JMSException {
- JmsConnector connector = new JmsConnector(bundleContext, connectionFactory, username, password);
- try {
- Session session = connector.createSession();
- Message message = session.createTextMessage(body);
- if (replyTo != null) {
- message.setJMSReplyTo(session.createQueue(replyTo));
- }
- MessageProducer producer = session.createProducer(session.createQueue(queue));
- producer.send(message);
- producer.close();
- } finally {
- connector.close();
- }
- }
-
- @Override
- public int consume(String connectionFactory, final String queue, final String selector, String username,
- String password) throws Exception {
- JmsConnector connector = new JmsConnector(bundleContext, connectionFactory, username, password);
- try {
- int count = 0;
- Session session = connector.createSession();
- MessageConsumer consumer = session.createConsumer(session.createQueue(queue), selector);
- Message message;
- do {
- message = consumer.receive(5000L);
- if (message != null) {
- count++;
- }
- } while (message != null);
- return count;
- } finally {
- connector.close();
- }
- }
-
- @Override
- public int move(String connectionFactory, final String sourceQueue, final String targetQueue,
- final String selector, String username, String password) throws IOException, JMSException {
- JmsConnector connector = new JmsConnector(bundleContext, connectionFactory, username, password);
- try {
- int count = 0;
- Session session = connector.createSession(Session.SESSION_TRANSACTED);
- MessageConsumer consumer = session.createConsumer(session.createQueue(sourceQueue), selector);
- Message message;
- do {
- message = consumer.receive(5000L);
- if (message != null) {
- MessageProducer producer = session.createProducer(session.createQueue(targetQueue));
- producer.send(message);
- count++;
- }
- } while (message != null);
- session.commit();
- consumer.close();
- return count;
- } finally {
- connector.close();
- }
- }
-
- public void setBundleContext(BundleContext bundleContext) {
- this.bundleContext = bundleContext;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/src/main/resources/OSGI-INF/blueprint/jms-core.xml
----------------------------------------------------------------------
diff --git a/jms/src/main/resources/OSGI-INF/blueprint/jms-core.xml b/jms/src/main/resources/OSGI-INF/blueprint/jms-core.xml
deleted file mode 100644
index c011b6a..0000000
--- a/jms/src/main/resources/OSGI-INF/blueprint/jms-core.xml
+++ /dev/null
@@ -1,55 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- 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.
- -->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
- default-activation="lazy">
-
- <ext:property-placeholder placeholder-prefix="$[" placeholder-suffix="]"/>
-
- <bean id="jmsService" class="org.apache.karaf.jms.internal.JmsServiceImpl">
- <property name="bundleContext" ref="blueprintBundleContext"/>
- </bean>
-
- <service ref="jmsService" interface="org.apache.karaf.jms.JmsService" />
-
- <!-- Management -->
- <bean id="jmsMBeanImpl" class="org.apache.karaf.jms.internal.JmsMBeanImpl">
- <property name="jmsService" ref="jmsService"/>
- </bean>
-
- <service ref="jmsMBeanImpl" auto-export="interfaces">
- <service-properties>
- <entry key="jmx.objectname" value="org.apache.karaf:type=jms,name=$[karaf.name]"/>
- </service-properties>
- </service>
-
- <!-- Lets try to filter passwords out of the logs -->
- <service auto-export="interfaces">
- <bean class="org.apache.karaf.shell.support.RegexCommandLoggingFilter">
- <property name="pattern" value="create +.*?--password ([^ ]+)"/>
- <property name="group" value="2"/>
- </bean>
- </service>
- <service auto-export="interfaces">
- <bean class="org.apache.karaf.shell.support.RegexCommandLoggingFilter">
- <property name="pattern" value="create +.*?-p ([^ ]+)"/>
- <property name="group" value="2"/>
- </bean>
- </service>
-
-</blueprint>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/src/main/resources/OSGI-INF/bundle.info
----------------------------------------------------------------------
diff --git a/jms/src/main/resources/OSGI-INF/bundle.info b/jms/src/main/resources/OSGI-INF/bundle.info
deleted file mode 100644
index 9d83749..0000000
--- a/jms/src/main/resources/OSGI-INF/bundle.info
+++ /dev/null
@@ -1,41 +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.
-#
-#
-h1. Synopsis
-
- ${project.name}
-
- ${project.description}
-
- Maven URL:
- [mvn:${project.groupId}/${project.artifactId}/${project.version}]
-
-h1. Description
-
- This bundle is the core implementation of the JMS service support.
-
- The JMS service allows you to create connection factories, and send/browse/consume messages.
-
-h1. Commands
-
- The bundle contains the following commands:
-\${command-list|jms|indent=8,list,cyan}
-
-h1. See also
-
- JMS - section of the Karaf User Guide
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/src/main/resources/org/apache/karaf/jms/internal/connectionfactory-activemq.xml
----------------------------------------------------------------------
diff --git a/jms/src/main/resources/org/apache/karaf/jms/internal/connectionfactory-activemq.xml b/jms/src/main/resources/org/apache/karaf/jms/internal/connectionfactory-activemq.xml
deleted file mode 100644
index 5627e73..0000000
--- a/jms/src/main/resources/org/apache/karaf/jms/internal/connectionfactory-activemq.xml
+++ /dev/null
@@ -1,46 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- 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.
- -->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
-
- <bean id="activemqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
- <property name="brokerURL" value="${url}" />
- <property name="userName" value="${username}" />
- <property name="password" value="${password}" />
- </bean>
-
- <bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
- <property name="maxConnections" value="8" />
- <property name="connectionFactory" ref="activemqConnectionFactory" />
- </bean>
-
- <bean id="resourceManager" class="org.apache.activemq.pool.ActiveMQResourceManager" init-method="recoverResource">
- <property name="transactionManager" ref="transactionManager" />
- <property name="connectionFactory" ref="activemqConnectionFactory" />
- <property name="resourceName" value="activemq.localhost" />
- </bean>
-
- <reference id="transactionManager" interface="javax.transaction.TransactionManager" />
-
- <service ref="pooledConnectionFactory" interface="javax.jms.ConnectionFactory">
- <service-properties>
- <entry key="name" value="${name}" />
- <entry key="osgi.jndi.service.name" value="jms/${name}" />
- </service-properties>
- </service>
-
-</blueprint>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/src/main/resources/org/apache/karaf/jms/internal/connectionfactory-webspheremq.xml
----------------------------------------------------------------------
diff --git a/jms/src/main/resources/org/apache/karaf/jms/internal/connectionfactory-webspheremq.xml b/jms/src/main/resources/org/apache/karaf/jms/internal/connectionfactory-webspheremq.xml
deleted file mode 100644
index 3123f49..0000000
--- a/jms/src/main/resources/org/apache/karaf/jms/internal/connectionfactory-webspheremq.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- 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.
- -->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
-
- <bean id="wmqConnectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory">
- <property name="transportType" value="1" />
- <property name="hostName" value="${hostname}" />
- <property name="port" value="${port}" />
- <property name="queueManager" value="${queuemanager}" />
- <property name="channel" value="${channel}" />
- <property name="useConnectionPooling" value="true" />
- </bean>
-
- <service ref="wmqConnectionFactory" interface="javax.jms.ConnectionFactory">
- <service-properties>
- <entry key="name" value="${name}"/>
- <entry key="osgi.jndi.service.name" value="jms/${name}"/>
- </service-properties>
- </service>
-
-</blueprint>
\ No newline at end of file
[3/3] karaf git commit: [KARAF-4624] Karaf component to create
ConnectionFactories out of configs
Posted by cs...@apache.org.
[KARAF-4624] Karaf component to create ConnectionFactories out of configs
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/6d46540f
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/6d46540f
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/6d46540f
Branch: refs/heads/master
Commit: 6d46540ff5f4437327de39ecf72846c64063a32c
Parents: 4854661
Author: Christian Schneider <ch...@die-schneider.net>
Authored: Fri Jul 15 16:13:07 2016 +0200
Committer: Christian Schneider <ch...@die-schneider.net>
Committed: Fri Jul 15 16:13:07 2016 +0200
----------------------------------------------------------------------
jms/NOTICE | 71 -----
jms/activemq-cf/.gitignore | 1 +
jms/activemq-cf/pom.xml | 77 +++++
.../activemq/ConnectionFactoryProvider.java | 80 +++++
jms/core/NOTICE | 71 +++++
jms/core/pom.xml | 115 +++++++
.../java/org/apache/karaf/jms/JmsMBean.java | 165 ++++++++++
.../java/org/apache/karaf/jms/JmsMessage.java | 164 ++++++++++
.../java/org/apache/karaf/jms/JmsService.java | 171 ++++++++++
.../apache/karaf/jms/command/BrowseCommand.java | 104 +++++++
.../jms/command/ConnectionFactoriesCommand.java | 45 +++
.../karaf/jms/command/ConsumeCommand.java | 40 +++
.../apache/karaf/jms/command/CountCommand.java | 41 +++
.../apache/karaf/jms/command/CreateCommand.java | 52 ++++
.../apache/karaf/jms/command/DeleteCommand.java | 40 +++
.../apache/karaf/jms/command/InfoCommand.java | 46 +++
.../karaf/jms/command/JmsCommandSupport.java | 36 +++
.../command/JmsConnectionCommandSupport.java | 39 +++
.../apache/karaf/jms/command/MoveCommand.java | 44 +++
.../apache/karaf/jms/command/QueuesCommand.java | 43 +++
.../apache/karaf/jms/command/SendCommand.java | 44 +++
.../apache/karaf/jms/command/TopicsCommand.java | 43 +++
.../ConnectionFactoriesFileNameCompleter.java | 59 ++++
.../ConnectionFactoriesNameCompleter.java | 59 ++++
.../apache/karaf/jms/internal/JmsConnector.java | 109 +++++++
.../apache/karaf/jms/internal/JmsMBeanImpl.java | 164 ++++++++++
.../karaf/jms/internal/JmsServiceImpl.java | 308 +++++++++++++++++++
.../resources/OSGI-INF/blueprint/jms-core.xml | 55 ++++
.../src/main/resources/OSGI-INF/bundle.info | 41 +++
.../jms/internal/connectionfactory-activemq.xml | 46 +++
.../internal/connectionfactory-webspheremq.xml | 36 +++
jms/pom.xml | 93 +-----
.../java/org/apache/karaf/jms/JmsMBean.java | 165 ----------
.../java/org/apache/karaf/jms/JmsMessage.java | 164 ----------
.../java/org/apache/karaf/jms/JmsService.java | 171 ----------
.../apache/karaf/jms/command/BrowseCommand.java | 104 -------
.../jms/command/ConnectionFactoriesCommand.java | 45 ---
.../karaf/jms/command/ConsumeCommand.java | 40 ---
.../apache/karaf/jms/command/CountCommand.java | 41 ---
.../apache/karaf/jms/command/CreateCommand.java | 52 ----
.../apache/karaf/jms/command/DeleteCommand.java | 40 ---
.../apache/karaf/jms/command/InfoCommand.java | 46 ---
.../karaf/jms/command/JmsCommandSupport.java | 36 ---
.../command/JmsConnectionCommandSupport.java | 39 ---
.../apache/karaf/jms/command/MoveCommand.java | 44 ---
.../apache/karaf/jms/command/QueuesCommand.java | 43 ---
.../apache/karaf/jms/command/SendCommand.java | 44 ---
.../apache/karaf/jms/command/TopicsCommand.java | 43 ---
.../ConnectionFactoriesFileNameCompleter.java | 59 ----
.../ConnectionFactoriesNameCompleter.java | 59 ----
.../apache/karaf/jms/internal/JmsConnector.java | 109 -------
.../apache/karaf/jms/internal/JmsMBeanImpl.java | 164 ----------
.../karaf/jms/internal/JmsServiceImpl.java | 308 -------------------
.../resources/OSGI-INF/blueprint/jms-core.xml | 55 ----
jms/src/main/resources/OSGI-INF/bundle.info | 41 ---
.../jms/internal/connectionfactory-activemq.xml | 46 ---
.../internal/connectionfactory-webspheremq.xml | 36 ---
57 files changed, 2347 insertions(+), 2149 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/NOTICE
----------------------------------------------------------------------
diff --git a/jms/NOTICE b/jms/NOTICE
deleted file mode 100644
index b70f1f9..0000000
--- a/jms/NOTICE
+++ /dev/null
@@ -1,71 +0,0 @@
-Apache Karaf
-Copyright 2010-2014 The Apache Software Foundation
-
-
-I. Included Software
-
-This product includes software developed at
-The Apache Software Foundation (http://www.apache.org/).
-Licensed under the Apache License 2.0.
-
-This product uses software developed at
-The OSGi Alliance (http://www.osgi.org/).
-Copyright (c) OSGi Alliance (2000, 2010).
-Licensed under the Apache License 2.0.
-
-This product includes software developed at
-OW2 (http://www.ow2.org/).
-Licensed under the BSD License.
-
-This product includes software developed at
-OPS4J (http://www.ops4j.org/).
-Licensed under the Apache License 2.0.
-
-This product includes software developed at
-Eclipse Foundation (http://www.eclipse.org/).
-Licensed under the EPL.
-
-This product includes software written by
-Antony Lesuisse.
-Licensed under Public Domain.
-
-
-II. Used Software
-
-This product uses software developed at
-FUSE Source (http://www.fusesource.org/).
-Licensed under the Apache License 2.0.
-
-This product uses software developed at
-AOP Alliance (http://aopalliance.sourceforge.net/).
-Licensed under the Public Domain.
-
-This product uses software developed at
-Tanuki Software (http://www.tanukisoftware.com/).
-Licensed under the Apache License 2.0.
-
-This product uses software developed at
-Jasypt (http://jasypt.sourceforge.net/).
-Licensed under the Apache License 2.0.
-
-This product uses software developed at
-JLine (http://jline.sourceforge.net).
-Licensed under the BSD License.
-
-This product uses software developed at
-SLF4J (http://www.slf4j.org/).
-Licensed under the MIT License.
-
-This product uses software developed at
-SpringSource (http://www.springsource.org/).
-Licensed under the Apache License 2.0.
-
-This product includes software from http://www.json.org.
-Copyright (c) 2002 JSON.org
-
-
-III. License Summary
-- Apache License 2.0
-- BSD License
-- EPL License
-- MIT License
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/activemq-cf/.gitignore
----------------------------------------------------------------------
diff --git a/jms/activemq-cf/.gitignore b/jms/activemq-cf/.gitignore
new file mode 100644
index 0000000..b83d222
--- /dev/null
+++ b/jms/activemq-cf/.gitignore
@@ -0,0 +1 @@
+/target/
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/activemq-cf/pom.xml
----------------------------------------------------------------------
diff --git a/jms/activemq-cf/pom.xml b/jms/activemq-cf/pom.xml
new file mode 100644
index 0000000..605e527
--- /dev/null
+++ b/jms/activemq-cf/pom.xml
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <!--
+
+ 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.
+ -->
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.karaf</groupId>
+ <artifactId>karaf</artifactId>
+ <version>4.1.0-SNAPSHOT</version>
+ <relativePath>../../parent/pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.apache.karaf.jms</groupId>
+ <artifactId>org.apache.karaf.jms.activemq-cf</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Karaf :: JMS :: ActiveMQ Connection Factory</name>
+ <description>Creates ACTIVEMQ ConnectionFactory services from config</description>
+
+ <properties>
+ <appendedResourcesDirectory>${basedir}/../../etc/appended-resources</appendedResourcesDirectory>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-client</artifactId>
+ <version>5.13.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-jms-pool</artifactId>
+ <version>5.13.3</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Private-Package>
+ org.apache.karaf.activemq
+ </Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/activemq-cf/src/main/java/org/apache/karaf/activemq/ConnectionFactoryProvider.java
----------------------------------------------------------------------
diff --git a/jms/activemq-cf/src/main/java/org/apache/karaf/activemq/ConnectionFactoryProvider.java b/jms/activemq-cf/src/main/java/org/apache/karaf/activemq/ConnectionFactoryProvider.java
new file mode 100644
index 0000000..574c346
--- /dev/null
+++ b/jms/activemq-cf/src/main/java/org/apache/karaf/activemq/ConnectionFactoryProvider.java
@@ -0,0 +1,80 @@
+/*
+ * 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.karaf.activemq;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import javax.jms.ConnectionFactory;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.jms.pool.PooledConnectionFactory;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.ConfigurationPolicy;
+import org.osgi.service.component.annotations.Deactivate;
+
+@Component //
+( //
+ configurationPid = "org.apache.karaf.activemq", //
+ immediate = true, //
+ configurationPolicy = ConfigurationPolicy.REQUIRE //
+)
+public class ConnectionFactoryProvider {
+
+ private static final String OSGI_JNDI_SERVICE_NAME = "osgi.jndi.service.name";
+ private ServiceRegistration<ConnectionFactory> reg;
+
+ @Activate
+ public void create(ComponentContext compContext) {
+ BundleContext context = compContext.getBundleContext();
+ Dictionary<String, Object> config = compContext.getProperties();
+ String brokerURL = getString(config, "url", "tcp://localhost:61616");
+ String jndiName = getString(config, OSGI_JNDI_SERVICE_NAME, "jms/local");
+ String userName = getString(config, "userName", null);
+ String password = getString(config, "password", null);
+ long expiryTimeout = new Long(getString(config, "expiryTimeout", "0"));
+ int idleTimeout = new Integer(getString(config, "idleTimeout", "30000"));
+ int maxConnections = new Integer(getString(config, "maxConnections", "8"));
+ ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(brokerURL);
+ if (userName != null) {
+ cf.setUserName(userName);
+ cf.setPassword(password);
+ }
+ PooledConnectionFactory pcf = new PooledConnectionFactory();
+ pcf.setConnectionFactory(cf);
+ pcf.setExpiryTimeout(expiryTimeout);
+ pcf.setIdleTimeout(idleTimeout);
+ pcf.setMaxConnections(maxConnections);
+ Dictionary<String, String> props = new Hashtable<String, String>();
+ props.put(OSGI_JNDI_SERVICE_NAME, jndiName);
+ reg = context.registerService(ConnectionFactory.class, pcf, props);
+ }
+
+ @Deactivate
+ public void deactivate() {
+ reg.unregister();
+ }
+
+ private String getString(Dictionary<String, Object> config, String key, String defaultValue) {
+ Object value = config.get(key);
+ return value != null ? value.toString() : defaultValue;
+ }
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/NOTICE
----------------------------------------------------------------------
diff --git a/jms/core/NOTICE b/jms/core/NOTICE
new file mode 100644
index 0000000..b70f1f9
--- /dev/null
+++ b/jms/core/NOTICE
@@ -0,0 +1,71 @@
+Apache Karaf
+Copyright 2010-2014 The Apache Software Foundation
+
+
+I. Included Software
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+The OSGi Alliance (http://www.osgi.org/).
+Copyright (c) OSGi Alliance (2000, 2010).
+Licensed under the Apache License 2.0.
+
+This product includes software developed at
+OW2 (http://www.ow2.org/).
+Licensed under the BSD License.
+
+This product includes software developed at
+OPS4J (http://www.ops4j.org/).
+Licensed under the Apache License 2.0.
+
+This product includes software developed at
+Eclipse Foundation (http://www.eclipse.org/).
+Licensed under the EPL.
+
+This product includes software written by
+Antony Lesuisse.
+Licensed under Public Domain.
+
+
+II. Used Software
+
+This product uses software developed at
+FUSE Source (http://www.fusesource.org/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+AOP Alliance (http://aopalliance.sourceforge.net/).
+Licensed under the Public Domain.
+
+This product uses software developed at
+Tanuki Software (http://www.tanukisoftware.com/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+Jasypt (http://jasypt.sourceforge.net/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+JLine (http://jline.sourceforge.net).
+Licensed under the BSD License.
+
+This product uses software developed at
+SLF4J (http://www.slf4j.org/).
+Licensed under the MIT License.
+
+This product uses software developed at
+SpringSource (http://www.springsource.org/).
+Licensed under the Apache License 2.0.
+
+This product includes software from http://www.json.org.
+Copyright (c) 2002 JSON.org
+
+
+III. License Summary
+- Apache License 2.0
+- BSD License
+- EPL License
+- MIT License
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/pom.xml
----------------------------------------------------------------------
diff --git a/jms/core/pom.xml b/jms/core/pom.xml
new file mode 100644
index 0000000..30513fb
--- /dev/null
+++ b/jms/core/pom.xml
@@ -0,0 +1,115 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <!--
+
+ 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.
+ -->
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.karaf</groupId>
+ <artifactId>karaf</artifactId>
+ <version>4.1.0-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.apache.karaf.jms</groupId>
+ <artifactId>org.apache.karaf.jms.core</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Karaf :: JMS :: Core</name>
+ <description>This bundle provides core implementation of the JMS service.</description>
+
+ <properties>
+ <appendedResourcesDirectory>${basedir}/../../etc/appended-resources</appendedResourcesDirectory>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jms_1.1_spec</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-pool</artifactId>
+ <version>5.9.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf</groupId>
+ <artifactId>org.apache.karaf.util</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.shell</groupId>
+ <artifactId>org.apache.karaf.shell.core</artifactId>
+ <optional>true</optional>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>${project.basedir}/src/main/resources</directory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>${project.basedir}/src/main/resources</directory>
+ <filtering>true</filtering>
+ <includes>
+ <include>**/*.info</include>
+ </includes>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.karaf.tooling</groupId>
+ <artifactId>karaf-services-maven-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.karaf.jms
+ </Export-Package>
+ <Import-Package>
+ org.apache.activemq*;resolution:=optional,
+ *
+ </Import-Package>
+ <Private-Package>
+ org.apache.karaf.jms.command,
+ org.apache.karaf.jms.command.completers,
+ org.apache.karaf.jms.internal,
+ org.apache.karaf.util
+ </Private-Package>
+ <DynamicImport-Package>*</DynamicImport-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/src/main/java/org/apache/karaf/jms/JmsMBean.java
----------------------------------------------------------------------
diff --git a/jms/core/src/main/java/org/apache/karaf/jms/JmsMBean.java b/jms/core/src/main/java/org/apache/karaf/jms/JmsMBean.java
new file mode 100644
index 0000000..d62a9ba
--- /dev/null
+++ b/jms/core/src/main/java/org/apache/karaf/jms/JmsMBean.java
@@ -0,0 +1,165 @@
+/*
+ * 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.karaf.jms;
+
+import javax.management.MBeanException;
+import javax.management.openmbean.TabularData;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * JMS MBean.
+ */
+public interface JmsMBean {
+
+ /**
+ * List the JMS connection factories.
+ *
+ * @return The {@link List} of the JMS connection factories name.
+ * @throws MBeanException If the MBean fails.
+ */
+ List<String> getConnectionfactories() throws MBeanException;
+
+ /**
+ * Create a JMS connection factory.
+ *
+ * @param name The JMS connection factory name.
+ * @param type The JMS connection factory type (ActiveMQ or WebsphereMQ).
+ * @param url The JMS connection factory URL. NB: when type is WebsphereMQ, the URL has the format host/port/queuemanager/channel.
+ * @throws MBeanException If the MBean fails.
+ */
+ void create(String name, String type, String url) throws MBeanException;
+
+ /**
+ * Create a JMS connection factory.
+ *
+ * @param name The JMS connection factory name.
+ * @param type The JMS connection factory type (ActiveMQ or WebsphereMQ).
+ * @param url The JMS connection factory URL. NB: when type is WebsphereMQ, the URL has the format host/port/queuemanager/channel.
+ * @param username The JMS connection factory authentication username.
+ * @param password The JMS connection factory authentication password.
+ * @throws MBeanException If the MBean fails.
+ */
+ void create(String name, String type, String url, String username, String password) throws MBeanException;
+
+ /**
+ * Delete a JMS connection factory.
+ *
+ * @param name The JMS connection factory name.
+ * @throws MBeanException If the MBean fails.
+ */
+ void delete(String name) throws MBeanException;
+
+ /**
+ * Get details about a JMS connection factory.
+ *
+ * @param connectionFactory The JMS connection factory name.
+ * @param username The (optional) username to connect to the JMS broker.
+ * @param password The (optional) password to connect to the JMS broker.
+ * @return A {@link Map} (property/value) containing details.
+ * @throws MBeanException If the MBean fails.
+ */
+ Map<String, String> info(String connectionFactory, String username, String password) throws MBeanException;
+
+ /**
+ * Count the messages on a given JMS queue.
+ *
+ * @param connectionFactory The JMS connection factory name.
+ * @param queue The JMS queue name.
+ * @param username The (optional) username to connect to the JMS broker.
+ * @param password The (optional) password to connect to the JMS broker.
+ * @return The number of messages in the queue.
+ * @throws MBeanException If the MBean fails.
+ */
+ int count(String connectionFactory, String queue, String username, String password) throws MBeanException;
+
+ /**
+ * List the JMS queues.
+ *
+ * @param connectionFactory The JMS connection factory name.
+ * @param username The (optional) username to connect to the JMS broker.
+ * @param password The (optional) password to connect to the JMS broker.
+ * @return The {@link List} of JMS queues.
+ * @throws MBeanException If the MBean fails.
+ */
+ List<String> queues(String connectionFactory, String username, String password) throws MBeanException;
+
+ /**
+ * List the JMS topics.
+ *
+ * @param connectionFactory The JMS connection factory name.
+ * @param username The (optional) username to connect to the JMS broker.
+ * @param password The (optional) password to connect to the JMS broker.
+ * @return The @link List} of JMS topics.
+ * @throws MBeanException If the MBean fails.
+ */
+ List<String> topics(String connectionFactory, String username, String password) throws MBeanException;
+
+ /**
+ * Browse the messages in a JMS queue.
+ *
+ * @param connectionFactory The JMS connection factory name.
+ * @param queue The JMS queue name.
+ * @param selector A selector to use to browse only certain messages.
+ * @param username The (optional) username to connect to the JMS broker.
+ * @param password The (optional) password to connect to the JMS broker.
+ * @return A {@link TabularData} containing messages details.
+ * @throws MBeanException If the MBean fails.
+ */
+ TabularData browse(String connectionFactory, String queue, String selector, String username, String password) throws MBeanException;
+
+ /**
+ * Send a JMS message to given queue.
+ *
+ * @param connectionFactory The JMS connection factory name.
+ * @param queue The JMS queue name.
+ * @param content The message content.
+ * @param replyTo The message ReplyTo.
+ * @param username The (optional) username to connect to the JMS broker.
+ * @param password The (optional) password to connect to the JMS broker.
+ * @throws MBeanException If the MBean fails.
+ */
+ void send(String connectionFactory, String queue, String content, String replyTo, String username, String password) throws MBeanException;
+
+ /**
+ * Consume JMS messages from a given queue.
+ *
+ * @param connectionFactory The JMS connection factory name.
+ * @param queue The JMS queue name.
+ * @param selector A selector to use to consume only certain messages.
+ * @param username The (optional) username to connect to the JMS broker.
+ * @param password The (optional) password to connect to the JMS broker.
+ * @return The number of messages consumed.
+ * @throws MBeanException If the MBean fails.
+ */
+ int consume(String connectionFactory, String queue, String selector, String username, String password) throws MBeanException;
+
+ /**
+ * Move JMS messages from one queue to another.
+ *
+ * @param connectionFactory The JMS connection factory name.
+ * @param source The source JMS queue name.
+ * @param destination The destination JMS queue name.
+ * @param selector A selector to move only certain messages.
+ * @param username The (optional) username to connect to the JMS broker.
+ * @param password The (optional) password to connect to the JMS broker.
+ * @return The number of messages moved.
+ * @throws MBeanException If the MBean fails.
+ */
+ int move(String connectionFactory, String source, String destination, String selector, String username, String password) throws MBeanException;
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/src/main/java/org/apache/karaf/jms/JmsMessage.java
----------------------------------------------------------------------
diff --git a/jms/core/src/main/java/org/apache/karaf/jms/JmsMessage.java b/jms/core/src/main/java/org/apache/karaf/jms/JmsMessage.java
new file mode 100644
index 0000000..a85af10
--- /dev/null
+++ b/jms/core/src/main/java/org/apache/karaf/jms/JmsMessage.java
@@ -0,0 +1,164 @@
+/*
+ * 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.karaf.jms;
+
+import javax.jms.*;
+import java.io.UnsupportedEncodingException;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Describe a JMS message is more human readable way.
+ */
+public class JmsMessage {
+
+ private Map<String, Object> properties = new HashMap<String, Object>();
+
+ private String content;
+ private String charset = "UTF-8";
+ private String correlationID;
+ private String deliveryMode;
+ private String destination;
+ private String expiration;
+ private String messageId;
+ private int priority;
+ private boolean redelivered;
+ private String replyTo;
+ private String timestamp;
+ private String type;
+
+ public JmsMessage(Message message) {
+ try {
+ initFromMessage(message);
+ } catch (JMSException e) {
+ throw new RuntimeException(e.getMessage(), e);
+ }
+ }
+
+ public void initFromMessage(Message message) throws JMSException {
+ @SuppressWarnings("unchecked")
+ Enumeration<String> names = message.getPropertyNames();
+ while (names.hasMoreElements()) {
+ String key = names.nextElement();
+ Object value = message.getObjectProperty(key);
+ properties.put(key, value);
+ }
+
+ correlationID = message.getJMSCorrelationID();
+ if (message.getJMSDeliveryMode() == DeliveryMode.NON_PERSISTENT) {
+ deliveryMode = "Non Persistent";
+ } else {
+ deliveryMode = "Persistent";
+ }
+ Destination destinationDest = message.getJMSDestination();
+ if (destinationDest != null) {
+ destination = destinationDest.toString();
+ }
+ if (message.getJMSExpiration() > 0) {
+ expiration = new Date(message.getJMSExpiration()).toString();
+ } else {
+ expiration = "Never";
+ }
+ messageId = message.getJMSMessageID();
+ priority = message.getJMSPriority();
+ redelivered = message.getJMSRedelivered();
+ Destination replyToDest = message.getJMSReplyTo();
+ if (replyToDest != null) {
+ replyTo = replyToDest.toString();
+ }
+ if (message.getJMSTimestamp() > 0) {
+ timestamp = new Date(message.getJMSTimestamp()).toString();
+ } else {
+ timestamp = "";
+ }
+ type = message.getJMSType();
+ content = getMessageContent(message);
+ }
+
+
+ private String getMessageContent(Message message) throws JMSException {
+ if (message instanceof TextMessage) {
+ return ((TextMessage) message).getText();
+ } else if (message instanceof BytesMessage) {
+ BytesMessage bMessage = (BytesMessage) message;
+ long length = bMessage.getBodyLength();
+ byte[] content = new byte[(int) length];
+ bMessage.readBytes(content);
+ try {
+ return new String(content, charset);
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e.getMessage(), e);
+ }
+ }
+ return "";
+ }
+
+ public Map<String, Object> getProperties() {
+ return properties;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public String getCharset() {
+ return charset;
+ }
+
+ public String getCorrelationID() {
+ return correlationID;
+ }
+
+ public String getDeliveryMode() {
+ return deliveryMode;
+ }
+
+ public String getDestination() {
+ return destination;
+ }
+
+ public String getExpiration() {
+ return expiration;
+ }
+
+ public String getMessageId() {
+ return messageId;
+ }
+
+ public int getPriority() {
+ return priority;
+ }
+
+ public boolean isRedelivered() {
+ return redelivered;
+ }
+
+ public String getReplyTo() {
+ return replyTo;
+ }
+
+ public String getTimestamp() {
+ return timestamp;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/src/main/java/org/apache/karaf/jms/JmsService.java
----------------------------------------------------------------------
diff --git a/jms/core/src/main/java/org/apache/karaf/jms/JmsService.java b/jms/core/src/main/java/org/apache/karaf/jms/JmsService.java
new file mode 100644
index 0000000..0902e33
--- /dev/null
+++ b/jms/core/src/main/java/org/apache/karaf/jms/JmsService.java
@@ -0,0 +1,171 @@
+/*
+ * 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.karaf.jms;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * JMS Service.
+ */
+public interface JmsService {
+
+ /**
+ * List the JMS connection factories.
+ *
+ * @return The {@link List} of JMS connection factory names.
+ * @throws Exception If the service fails.
+ */
+ List<String> connectionFactories() throws Exception;
+
+ /**
+ * List the JMS connection factories file names.
+ *
+ * @return The {@link List} of JMS connection factory file names.
+ * @throws Exception If the service fails.
+ */
+ List<String> connectionFactoryFileNames() throws Exception;
+
+ /**
+ * Create a new JMS connection factory.
+ *
+ * @param name The JMS connection factory name.
+ * @param type The JMS connection factory type (ActiveMQ, WebsphereMQ, ...).
+ * @param url The JMS URL to use.
+ * @throws Exception If the service fails.
+ */
+ void create(String name, String type, String url) throws Exception;
+
+ /**
+ * Create a new JMS connection factory.
+ *
+ * @param name The JMS connection factory name.
+ * @param type The JMS connection factory type (ActiveMQ, WebsphereMQ, ...).
+ * @param url The JMS URL to use.
+ * @param username The username to use.
+ * @param password The password to use.
+ * @throws Exception If the service fails.
+ */
+ void create(String name, String type, String url, String username, String password) throws Exception;
+
+ /**
+ * Delete a JMS connection factory.
+ *
+ * @param name The JMS connection factory name.
+ * @throws Exception If the service fails.
+ */
+ void delete(String name) throws Exception;
+
+ /**
+ * Get details about a given JMS connection factory.
+ *
+ * @param connectionFactory The JMS connection factory name.
+ * @param username The (optional) username to connect to the JMS broker.
+ * @param password The (optional) password to connect to the JMS broker.
+ * @return A {@link Map} (property/value) containing details.
+ * @throws Exception If the service fails.
+ */
+ Map<String, String> info(String connectionFactory, String username, String password) throws Exception;
+
+ /**
+ * Count the number of messages in a JMS queue.
+ *
+ * @param connectionFactory The JMS connection factory name.
+ * @param queue The queue name.
+ * @param username The (optional) username to connect to the JMS broker.
+ * @param password The (optional) password to connect to the JMS broker.
+ * @return The number of messages in a JMS queue.
+ * @throws Exception If the service fails.
+ */
+ int count(String connectionFactory, String queue, String username, String password) throws Exception;
+
+ /**
+ * List the queues.
+ *
+ * @param connectionFactory The JMS connection factory name.
+ * @param username The (optional) username to connect to the JMS broker.
+ * @param password The (optional) password to connect to the JMS broker.
+ * @return The {@link List} of queues.
+ * @throws Exception If the service fails.
+ */
+ List<String> queues(String connectionFactory, String username, String password) throws Exception;
+
+ /**
+ * List the topics.
+ *
+ * @param connectionFactory The JMS connection factory name.
+ * @param username The (optional) username to connect to the JMS broker.
+ * @param password The (optional) password to connect to the JMS broker.
+ * @return The {@link List} of topics.
+ * @throws Exception If the service fails.
+ */
+ List<String> topics(String connectionFactory, String username, String password) throws Exception;
+
+ /**
+ * Browse a destination.
+ *
+ * @param connectionFactory The JMS connection factory name.
+ * @param queue The queue name.
+ * @param selector The selector.
+ * @param username The (optional) username to connect to the JMS broker.
+ * @param password The (optional) password to connect to the JMS broker.
+ * @return The {@link List} of messages.
+ * @throws Exception If the service fails.
+ */
+ List<JmsMessage> browse(String connectionFactory, String queue, String selector, String username, String password) throws Exception;
+
+ /**
+ * Send a message on the given queue.
+ *
+ * @param connectionFactory The JMS connection factory name.
+ * @param queue The queue name.
+ * @param body The message body.
+ * @param replyTo The message replyTo header.
+ * @param username The (optional) username to connect to the JMS broker.
+ * @param password The (optional) password to connect to the JMS broker.
+ * @throws Exception If the service fails.
+ */
+ void send(String connectionFactory, String queue, String body, String replyTo, String username, String password) throws Exception;
+
+ /**
+ * Consume messages from a given destination.
+ *
+ * @param connectionFactory The JMS connection factory name.
+ * @param queue The queue name.
+ * @param selector The messages selector.
+ * @param username The (optional) username to connect to the JMS broker.
+ * @param password The (optional) password to connect to the JMS broker.
+ * @return The number of messages consumed.
+ * @throws Exception If the service fails.
+ */
+ int consume(String connectionFactory, String queue, String selector, String username, String password) throws Exception;
+
+ /**
+ * Move messages from a destination to another.
+ *
+ * @param connectionFactory The JMS connection factory name.
+ * @param sourceQueue The source queue.
+ * @param targetQueue The target queue.
+ * @param selector The messages selector on the source queue.
+ * @param username The (optional) username to connect to the JMS broker.
+ * @param password The (optional) password to connect to the JMS broker.
+ * @return The number of messages moved.
+ * @throws Exception If the service fails.
+ */
+ int move(String connectionFactory, String sourceQueue, String targetQueue, String selector, String username, String password) throws Exception;
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/src/main/java/org/apache/karaf/jms/command/BrowseCommand.java
----------------------------------------------------------------------
diff --git a/jms/core/src/main/java/org/apache/karaf/jms/command/BrowseCommand.java b/jms/core/src/main/java/org/apache/karaf/jms/command/BrowseCommand.java
new file mode 100644
index 0000000..cb86aa6
--- /dev/null
+++ b/jms/core/src/main/java/org/apache/karaf/jms/command/BrowseCommand.java
@@ -0,0 +1,104 @@
+/*
+ * 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.karaf.jms.command;
+
+import java.util.List;
+
+import org.apache.karaf.jms.JmsMessage;
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Option;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.support.table.ShellTable;
+
+@Command(scope = "jms", name = "browse", description = "Browse a JMS queue")
+@Service
+public class BrowseCommand extends JmsConnectionCommandSupport {
+
+ @Argument(index = 1, name = "queue", description = "The JMS queue to browse", required = true, multiValued = false)
+ String queue;
+
+ @Option(name = "-s", aliases = { "--selector" }, description = "The selector to select the messages to browse", required = false, multiValued = false)
+ String selector;
+
+ @Option(name = "-v", aliases = { "--verbose" }, description = "Display JMS properties", required = false, multiValued = false)
+ boolean verbose = false;
+
+ @Override
+ public Object execute() throws Exception {
+
+ ShellTable table = new ShellTable();
+ table.column("Message ID");
+ table.column("Content").maxSize(80);
+ table.column("Charset");
+ table.column("Type");
+ table.column("Correlation ID");
+ table.column("Delivery Mode");
+ table.column("Destination");
+ table.column("Expiration");
+ table.column("Priority");
+ table.column("Redelivered");
+ table.column("ReplyTo");
+ table.column("Timestamp");
+ if (verbose) {
+ table.column("Properties");
+ }
+
+ List<JmsMessage> messages = getJmsService().browse(connectionFactory, queue, selector, username, password);
+ for (JmsMessage message : messages) {
+ if (verbose) {
+ StringBuilder properties = new StringBuilder();
+ for (String property : message.getProperties().keySet()) {
+ properties.append(property).append("=").append(message.getProperties().get(property)).append("\n");
+ }
+ table.addRow().addContent(
+ message.getMessageId(),
+ message.getContent(),
+ message.getCharset(),
+ message.getType(),
+ message.getCorrelationID(),
+ message.getDeliveryMode(),
+ message.getDestination(),
+ message.getExpiration(),
+ message.getPriority(),
+ message.isRedelivered(),
+ message.getReplyTo(),
+ message.getTimestamp(),
+ properties.toString());
+ } else {
+ table.addRow().addContent(
+ message.getMessageId(),
+ message.getContent(),
+ message.getCharset(),
+ message.getType(),
+ message.getCorrelationID(),
+ message.getDeliveryMode(),
+ message.getDestination(),
+ message.getExpiration(),
+ message.getPriority(),
+ message.isRedelivered(),
+ message.getReplyTo(),
+ message.getTimestamp());
+ }
+ }
+
+ table.print(System.out);
+
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/src/main/java/org/apache/karaf/jms/command/ConnectionFactoriesCommand.java
----------------------------------------------------------------------
diff --git a/jms/core/src/main/java/org/apache/karaf/jms/command/ConnectionFactoriesCommand.java b/jms/core/src/main/java/org/apache/karaf/jms/command/ConnectionFactoriesCommand.java
new file mode 100644
index 0000000..b698336
--- /dev/null
+++ b/jms/core/src/main/java/org/apache/karaf/jms/command/ConnectionFactoriesCommand.java
@@ -0,0 +1,45 @@
+/*
+ * 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.karaf.jms.command;
+
+import java.util.List;
+
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.support.table.ShellTable;
+
+@Command(scope = "jms", name = "connectionfactories", description = "List the JMS connection factories")
+@Service
+public class ConnectionFactoriesCommand extends JmsCommandSupport {
+
+ @Override
+ public Object execute() throws Exception {
+
+ ShellTable table = new ShellTable();
+ table.column("JMS Connection Factory");
+
+ List<String> connectionFactories = getJmsService().connectionFactories();
+ for (String connectionFactory : connectionFactories) {
+ table.addRow().addContent(connectionFactory);
+ }
+
+ table.print(System.out);
+
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/src/main/java/org/apache/karaf/jms/command/ConsumeCommand.java
----------------------------------------------------------------------
diff --git a/jms/core/src/main/java/org/apache/karaf/jms/command/ConsumeCommand.java b/jms/core/src/main/java/org/apache/karaf/jms/command/ConsumeCommand.java
new file mode 100644
index 0000000..cd8caaf
--- /dev/null
+++ b/jms/core/src/main/java/org/apache/karaf/jms/command/ConsumeCommand.java
@@ -0,0 +1,40 @@
+/*
+ * 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.karaf.jms.command;
+
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Option;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+
+@Command(scope = "jms", name = "consume", description = "Consume messages from a JMS queue.")
+@Service
+public class ConsumeCommand extends JmsConnectionCommandSupport {
+
+ @Argument(index = 1, name = "queue", description = "The JMS queue where to consume messages", required = true, multiValued = false)
+ String queue;
+
+ @Option(name = "-s", aliases = { "--selector" }, description = "The selector to use to select the messages to consume", required = false, multiValued = false)
+ String selector;
+
+ @Override
+ public Object execute() throws Exception {
+ System.out.println(getJmsService().consume(connectionFactory, queue, selector, username, password) + " message(s) consumed");
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/src/main/java/org/apache/karaf/jms/command/CountCommand.java
----------------------------------------------------------------------
diff --git a/jms/core/src/main/java/org/apache/karaf/jms/command/CountCommand.java b/jms/core/src/main/java/org/apache/karaf/jms/command/CountCommand.java
new file mode 100644
index 0000000..576e8dd
--- /dev/null
+++ b/jms/core/src/main/java/org/apache/karaf/jms/command/CountCommand.java
@@ -0,0 +1,41 @@
+/*
+ * 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.karaf.jms.command;
+
+
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.support.table.ShellTable;
+
+@Command(scope = "jms", name = "count", description = "Count the number of messages on a JMS queue.")
+@Service
+public class CountCommand extends JmsConnectionCommandSupport {
+
+ @Argument(index = 1, name = "queue", description = "The JMS queue name", required = true, multiValued = false)
+ String queue;
+
+ @Override
+ public Object execute() throws Exception {
+ ShellTable table = new ShellTable();
+ table.column("Messages Count");
+ table.addRow().addContent(getJmsService().count(connectionFactory, queue, username, password));
+ table.print(System.out);
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/src/main/java/org/apache/karaf/jms/command/CreateCommand.java
----------------------------------------------------------------------
diff --git a/jms/core/src/main/java/org/apache/karaf/jms/command/CreateCommand.java b/jms/core/src/main/java/org/apache/karaf/jms/command/CreateCommand.java
new file mode 100644
index 0000000..fb91416
--- /dev/null
+++ b/jms/core/src/main/java/org/apache/karaf/jms/command/CreateCommand.java
@@ -0,0 +1,52 @@
+/*
+ * 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.karaf.jms.command;
+
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Completion;
+import org.apache.karaf.shell.api.action.Option;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.support.completers.StringsCompleter;
+
+@Command(scope = "jms", name = "create", description = "Create a JMS connection factory.")
+@Service
+public class CreateCommand extends JmsCommandSupport {
+
+ @Argument(index = 0, name = "name", description = "The JMS connection factory name", required = true, multiValued = false)
+ String name;
+
+ @Option(name = "-t", aliases = { "--type" }, description = "The JMS connection factory type (ActiveMQ or WebsphereMQ)", required = false, multiValued = false)
+ @Completion(value = StringsCompleter.class, values = { "activemq", "webspheremq" })
+ String type = "ActiveMQ";
+
+ @Option(name = "--url", description = "URL of the JMS broker. For WebsphereMQ type, the URL is hostname/port/queuemanager/channel", required = false, multiValued = false)
+ String url = "tcp://localhost:61616";
+
+ @Option(name = "-u", aliases = { "--username" }, description = "Username to connect to the JMS broker", required = false, multiValued = false)
+ String username = "karaf";
+
+ @Option(name = "-p", aliases = { "--password" }, description = "Password to connect to the JMS broker", required = false, multiValued = false)
+ String password = "karaf";
+
+ @Override
+ public Object execute() throws Exception {
+ getJmsService().create(name, type, url, username, password);
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/src/main/java/org/apache/karaf/jms/command/DeleteCommand.java
----------------------------------------------------------------------
diff --git a/jms/core/src/main/java/org/apache/karaf/jms/command/DeleteCommand.java b/jms/core/src/main/java/org/apache/karaf/jms/command/DeleteCommand.java
new file mode 100644
index 0000000..cab3123
--- /dev/null
+++ b/jms/core/src/main/java/org/apache/karaf/jms/command/DeleteCommand.java
@@ -0,0 +1,40 @@
+/*
+ * 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.karaf.jms.command;
+
+
+import org.apache.karaf.jms.command.completers.ConnectionFactoriesFileNameCompleter;
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Completion;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+
+@Command(scope = "jms", name = "delete", description = "Delete a JMS connection factory")
+@Service
+public class DeleteCommand extends JmsCommandSupport {
+
+ @Argument(index = 0, name = "name", description = "The JMS connection factory name", required = true, multiValued = false)
+ @Completion(ConnectionFactoriesFileNameCompleter.class)
+ String name;
+
+ @Override
+ public Object execute() throws Exception {
+ getJmsService().delete(name);
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/src/main/java/org/apache/karaf/jms/command/InfoCommand.java
----------------------------------------------------------------------
diff --git a/jms/core/src/main/java/org/apache/karaf/jms/command/InfoCommand.java b/jms/core/src/main/java/org/apache/karaf/jms/command/InfoCommand.java
new file mode 100644
index 0000000..354db39
--- /dev/null
+++ b/jms/core/src/main/java/org/apache/karaf/jms/command/InfoCommand.java
@@ -0,0 +1,46 @@
+/*
+ * 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.karaf.jms.command;
+
+
+import java.util.Map;
+
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.support.table.ShellTable;
+
+@Command(scope = "jms", name = "info", description = "Provides details about a JMS connection factory.")
+@Service
+public class InfoCommand extends JmsConnectionCommandSupport {
+
+ @Override
+ public Object execute() throws Exception {
+ ShellTable table = new ShellTable();
+ table.column("Property");
+ table.column("Value");
+
+ Map<String, String> info = getJmsService().info(connectionFactory, username, password);
+ for (String key : info.keySet()) {
+ table.addRow().addContent(key, info.get(key));
+ }
+
+ table.print(System.out);
+
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/src/main/java/org/apache/karaf/jms/command/JmsCommandSupport.java
----------------------------------------------------------------------
diff --git a/jms/core/src/main/java/org/apache/karaf/jms/command/JmsCommandSupport.java b/jms/core/src/main/java/org/apache/karaf/jms/command/JmsCommandSupport.java
new file mode 100644
index 0000000..2f5df8f
--- /dev/null
+++ b/jms/core/src/main/java/org/apache/karaf/jms/command/JmsCommandSupport.java
@@ -0,0 +1,36 @@
+/*
+ * 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.karaf.jms.command;
+
+import org.apache.karaf.jms.JmsService;
+import org.apache.karaf.shell.api.action.Action;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+
+public abstract class JmsCommandSupport implements Action {
+
+ @Reference
+ private JmsService jmsService;
+
+ public JmsService getJmsService() {
+ return jmsService;
+ }
+
+ public void setJmsService(JmsService jmsService) {
+ this.jmsService = jmsService;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/src/main/java/org/apache/karaf/jms/command/JmsConnectionCommandSupport.java
----------------------------------------------------------------------
diff --git a/jms/core/src/main/java/org/apache/karaf/jms/command/JmsConnectionCommandSupport.java b/jms/core/src/main/java/org/apache/karaf/jms/command/JmsConnectionCommandSupport.java
new file mode 100644
index 0000000..64adfe4
--- /dev/null
+++ b/jms/core/src/main/java/org/apache/karaf/jms/command/JmsConnectionCommandSupport.java
@@ -0,0 +1,39 @@
+/*
+ * 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.karaf.jms.command;
+
+import org.apache.karaf.jms.command.completers.ConnectionFactoriesNameCompleter;
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Completion;
+import org.apache.karaf.shell.api.action.Option;
+
+/**
+ * For commands that need a connection factory and authentication information
+ */
+public abstract class JmsConnectionCommandSupport extends JmsCommandSupport {
+
+ @Argument(index = 0, name = "connectionFactory", description = "The JMS connection factory name", required = true, multiValued = false)
+ @Completion(ConnectionFactoriesNameCompleter.class)
+ String connectionFactory;
+
+ @Option(name = "-u", aliases = { "--username" }, description = "Username to connect to the JMS broker", required = false, multiValued = false)
+ String username = "karaf";
+
+ @Option(name = "-p", aliases = { "--password" }, description = "Password to connect to the JMS broker", required = false, multiValued = false)
+ String password = "karaf";
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/src/main/java/org/apache/karaf/jms/command/MoveCommand.java
----------------------------------------------------------------------
diff --git a/jms/core/src/main/java/org/apache/karaf/jms/command/MoveCommand.java b/jms/core/src/main/java/org/apache/karaf/jms/command/MoveCommand.java
new file mode 100644
index 0000000..a4c8d12
--- /dev/null
+++ b/jms/core/src/main/java/org/apache/karaf/jms/command/MoveCommand.java
@@ -0,0 +1,44 @@
+/*
+ * 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.karaf.jms.command;
+
+
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Option;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+
+@Command(scope = "jms", name = "move", description = "Move messages from one JMS queue to another one.")
+@Service
+public class MoveCommand extends JmsConnectionCommandSupport {
+
+ @Argument(index = 1, name = "source", description = "The source JMS queue", required = true, multiValued = false)
+ String source;
+
+ @Argument(index = 2, name = "destination", description = "The destination JMS queue", required = true, multiValued = false)
+ String destination;
+
+ @Option(name = "-s", aliases = { "--selector" }, description = "Selector to move only some messages", required = false, multiValued = false)
+ String selector;
+
+ @Override
+ public Object execute() throws Exception {
+ System.out.println(getJmsService().move(connectionFactory, source, destination, selector, username, password) + " message(s) moved");
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/src/main/java/org/apache/karaf/jms/command/QueuesCommand.java
----------------------------------------------------------------------
diff --git a/jms/core/src/main/java/org/apache/karaf/jms/command/QueuesCommand.java b/jms/core/src/main/java/org/apache/karaf/jms/command/QueuesCommand.java
new file mode 100644
index 0000000..7cf1dac
--- /dev/null
+++ b/jms/core/src/main/java/org/apache/karaf/jms/command/QueuesCommand.java
@@ -0,0 +1,43 @@
+/*
+ * 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.karaf.jms.command;
+
+
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.support.table.ShellTable;
+
+@Command(scope = "jms", name = "queues", description = "List the JMS queues.")
+@Service
+public class QueuesCommand extends JmsConnectionCommandSupport {
+
+ @Override
+ public Object execute() throws Exception {
+ ShellTable table = new ShellTable();
+
+ table.column("JMS Queues");
+
+ for (String queue : getJmsService().queues(connectionFactory, username, password)) {
+ table.addRow().addContent(queue);
+ }
+
+ table.print(System.out);
+
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/src/main/java/org/apache/karaf/jms/command/SendCommand.java
----------------------------------------------------------------------
diff --git a/jms/core/src/main/java/org/apache/karaf/jms/command/SendCommand.java b/jms/core/src/main/java/org/apache/karaf/jms/command/SendCommand.java
new file mode 100644
index 0000000..63d3f4a
--- /dev/null
+++ b/jms/core/src/main/java/org/apache/karaf/jms/command/SendCommand.java
@@ -0,0 +1,44 @@
+/*
+ * 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.karaf.jms.command;
+
+
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Option;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+
+@Command(scope = "jms", name = "send", description = "Send a message to ")
+@Service
+public class SendCommand extends JmsConnectionCommandSupport {
+
+ @Argument(index = 1, name = "queue", description = "The JMS queue name", required = true, multiValued = false)
+ String queue;
+
+ @Argument(index = 2, name = "message", description = "The JMS message content", required = true, multiValued = false)
+ String message;
+
+ @Option(name = "-r", aliases = { "--replyTo" }, description = "Set the message ReplyTo", required = false, multiValued = false)
+ String replyTo;
+
+ @Override
+ public Object execute() throws Exception {
+ getJmsService().send(connectionFactory, queue, message, replyTo, username, password);
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/src/main/java/org/apache/karaf/jms/command/TopicsCommand.java
----------------------------------------------------------------------
diff --git a/jms/core/src/main/java/org/apache/karaf/jms/command/TopicsCommand.java b/jms/core/src/main/java/org/apache/karaf/jms/command/TopicsCommand.java
new file mode 100644
index 0000000..b583bc4
--- /dev/null
+++ b/jms/core/src/main/java/org/apache/karaf/jms/command/TopicsCommand.java
@@ -0,0 +1,43 @@
+/*
+ * 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.karaf.jms.command;
+
+
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.support.table.ShellTable;
+
+@Command(scope = "jms", name = "topics", description = "List the JMS topics.")
+@Service
+public class TopicsCommand extends JmsConnectionCommandSupport {
+
+ @Override
+ public Object execute() throws Exception {
+ ShellTable table = new ShellTable();
+
+ table.column("JMS Topics");
+
+ for (String topic : getJmsService().topics(connectionFactory, username, password)) {
+ table.addRow().addContent(topic);
+ }
+
+ table.print(System.out);
+
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/src/main/java/org/apache/karaf/jms/command/completers/ConnectionFactoriesFileNameCompleter.java
----------------------------------------------------------------------
diff --git a/jms/core/src/main/java/org/apache/karaf/jms/command/completers/ConnectionFactoriesFileNameCompleter.java b/jms/core/src/main/java/org/apache/karaf/jms/command/completers/ConnectionFactoriesFileNameCompleter.java
new file mode 100644
index 0000000..c33ff62
--- /dev/null
+++ b/jms/core/src/main/java/org/apache/karaf/jms/command/completers/ConnectionFactoriesFileNameCompleter.java
@@ -0,0 +1,59 @@
+/*
+ * 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.karaf.jms.command.completers;
+
+import java.util.List;
+
+import org.apache.karaf.jms.JmsService;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.api.console.CommandLine;
+import org.apache.karaf.shell.api.console.Completer;
+import org.apache.karaf.shell.api.console.Session;
+import org.apache.karaf.shell.support.completers.StringsCompleter;
+
+/**
+ * Completer on the JMS connection factory file names.
+ */
+@Service
+public class ConnectionFactoriesFileNameCompleter implements Completer {
+
+ @Reference
+ private JmsService jmsService;
+
+ @Override
+ public int complete(Session session, CommandLine commandLine, List<String> candidates) {
+ StringsCompleter delegate = new StringsCompleter();
+ try {
+ for (String connectionFactory : jmsService.connectionFactoryFileNames()) {
+ delegate.getStrings().add(connectionFactory.replace("connectionfactory-", "").replace(".xml", ""));
+ }
+ } catch (Exception e) {
+ // nothing to do
+ }
+ return delegate.complete(session, commandLine, candidates);
+ }
+
+ public JmsService getJmsService() {
+ return jmsService;
+ }
+
+ public void setJmsService(JmsService jmsService) {
+ this.jmsService = jmsService;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/src/main/java/org/apache/karaf/jms/command/completers/ConnectionFactoriesNameCompleter.java
----------------------------------------------------------------------
diff --git a/jms/core/src/main/java/org/apache/karaf/jms/command/completers/ConnectionFactoriesNameCompleter.java b/jms/core/src/main/java/org/apache/karaf/jms/command/completers/ConnectionFactoriesNameCompleter.java
new file mode 100644
index 0000000..98f97b3
--- /dev/null
+++ b/jms/core/src/main/java/org/apache/karaf/jms/command/completers/ConnectionFactoriesNameCompleter.java
@@ -0,0 +1,59 @@
+/*
+ * 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.karaf.jms.command.completers;
+
+import java.util.List;
+
+import org.apache.karaf.jms.JmsService;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.api.console.CommandLine;
+import org.apache.karaf.shell.api.console.Completer;
+import org.apache.karaf.shell.api.console.Session;
+import org.apache.karaf.shell.support.completers.StringsCompleter;
+
+/**
+ * Completer on the JMS connection factories name.
+ */
+@Service
+public class ConnectionFactoriesNameCompleter implements Completer {
+
+ @Reference
+ private JmsService jmsService;
+
+ @Override
+ public int complete(Session session, CommandLine commandLine, List<String> candidates) {
+ StringsCompleter delegate = new StringsCompleter();
+ try {
+ for (String connectionFactory : jmsService.connectionFactories()) {
+ delegate.getStrings().add(connectionFactory);
+ }
+ } catch (Exception e) {
+ // nothing to do
+ }
+ return delegate.complete(session, commandLine, candidates);
+ }
+
+ public JmsService getJmsService() {
+ return jmsService;
+ }
+
+ public void setJmsService(JmsService jmsService) {
+ this.jmsService = jmsService;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/src/main/java/org/apache/karaf/jms/internal/JmsConnector.java
----------------------------------------------------------------------
diff --git a/jms/core/src/main/java/org/apache/karaf/jms/internal/JmsConnector.java b/jms/core/src/main/java/org/apache/karaf/jms/internal/JmsConnector.java
new file mode 100644
index 0000000..80eb457
--- /dev/null
+++ b/jms/core/src/main/java/org/apache/karaf/jms/internal/JmsConnector.java
@@ -0,0 +1,109 @@
+/*
+ * 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.karaf.jms.internal;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.Collection;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.Session;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+public class JmsConnector implements Closeable {
+ private BundleContext bc;
+ private ServiceReference<ConnectionFactory> reference;
+ private Connection connection;
+ private Session session;
+ private String connectionFactoryName;
+ private String username;
+ private String password;
+
+ public JmsConnector(BundleContext bc, String connectionFactoryName, String username, String password) throws JMSException {
+ this.bc = bc;
+ this.connectionFactoryName = connectionFactoryName;
+ this.username = username;
+ this.password = password;
+ }
+
+ private ServiceReference<ConnectionFactory> lookupConnectionFactory(String name) {
+ Collection<ServiceReference<ConnectionFactory>> references;
+ try {
+ references = bc.getServiceReferences(ConnectionFactory.class, "(|(osgi.jndi.service.name=" + name + ")(name=" + name + ")(service.id=" + name + "))");
+ } catch (InvalidSyntaxException e) {
+ throw new RuntimeException("Error finding connection factory service " + name, e);
+ }
+ if (references == null || references.size() == 0) {
+ throw new IllegalArgumentException("No JMS connection factory found for " + name);
+ }
+ if (references.size() > 1) {
+ throw new IllegalArgumentException("Multiple JMS connection factories found for " + name);
+ }
+ return references.iterator().next();
+ }
+
+ @Override
+ public void close() throws IOException {
+ if (session != null) {
+ try {
+ session.close();
+ } catch (JMSException e) {
+ // Ignore
+ }
+ }
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (JMSException e) {
+ // Ignore
+ }
+ }
+ if (reference != null) {
+ bc.ungetService(reference);
+ }
+ }
+
+ public Connection connect() throws JMSException {
+ reference = this.lookupConnectionFactory(connectionFactoryName);
+ ConnectionFactory cf = (ConnectionFactory) bc.getService(reference);
+ connection = cf.createConnection(username, password);
+ connection.start();
+ return connection;
+ }
+
+ public Session createSession() throws JMSException {
+ return createSession(Session.AUTO_ACKNOWLEDGE);
+ }
+
+ public Session createSession(int acknowledgeMode) throws JMSException {
+ if (connection == null) {
+ connect();
+ }
+ if (acknowledgeMode == Session.SESSION_TRANSACTED) {
+ session = connection.createSession(true, acknowledgeMode);
+ } else {
+ session = connection.createSession(false, acknowledgeMode);
+ }
+ return session;
+ }
+
+}
[2/3] karaf git commit: [KARAF-4624] Karaf component to create
ConnectionFactories out of configs
Posted by cs...@apache.org.
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/src/main/java/org/apache/karaf/jms/internal/JmsMBeanImpl.java
----------------------------------------------------------------------
diff --git a/jms/core/src/main/java/org/apache/karaf/jms/internal/JmsMBeanImpl.java b/jms/core/src/main/java/org/apache/karaf/jms/internal/JmsMBeanImpl.java
new file mode 100644
index 0000000..e3b7801
--- /dev/null
+++ b/jms/core/src/main/java/org/apache/karaf/jms/internal/JmsMBeanImpl.java
@@ -0,0 +1,164 @@
+/*
+ * 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.karaf.jms.internal;
+
+import org.apache.karaf.jms.JmsMBean;
+import org.apache.karaf.jms.JmsMessage;
+import org.apache.karaf.jms.JmsService;
+
+import javax.management.MBeanException;
+import javax.management.openmbean.*;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Default implementation of the JMS MBean.
+ */
+public class JmsMBeanImpl implements JmsMBean {
+
+ private JmsService jmsService;
+
+ @Override
+ public List<String> getConnectionfactories() throws MBeanException {
+ try {
+ return jmsService.connectionFactories();
+ } catch (Throwable t) {
+ throw new MBeanException(null, t.getMessage());
+ }
+ }
+
+ @Override
+ public void create(String name, String type, String url) throws MBeanException {
+ try {
+ jmsService.create(name, type, url);
+ } catch (Throwable t) {
+ throw new MBeanException(null, t.getMessage());
+ }
+ }
+
+ @Override
+ public void create(String name, String type, String url, String username, String password) throws MBeanException {
+ try {
+ jmsService.create(name, type, url, username, password);
+ } catch (Throwable t) {
+ throw new MBeanException(null, t.getMessage());
+ }
+ }
+
+ @Override
+ public void delete(String name) throws MBeanException {
+ try {
+ jmsService.delete(name);
+ } catch (Throwable t) {
+ throw new MBeanException(null, t.getMessage());
+ }
+ }
+
+ @Override
+ public Map<String, String> info(String connectionFactory, String username, String password) throws MBeanException {
+ try {
+ return jmsService.info(connectionFactory, username, password);
+ } catch (Throwable t) {
+ throw new MBeanException(null, t.getMessage());
+ }
+ }
+
+ @Override
+ public int count(String connectionFactory, String queue, String username, String password) throws MBeanException {
+ try {
+ return jmsService.count(connectionFactory, queue, username, password);
+ } catch (Throwable t) {
+ throw new MBeanException(null, t.getMessage());
+ }
+ }
+
+ @Override
+ public List<String> queues(String connectionFactory, String username, String password) throws MBeanException {
+ try {
+ return jmsService.queues(connectionFactory, username, password);
+ } catch (Throwable t) {
+ throw new MBeanException(null, t.getMessage());
+ }
+ }
+
+ @Override
+ public List<String> topics(String connectionFactory, String username, String password) throws MBeanException {
+ try {
+ return jmsService.topics(connectionFactory, username, password);
+ } catch (Throwable t) {
+ throw new MBeanException(null, t.getMessage());
+ }
+ }
+
+ @Override
+ public void send(String connectionFactory, String queue, String content, String replyTo, String username, String password) throws MBeanException {
+ try {
+ jmsService.send(connectionFactory, queue, content, replyTo, username, password);
+ } catch (Throwable t) {
+ throw new MBeanException(null, t.getMessage());
+ }
+ }
+
+ @Override
+ public int consume(String connectionFactory, String queue, String selector, String username, String password) throws MBeanException {
+ try {
+ return jmsService.consume(connectionFactory, queue, selector, username, password);
+ } catch (Throwable t) {
+ throw new MBeanException(null, t.getMessage());
+ }
+ }
+
+ @Override
+ public int move(String connectionFactory, String source, String destination, String selector, String username, String password) throws MBeanException {
+ try {
+ return jmsService.move(connectionFactory, source, destination, selector, username, password);
+ } catch (Throwable t) {
+ throw new MBeanException(null, t.getMessage());
+ }
+ }
+
+ @Override
+ public TabularData browse(String connectionFactory, String queue, String selector, String username, String password) throws MBeanException {
+ try {
+ CompositeType type = new CompositeType("message", "JMS Message",
+ new String[]{ "id", "content", "charset", "type", "correlation", "delivery", "destination", "expiration", "priority", "redelivered", "replyto", "timestamp" },
+ new String[]{ "Message ID", "Content", "Charset", "Type", "Correlation ID", "Delivery Mode", "Destination", "Expiration Date", "Priority", "Redelivered", "Reply-To", "Timestamp" },
+ new OpenType[]{ SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.INTEGER, SimpleType.BOOLEAN, SimpleType.STRING, SimpleType.STRING });
+ TabularType tableType = new TabularType("messages", "JMS Messages", type, new String[]{ "id" });
+ TabularData table = new TabularDataSupport(tableType);
+ for (JmsMessage message : getJmsService().browse(connectionFactory, queue, selector, username, password)) {
+ CompositeData data = new CompositeDataSupport(type,
+ new String[]{ "id", "content", "charset", "type", "correlation", "delivery", "destination", "expiration", "priority", "redelivered", "replyto", "timestamp" },
+ new Object[]{ message.getMessageId(), message.getContent(), message.getCharset(), message.getType(), message.getCorrelationID(), message.getDeliveryMode(), message.getDestination(), message.getExpiration(), message.getPriority(), message.isRedelivered(), message.getReplyTo(), message.getTimestamp() }
+ );
+ table.put(data);
+ }
+ return table;
+ } catch (Throwable t) {
+ throw new MBeanException(null, t.getMessage());
+ }
+ }
+
+ public JmsService getJmsService() {
+ return jmsService;
+ }
+
+ public void setJmsService(JmsService jmsService) {
+ this.jmsService = jmsService;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/src/main/java/org/apache/karaf/jms/internal/JmsServiceImpl.java
----------------------------------------------------------------------
diff --git a/jms/core/src/main/java/org/apache/karaf/jms/internal/JmsServiceImpl.java b/jms/core/src/main/java/org/apache/karaf/jms/internal/JmsServiceImpl.java
new file mode 100644
index 0000000..b4f394a
--- /dev/null
+++ b/jms/core/src/main/java/org/apache/karaf/jms/internal/JmsServiceImpl.java
@@ -0,0 +1,308 @@
+/*
+ * 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.karaf.jms.internal;
+
+import org.apache.activemq.ActiveMQConnection;
+import org.apache.activemq.advisory.DestinationSource;
+import org.apache.activemq.command.ActiveMQQueue;
+import org.apache.activemq.command.ActiveMQTopic;
+import org.apache.activemq.pool.PooledConnection;
+import org.apache.karaf.jms.JmsMessage;
+import org.apache.karaf.jms.JmsService;
+import org.apache.karaf.util.TemplateUtils;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+
+import javax.jms.*;
+
+import java.io.*;
+import java.lang.IllegalStateException;
+import java.util.*;
+
+/**
+ * Default implementation of the JMS Service.
+ */
+public class JmsServiceImpl implements JmsService {
+
+ private BundleContext bundleContext;
+ private File deployFolder;
+
+ public JmsServiceImpl() {
+ File karafBase = new File(System.getProperty("karaf.base"));
+ deployFolder = new File(karafBase, "deploy");
+ }
+
+ @Override
+ public void create(String name, String type, String url) throws Exception {
+ create(name, type, url, null, null);
+ }
+
+ @Override
+ public void create(String name, String type, String url, String username, String password) throws Exception {
+ if (!type.equalsIgnoreCase("activemq") && !type.equalsIgnoreCase("webspheremq")) {
+ throw new IllegalArgumentException("JMS connection factory type not known");
+ }
+
+ File outFile = getConnectionFactoryFile(name);
+ String template;
+ HashMap<String, String> properties = new HashMap<String, String>();
+ properties.put("name", name);
+
+ if (type.equalsIgnoreCase("activemq")) {
+ // activemq
+ properties.put("url", url);
+ properties.put("username", username);
+ properties.put("password", password);
+ template = "connectionfactory-activemq.xml";
+ } else {
+ // webspheremq
+ String[] splitted = url.split("/");
+ if (splitted.length != 4) {
+ throw new IllegalStateException("WebsphereMQ URI should be in the following format: host/port/queuemanager/channel");
+ }
+
+ properties.put("host", splitted[0]);
+ properties.put("port", splitted[1]);
+ properties.put("queuemanager", splitted[2]);
+ properties.put("channel", splitted[3]);
+ template = "connectionfactory-webspheremq.xml";
+ }
+ InputStream is = this.getClass().getResourceAsStream(template);
+ if (is == null) {
+ throw new IllegalArgumentException("Template resource " + template + " doesn't exist");
+ }
+ TemplateUtils.createFromTemplate(outFile, is, properties);
+ }
+
+ private File getConnectionFactoryFile(String name) {
+ return new File(deployFolder, "connectionfactory-" + name + ".xml");
+ }
+
+ @Override
+ public void delete(String name) throws Exception {
+ File connectionFactoryFile = getConnectionFactoryFile(name);
+ if (!connectionFactoryFile.exists()) {
+ throw new IllegalStateException("The JMS connection factory file " + connectionFactoryFile.getPath() + " doesn't exist");
+ }
+ connectionFactoryFile.delete();
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public List<String> connectionFactories() throws Exception {
+ List<String> connectionFactories = new ArrayList<String>();
+ ServiceReference[] references = bundleContext.getServiceReferences(ConnectionFactory.class.getName(), null);
+ if (references != null) {
+ for (ServiceReference reference : references) {
+ if (reference.getProperty("osgi.jndi.service.name") != null) {
+ connectionFactories.add((String) reference.getProperty("osgi.jndi.service.name"));
+ } else if (reference.getProperty("name") != null) {
+ connectionFactories.add((String) reference.getProperty("name"));
+ } else {
+ connectionFactories.add(reference.getProperty(Constants.SERVICE_ID).toString());
+ }
+ }
+ }
+ return connectionFactories;
+ }
+
+ @Override
+ public List<String> connectionFactoryFileNames() throws Exception {
+ String[] connectionFactoryFileNames = deployFolder.list(new FilenameFilter() {
+
+ @Override
+ public boolean accept(File dir, String name) {
+ return name.startsWith("connectionfactory-") && name.endsWith(".xml");
+ }
+ });
+
+ return Arrays.asList(connectionFactoryFileNames);
+ }
+
+ @Override
+ public Map<String, String> info(String connectionFactory, String username, String password) throws IOException, JMSException {
+ JmsConnector connector = new JmsConnector(bundleContext, connectionFactory, username, password);
+ try {
+ ConnectionMetaData metaData = connector.connect().getMetaData();
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("product", metaData.getJMSProviderName());
+ map.put("version", metaData.getProviderVersion());
+ return map;
+ } finally {
+ connector.close();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public int count(String connectionFactory, final String destination, String username, String password) throws IOException, JMSException {
+ JmsConnector connector = new JmsConnector(bundleContext, connectionFactory, username, password);
+ try {
+ Session session = connector.createSession();
+ QueueBrowser browser = session.createBrowser(session.createQueue(destination));
+ Enumeration<Message> enumeration = browser.getEnumeration();
+ int count = 0;
+ while (enumeration.hasMoreElements()) {
+ enumeration.nextElement();
+ count++;
+ }
+ browser.close();
+ return count;
+ } finally {
+ connector.close();
+ }
+ }
+
+ private DestinationSource getDestinationSource(Connection connection) throws JMSException {
+ if (connection instanceof PooledConnection) {
+ connection = ((PooledConnection) connection).getConnection();
+ }
+ if (connection instanceof ActiveMQConnection) {
+ return ((ActiveMQConnection) connection).getDestinationSource();
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public List<String> queues(String connectionFactory, String username, String password) throws JMSException, IOException {
+ JmsConnector connector = new JmsConnector(bundleContext, connectionFactory, username, password);
+ try {
+ List<String> queues = new ArrayList<String>();
+ DestinationSource destinationSource = getDestinationSource(connector.connect());
+ if (destinationSource != null) {
+ Set<ActiveMQQueue> activeMQQueues = destinationSource.getQueues();
+ for (ActiveMQQueue activeMQQueue : activeMQQueues) {
+ queues.add(activeMQQueue.getQueueName());
+ }
+ }
+ return queues;
+ } finally {
+ connector.close();
+ }
+ }
+
+ @Override
+ public List<String> topics(String connectionFactory, String username, String password) throws IOException, JMSException {
+ JmsConnector connector = new JmsConnector(bundleContext, connectionFactory, username, password);
+ try {
+ DestinationSource destinationSource = getDestinationSource(connector.connect());
+ List<String> topics = new ArrayList<String>();
+ if (destinationSource != null) {
+ Set<ActiveMQTopic> activeMQTopics = destinationSource.getTopics();
+ for (ActiveMQTopic activeMQTopic : activeMQTopics) {
+ topics.add(activeMQTopic.getTopicName());
+ }
+ }
+ return topics;
+ } finally {
+ connector.close();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public List<JmsMessage> browse(String connectionFactory, final String queue, final String filter,
+ String username, String password) throws JMSException, IOException {
+ JmsConnector connector = new JmsConnector(bundleContext, connectionFactory, username, password);
+ try {
+ List<JmsMessage> messages = new ArrayList<JmsMessage>();
+ Session session = connector.createSession();
+ QueueBrowser browser = session.createBrowser(session.createQueue(queue), filter);
+ Enumeration<Message> enumeration = browser.getEnumeration();
+ while (enumeration.hasMoreElements()) {
+ Message message = enumeration.nextElement();
+
+ messages.add(new JmsMessage(message));
+ }
+ browser.close();
+ return messages;
+ } finally {
+ connector.close();
+ }
+ }
+
+ @Override
+ public void send(String connectionFactory, final String queue, final String body, final String replyTo,
+ String username, String password) throws IOException, JMSException {
+ JmsConnector connector = new JmsConnector(bundleContext, connectionFactory, username, password);
+ try {
+ Session session = connector.createSession();
+ Message message = session.createTextMessage(body);
+ if (replyTo != null) {
+ message.setJMSReplyTo(session.createQueue(replyTo));
+ }
+ MessageProducer producer = session.createProducer(session.createQueue(queue));
+ producer.send(message);
+ producer.close();
+ } finally {
+ connector.close();
+ }
+ }
+
+ @Override
+ public int consume(String connectionFactory, final String queue, final String selector, String username,
+ String password) throws Exception {
+ JmsConnector connector = new JmsConnector(bundleContext, connectionFactory, username, password);
+ try {
+ int count = 0;
+ Session session = connector.createSession();
+ MessageConsumer consumer = session.createConsumer(session.createQueue(queue), selector);
+ Message message;
+ do {
+ message = consumer.receive(5000L);
+ if (message != null) {
+ count++;
+ }
+ } while (message != null);
+ return count;
+ } finally {
+ connector.close();
+ }
+ }
+
+ @Override
+ public int move(String connectionFactory, final String sourceQueue, final String targetQueue,
+ final String selector, String username, String password) throws IOException, JMSException {
+ JmsConnector connector = new JmsConnector(bundleContext, connectionFactory, username, password);
+ try {
+ int count = 0;
+ Session session = connector.createSession(Session.SESSION_TRANSACTED);
+ MessageConsumer consumer = session.createConsumer(session.createQueue(sourceQueue), selector);
+ Message message;
+ do {
+ message = consumer.receive(5000L);
+ if (message != null) {
+ MessageProducer producer = session.createProducer(session.createQueue(targetQueue));
+ producer.send(message);
+ count++;
+ }
+ } while (message != null);
+ session.commit();
+ consumer.close();
+ return count;
+ } finally {
+ connector.close();
+ }
+ }
+
+ public void setBundleContext(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/src/main/resources/OSGI-INF/blueprint/jms-core.xml
----------------------------------------------------------------------
diff --git a/jms/core/src/main/resources/OSGI-INF/blueprint/jms-core.xml b/jms/core/src/main/resources/OSGI-INF/blueprint/jms-core.xml
new file mode 100644
index 0000000..c011b6a
--- /dev/null
+++ b/jms/core/src/main/resources/OSGI-INF/blueprint/jms-core.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+ -->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
+ default-activation="lazy">
+
+ <ext:property-placeholder placeholder-prefix="$[" placeholder-suffix="]"/>
+
+ <bean id="jmsService" class="org.apache.karaf.jms.internal.JmsServiceImpl">
+ <property name="bundleContext" ref="blueprintBundleContext"/>
+ </bean>
+
+ <service ref="jmsService" interface="org.apache.karaf.jms.JmsService" />
+
+ <!-- Management -->
+ <bean id="jmsMBeanImpl" class="org.apache.karaf.jms.internal.JmsMBeanImpl">
+ <property name="jmsService" ref="jmsService"/>
+ </bean>
+
+ <service ref="jmsMBeanImpl" auto-export="interfaces">
+ <service-properties>
+ <entry key="jmx.objectname" value="org.apache.karaf:type=jms,name=$[karaf.name]"/>
+ </service-properties>
+ </service>
+
+ <!-- Lets try to filter passwords out of the logs -->
+ <service auto-export="interfaces">
+ <bean class="org.apache.karaf.shell.support.RegexCommandLoggingFilter">
+ <property name="pattern" value="create +.*?--password ([^ ]+)"/>
+ <property name="group" value="2"/>
+ </bean>
+ </service>
+ <service auto-export="interfaces">
+ <bean class="org.apache.karaf.shell.support.RegexCommandLoggingFilter">
+ <property name="pattern" value="create +.*?-p ([^ ]+)"/>
+ <property name="group" value="2"/>
+ </bean>
+ </service>
+
+</blueprint>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/src/main/resources/OSGI-INF/bundle.info
----------------------------------------------------------------------
diff --git a/jms/core/src/main/resources/OSGI-INF/bundle.info b/jms/core/src/main/resources/OSGI-INF/bundle.info
new file mode 100644
index 0000000..9d83749
--- /dev/null
+++ b/jms/core/src/main/resources/OSGI-INF/bundle.info
@@ -0,0 +1,41 @@
+#
+#
+# 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.
+#
+#
+h1. Synopsis
+
+ ${project.name}
+
+ ${project.description}
+
+ Maven URL:
+ [mvn:${project.groupId}/${project.artifactId}/${project.version}]
+
+h1. Description
+
+ This bundle is the core implementation of the JMS service support.
+
+ The JMS service allows you to create connection factories, and send/browse/consume messages.
+
+h1. Commands
+
+ The bundle contains the following commands:
+\${command-list|jms|indent=8,list,cyan}
+
+h1. See also
+
+ JMS - section of the Karaf User Guide
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/src/main/resources/org/apache/karaf/jms/internal/connectionfactory-activemq.xml
----------------------------------------------------------------------
diff --git a/jms/core/src/main/resources/org/apache/karaf/jms/internal/connectionfactory-activemq.xml b/jms/core/src/main/resources/org/apache/karaf/jms/internal/connectionfactory-activemq.xml
new file mode 100644
index 0000000..5627e73
--- /dev/null
+++ b/jms/core/src/main/resources/org/apache/karaf/jms/internal/connectionfactory-activemq.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+ -->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+ <bean id="activemqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
+ <property name="brokerURL" value="${url}" />
+ <property name="userName" value="${username}" />
+ <property name="password" value="${password}" />
+ </bean>
+
+ <bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
+ <property name="maxConnections" value="8" />
+ <property name="connectionFactory" ref="activemqConnectionFactory" />
+ </bean>
+
+ <bean id="resourceManager" class="org.apache.activemq.pool.ActiveMQResourceManager" init-method="recoverResource">
+ <property name="transactionManager" ref="transactionManager" />
+ <property name="connectionFactory" ref="activemqConnectionFactory" />
+ <property name="resourceName" value="activemq.localhost" />
+ </bean>
+
+ <reference id="transactionManager" interface="javax.transaction.TransactionManager" />
+
+ <service ref="pooledConnectionFactory" interface="javax.jms.ConnectionFactory">
+ <service-properties>
+ <entry key="name" value="${name}" />
+ <entry key="osgi.jndi.service.name" value="jms/${name}" />
+ </service-properties>
+ </service>
+
+</blueprint>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/core/src/main/resources/org/apache/karaf/jms/internal/connectionfactory-webspheremq.xml
----------------------------------------------------------------------
diff --git a/jms/core/src/main/resources/org/apache/karaf/jms/internal/connectionfactory-webspheremq.xml b/jms/core/src/main/resources/org/apache/karaf/jms/internal/connectionfactory-webspheremq.xml
new file mode 100644
index 0000000..3123f49
--- /dev/null
+++ b/jms/core/src/main/resources/org/apache/karaf/jms/internal/connectionfactory-webspheremq.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+ -->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+ <bean id="wmqConnectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory">
+ <property name="transportType" value="1" />
+ <property name="hostName" value="${hostname}" />
+ <property name="port" value="${port}" />
+ <property name="queueManager" value="${queuemanager}" />
+ <property name="channel" value="${channel}" />
+ <property name="useConnectionPooling" value="true" />
+ </bean>
+
+ <service ref="wmqConnectionFactory" interface="javax.jms.ConnectionFactory">
+ <service-properties>
+ <entry key="name" value="${name}"/>
+ <entry key="osgi.jndi.service.name" value="jms/${name}"/>
+ </service-properties>
+ </service>
+
+</blueprint>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/pom.xml
----------------------------------------------------------------------
diff --git a/jms/pom.xml b/jms/pom.xml
index 4b844ee..756f654 100644
--- a/jms/pom.xml
+++ b/jms/pom.xml
@@ -29,87 +29,12 @@
</parent>
<groupId>org.apache.karaf.jms</groupId>
- <artifactId>org.apache.karaf.jms.core</artifactId>
- <packaging>bundle</packaging>
- <name>Apache Karaf :: JMS :: Core</name>
- <description>This bundle provides core implementation of the JMS service.</description>
-
- <properties>
- <appendedResourcesDirectory>${basedir}/../../etc/appended-resources</appendedResourcesDirectory>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-jms_1.1_spec</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.activemq</groupId>
- <artifactId>activemq-pool</artifactId>
- <version>5.9.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.karaf</groupId>
- <artifactId>org.apache.karaf.util</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.karaf.shell</groupId>
- <artifactId>org.apache.karaf.shell.core</artifactId>
- <optional>true</optional>
- </dependency>
- </dependencies>
-
- <build>
- <resources>
- <resource>
- <directory>${project.basedir}/src/main/resources</directory>
- <includes>
- <include>**/*</include>
- </includes>
- </resource>
- <resource>
- <directory>${project.basedir}/src/main/resources</directory>
- <filtering>true</filtering>
- <includes>
- <include>**/*.info</include>
- </includes>
- </resource>
- </resources>
- <plugins>
- <plugin>
- <groupId>org.apache.karaf.tooling</groupId>
- <artifactId>karaf-services-maven-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <configuration>
- <instructions>
- <Export-Package>
- org.apache.karaf.jms
- </Export-Package>
- <Import-Package>
- org.apache.activemq*;resolution:=optional,
- *
- </Import-Package>
- <Private-Package>
- org.apache.karaf.jms.command,
- org.apache.karaf.jms.command.completers,
- org.apache.karaf.jms.internal,
- org.apache.karaf.util
- </Private-Package>
- <DynamicImport-Package>*</DynamicImport-Package>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
-</project>
\ No newline at end of file
+ <artifactId>parent</artifactId>
+ <packaging>pom</packaging>
+ <name>Apache Karaf :: Features</name>
+
+ <modules>
+ <module>activemq-cf</module>
+ <module>core</module>
+ </modules>
+</project>
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/src/main/java/org/apache/karaf/jms/JmsMBean.java
----------------------------------------------------------------------
diff --git a/jms/src/main/java/org/apache/karaf/jms/JmsMBean.java b/jms/src/main/java/org/apache/karaf/jms/JmsMBean.java
deleted file mode 100644
index d62a9ba..0000000
--- a/jms/src/main/java/org/apache/karaf/jms/JmsMBean.java
+++ /dev/null
@@ -1,165 +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.karaf.jms;
-
-import javax.management.MBeanException;
-import javax.management.openmbean.TabularData;
-import java.util.List;
-import java.util.Map;
-
-/**
- * JMS MBean.
- */
-public interface JmsMBean {
-
- /**
- * List the JMS connection factories.
- *
- * @return The {@link List} of the JMS connection factories name.
- * @throws MBeanException If the MBean fails.
- */
- List<String> getConnectionfactories() throws MBeanException;
-
- /**
- * Create a JMS connection factory.
- *
- * @param name The JMS connection factory name.
- * @param type The JMS connection factory type (ActiveMQ or WebsphereMQ).
- * @param url The JMS connection factory URL. NB: when type is WebsphereMQ, the URL has the format host/port/queuemanager/channel.
- * @throws MBeanException If the MBean fails.
- */
- void create(String name, String type, String url) throws MBeanException;
-
- /**
- * Create a JMS connection factory.
- *
- * @param name The JMS connection factory name.
- * @param type The JMS connection factory type (ActiveMQ or WebsphereMQ).
- * @param url The JMS connection factory URL. NB: when type is WebsphereMQ, the URL has the format host/port/queuemanager/channel.
- * @param username The JMS connection factory authentication username.
- * @param password The JMS connection factory authentication password.
- * @throws MBeanException If the MBean fails.
- */
- void create(String name, String type, String url, String username, String password) throws MBeanException;
-
- /**
- * Delete a JMS connection factory.
- *
- * @param name The JMS connection factory name.
- * @throws MBeanException If the MBean fails.
- */
- void delete(String name) throws MBeanException;
-
- /**
- * Get details about a JMS connection factory.
- *
- * @param connectionFactory The JMS connection factory name.
- * @param username The (optional) username to connect to the JMS broker.
- * @param password The (optional) password to connect to the JMS broker.
- * @return A {@link Map} (property/value) containing details.
- * @throws MBeanException If the MBean fails.
- */
- Map<String, String> info(String connectionFactory, String username, String password) throws MBeanException;
-
- /**
- * Count the messages on a given JMS queue.
- *
- * @param connectionFactory The JMS connection factory name.
- * @param queue The JMS queue name.
- * @param username The (optional) username to connect to the JMS broker.
- * @param password The (optional) password to connect to the JMS broker.
- * @return The number of messages in the queue.
- * @throws MBeanException If the MBean fails.
- */
- int count(String connectionFactory, String queue, String username, String password) throws MBeanException;
-
- /**
- * List the JMS queues.
- *
- * @param connectionFactory The JMS connection factory name.
- * @param username The (optional) username to connect to the JMS broker.
- * @param password The (optional) password to connect to the JMS broker.
- * @return The {@link List} of JMS queues.
- * @throws MBeanException If the MBean fails.
- */
- List<String> queues(String connectionFactory, String username, String password) throws MBeanException;
-
- /**
- * List the JMS topics.
- *
- * @param connectionFactory The JMS connection factory name.
- * @param username The (optional) username to connect to the JMS broker.
- * @param password The (optional) password to connect to the JMS broker.
- * @return The @link List} of JMS topics.
- * @throws MBeanException If the MBean fails.
- */
- List<String> topics(String connectionFactory, String username, String password) throws MBeanException;
-
- /**
- * Browse the messages in a JMS queue.
- *
- * @param connectionFactory The JMS connection factory name.
- * @param queue The JMS queue name.
- * @param selector A selector to use to browse only certain messages.
- * @param username The (optional) username to connect to the JMS broker.
- * @param password The (optional) password to connect to the JMS broker.
- * @return A {@link TabularData} containing messages details.
- * @throws MBeanException If the MBean fails.
- */
- TabularData browse(String connectionFactory, String queue, String selector, String username, String password) throws MBeanException;
-
- /**
- * Send a JMS message to given queue.
- *
- * @param connectionFactory The JMS connection factory name.
- * @param queue The JMS queue name.
- * @param content The message content.
- * @param replyTo The message ReplyTo.
- * @param username The (optional) username to connect to the JMS broker.
- * @param password The (optional) password to connect to the JMS broker.
- * @throws MBeanException If the MBean fails.
- */
- void send(String connectionFactory, String queue, String content, String replyTo, String username, String password) throws MBeanException;
-
- /**
- * Consume JMS messages from a given queue.
- *
- * @param connectionFactory The JMS connection factory name.
- * @param queue The JMS queue name.
- * @param selector A selector to use to consume only certain messages.
- * @param username The (optional) username to connect to the JMS broker.
- * @param password The (optional) password to connect to the JMS broker.
- * @return The number of messages consumed.
- * @throws MBeanException If the MBean fails.
- */
- int consume(String connectionFactory, String queue, String selector, String username, String password) throws MBeanException;
-
- /**
- * Move JMS messages from one queue to another.
- *
- * @param connectionFactory The JMS connection factory name.
- * @param source The source JMS queue name.
- * @param destination The destination JMS queue name.
- * @param selector A selector to move only certain messages.
- * @param username The (optional) username to connect to the JMS broker.
- * @param password The (optional) password to connect to the JMS broker.
- * @return The number of messages moved.
- * @throws MBeanException If the MBean fails.
- */
- int move(String connectionFactory, String source, String destination, String selector, String username, String password) throws MBeanException;
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/src/main/java/org/apache/karaf/jms/JmsMessage.java
----------------------------------------------------------------------
diff --git a/jms/src/main/java/org/apache/karaf/jms/JmsMessage.java b/jms/src/main/java/org/apache/karaf/jms/JmsMessage.java
deleted file mode 100644
index a85af10..0000000
--- a/jms/src/main/java/org/apache/karaf/jms/JmsMessage.java
+++ /dev/null
@@ -1,164 +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.karaf.jms;
-
-import javax.jms.*;
-import java.io.UnsupportedEncodingException;
-import java.util.Date;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Describe a JMS message is more human readable way.
- */
-public class JmsMessage {
-
- private Map<String, Object> properties = new HashMap<String, Object>();
-
- private String content;
- private String charset = "UTF-8";
- private String correlationID;
- private String deliveryMode;
- private String destination;
- private String expiration;
- private String messageId;
- private int priority;
- private boolean redelivered;
- private String replyTo;
- private String timestamp;
- private String type;
-
- public JmsMessage(Message message) {
- try {
- initFromMessage(message);
- } catch (JMSException e) {
- throw new RuntimeException(e.getMessage(), e);
- }
- }
-
- public void initFromMessage(Message message) throws JMSException {
- @SuppressWarnings("unchecked")
- Enumeration<String> names = message.getPropertyNames();
- while (names.hasMoreElements()) {
- String key = names.nextElement();
- Object value = message.getObjectProperty(key);
- properties.put(key, value);
- }
-
- correlationID = message.getJMSCorrelationID();
- if (message.getJMSDeliveryMode() == DeliveryMode.NON_PERSISTENT) {
- deliveryMode = "Non Persistent";
- } else {
- deliveryMode = "Persistent";
- }
- Destination destinationDest = message.getJMSDestination();
- if (destinationDest != null) {
- destination = destinationDest.toString();
- }
- if (message.getJMSExpiration() > 0) {
- expiration = new Date(message.getJMSExpiration()).toString();
- } else {
- expiration = "Never";
- }
- messageId = message.getJMSMessageID();
- priority = message.getJMSPriority();
- redelivered = message.getJMSRedelivered();
- Destination replyToDest = message.getJMSReplyTo();
- if (replyToDest != null) {
- replyTo = replyToDest.toString();
- }
- if (message.getJMSTimestamp() > 0) {
- timestamp = new Date(message.getJMSTimestamp()).toString();
- } else {
- timestamp = "";
- }
- type = message.getJMSType();
- content = getMessageContent(message);
- }
-
-
- private String getMessageContent(Message message) throws JMSException {
- if (message instanceof TextMessage) {
- return ((TextMessage) message).getText();
- } else if (message instanceof BytesMessage) {
- BytesMessage bMessage = (BytesMessage) message;
- long length = bMessage.getBodyLength();
- byte[] content = new byte[(int) length];
- bMessage.readBytes(content);
- try {
- return new String(content, charset);
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e.getMessage(), e);
- }
- }
- return "";
- }
-
- public Map<String, Object> getProperties() {
- return properties;
- }
-
- public String getContent() {
- return content;
- }
-
- public String getCharset() {
- return charset;
- }
-
- public String getCorrelationID() {
- return correlationID;
- }
-
- public String getDeliveryMode() {
- return deliveryMode;
- }
-
- public String getDestination() {
- return destination;
- }
-
- public String getExpiration() {
- return expiration;
- }
-
- public String getMessageId() {
- return messageId;
- }
-
- public int getPriority() {
- return priority;
- }
-
- public boolean isRedelivered() {
- return redelivered;
- }
-
- public String getReplyTo() {
- return replyTo;
- }
-
- public String getTimestamp() {
- return timestamp;
- }
-
- public String getType() {
- return type;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/src/main/java/org/apache/karaf/jms/JmsService.java
----------------------------------------------------------------------
diff --git a/jms/src/main/java/org/apache/karaf/jms/JmsService.java b/jms/src/main/java/org/apache/karaf/jms/JmsService.java
deleted file mode 100644
index 0902e33..0000000
--- a/jms/src/main/java/org/apache/karaf/jms/JmsService.java
+++ /dev/null
@@ -1,171 +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.karaf.jms;
-
-import java.util.List;
-import java.util.Map;
-
-/**
- * JMS Service.
- */
-public interface JmsService {
-
- /**
- * List the JMS connection factories.
- *
- * @return The {@link List} of JMS connection factory names.
- * @throws Exception If the service fails.
- */
- List<String> connectionFactories() throws Exception;
-
- /**
- * List the JMS connection factories file names.
- *
- * @return The {@link List} of JMS connection factory file names.
- * @throws Exception If the service fails.
- */
- List<String> connectionFactoryFileNames() throws Exception;
-
- /**
- * Create a new JMS connection factory.
- *
- * @param name The JMS connection factory name.
- * @param type The JMS connection factory type (ActiveMQ, WebsphereMQ, ...).
- * @param url The JMS URL to use.
- * @throws Exception If the service fails.
- */
- void create(String name, String type, String url) throws Exception;
-
- /**
- * Create a new JMS connection factory.
- *
- * @param name The JMS connection factory name.
- * @param type The JMS connection factory type (ActiveMQ, WebsphereMQ, ...).
- * @param url The JMS URL to use.
- * @param username The username to use.
- * @param password The password to use.
- * @throws Exception If the service fails.
- */
- void create(String name, String type, String url, String username, String password) throws Exception;
-
- /**
- * Delete a JMS connection factory.
- *
- * @param name The JMS connection factory name.
- * @throws Exception If the service fails.
- */
- void delete(String name) throws Exception;
-
- /**
- * Get details about a given JMS connection factory.
- *
- * @param connectionFactory The JMS connection factory name.
- * @param username The (optional) username to connect to the JMS broker.
- * @param password The (optional) password to connect to the JMS broker.
- * @return A {@link Map} (property/value) containing details.
- * @throws Exception If the service fails.
- */
- Map<String, String> info(String connectionFactory, String username, String password) throws Exception;
-
- /**
- * Count the number of messages in a JMS queue.
- *
- * @param connectionFactory The JMS connection factory name.
- * @param queue The queue name.
- * @param username The (optional) username to connect to the JMS broker.
- * @param password The (optional) password to connect to the JMS broker.
- * @return The number of messages in a JMS queue.
- * @throws Exception If the service fails.
- */
- int count(String connectionFactory, String queue, String username, String password) throws Exception;
-
- /**
- * List the queues.
- *
- * @param connectionFactory The JMS connection factory name.
- * @param username The (optional) username to connect to the JMS broker.
- * @param password The (optional) password to connect to the JMS broker.
- * @return The {@link List} of queues.
- * @throws Exception If the service fails.
- */
- List<String> queues(String connectionFactory, String username, String password) throws Exception;
-
- /**
- * List the topics.
- *
- * @param connectionFactory The JMS connection factory name.
- * @param username The (optional) username to connect to the JMS broker.
- * @param password The (optional) password to connect to the JMS broker.
- * @return The {@link List} of topics.
- * @throws Exception If the service fails.
- */
- List<String> topics(String connectionFactory, String username, String password) throws Exception;
-
- /**
- * Browse a destination.
- *
- * @param connectionFactory The JMS connection factory name.
- * @param queue The queue name.
- * @param selector The selector.
- * @param username The (optional) username to connect to the JMS broker.
- * @param password The (optional) password to connect to the JMS broker.
- * @return The {@link List} of messages.
- * @throws Exception If the service fails.
- */
- List<JmsMessage> browse(String connectionFactory, String queue, String selector, String username, String password) throws Exception;
-
- /**
- * Send a message on the given queue.
- *
- * @param connectionFactory The JMS connection factory name.
- * @param queue The queue name.
- * @param body The message body.
- * @param replyTo The message replyTo header.
- * @param username The (optional) username to connect to the JMS broker.
- * @param password The (optional) password to connect to the JMS broker.
- * @throws Exception If the service fails.
- */
- void send(String connectionFactory, String queue, String body, String replyTo, String username, String password) throws Exception;
-
- /**
- * Consume messages from a given destination.
- *
- * @param connectionFactory The JMS connection factory name.
- * @param queue The queue name.
- * @param selector The messages selector.
- * @param username The (optional) username to connect to the JMS broker.
- * @param password The (optional) password to connect to the JMS broker.
- * @return The number of messages consumed.
- * @throws Exception If the service fails.
- */
- int consume(String connectionFactory, String queue, String selector, String username, String password) throws Exception;
-
- /**
- * Move messages from a destination to another.
- *
- * @param connectionFactory The JMS connection factory name.
- * @param sourceQueue The source queue.
- * @param targetQueue The target queue.
- * @param selector The messages selector on the source queue.
- * @param username The (optional) username to connect to the JMS broker.
- * @param password The (optional) password to connect to the JMS broker.
- * @return The number of messages moved.
- * @throws Exception If the service fails.
- */
- int move(String connectionFactory, String sourceQueue, String targetQueue, String selector, String username, String password) throws Exception;
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/src/main/java/org/apache/karaf/jms/command/BrowseCommand.java
----------------------------------------------------------------------
diff --git a/jms/src/main/java/org/apache/karaf/jms/command/BrowseCommand.java b/jms/src/main/java/org/apache/karaf/jms/command/BrowseCommand.java
deleted file mode 100644
index cb86aa6..0000000
--- a/jms/src/main/java/org/apache/karaf/jms/command/BrowseCommand.java
+++ /dev/null
@@ -1,104 +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.karaf.jms.command;
-
-import java.util.List;
-
-import org.apache.karaf.jms.JmsMessage;
-import org.apache.karaf.shell.api.action.Argument;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.Option;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.apache.karaf.shell.support.table.ShellTable;
-
-@Command(scope = "jms", name = "browse", description = "Browse a JMS queue")
-@Service
-public class BrowseCommand extends JmsConnectionCommandSupport {
-
- @Argument(index = 1, name = "queue", description = "The JMS queue to browse", required = true, multiValued = false)
- String queue;
-
- @Option(name = "-s", aliases = { "--selector" }, description = "The selector to select the messages to browse", required = false, multiValued = false)
- String selector;
-
- @Option(name = "-v", aliases = { "--verbose" }, description = "Display JMS properties", required = false, multiValued = false)
- boolean verbose = false;
-
- @Override
- public Object execute() throws Exception {
-
- ShellTable table = new ShellTable();
- table.column("Message ID");
- table.column("Content").maxSize(80);
- table.column("Charset");
- table.column("Type");
- table.column("Correlation ID");
- table.column("Delivery Mode");
- table.column("Destination");
- table.column("Expiration");
- table.column("Priority");
- table.column("Redelivered");
- table.column("ReplyTo");
- table.column("Timestamp");
- if (verbose) {
- table.column("Properties");
- }
-
- List<JmsMessage> messages = getJmsService().browse(connectionFactory, queue, selector, username, password);
- for (JmsMessage message : messages) {
- if (verbose) {
- StringBuilder properties = new StringBuilder();
- for (String property : message.getProperties().keySet()) {
- properties.append(property).append("=").append(message.getProperties().get(property)).append("\n");
- }
- table.addRow().addContent(
- message.getMessageId(),
- message.getContent(),
- message.getCharset(),
- message.getType(),
- message.getCorrelationID(),
- message.getDeliveryMode(),
- message.getDestination(),
- message.getExpiration(),
- message.getPriority(),
- message.isRedelivered(),
- message.getReplyTo(),
- message.getTimestamp(),
- properties.toString());
- } else {
- table.addRow().addContent(
- message.getMessageId(),
- message.getContent(),
- message.getCharset(),
- message.getType(),
- message.getCorrelationID(),
- message.getDeliveryMode(),
- message.getDestination(),
- message.getExpiration(),
- message.getPriority(),
- message.isRedelivered(),
- message.getReplyTo(),
- message.getTimestamp());
- }
- }
-
- table.print(System.out);
-
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/src/main/java/org/apache/karaf/jms/command/ConnectionFactoriesCommand.java
----------------------------------------------------------------------
diff --git a/jms/src/main/java/org/apache/karaf/jms/command/ConnectionFactoriesCommand.java b/jms/src/main/java/org/apache/karaf/jms/command/ConnectionFactoriesCommand.java
deleted file mode 100644
index b698336..0000000
--- a/jms/src/main/java/org/apache/karaf/jms/command/ConnectionFactoriesCommand.java
+++ /dev/null
@@ -1,45 +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.karaf.jms.command;
-
-import java.util.List;
-
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.apache.karaf.shell.support.table.ShellTable;
-
-@Command(scope = "jms", name = "connectionfactories", description = "List the JMS connection factories")
-@Service
-public class ConnectionFactoriesCommand extends JmsCommandSupport {
-
- @Override
- public Object execute() throws Exception {
-
- ShellTable table = new ShellTable();
- table.column("JMS Connection Factory");
-
- List<String> connectionFactories = getJmsService().connectionFactories();
- for (String connectionFactory : connectionFactories) {
- table.addRow().addContent(connectionFactory);
- }
-
- table.print(System.out);
-
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/src/main/java/org/apache/karaf/jms/command/ConsumeCommand.java
----------------------------------------------------------------------
diff --git a/jms/src/main/java/org/apache/karaf/jms/command/ConsumeCommand.java b/jms/src/main/java/org/apache/karaf/jms/command/ConsumeCommand.java
deleted file mode 100644
index cd8caaf..0000000
--- a/jms/src/main/java/org/apache/karaf/jms/command/ConsumeCommand.java
+++ /dev/null
@@ -1,40 +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.karaf.jms.command;
-
-import org.apache.karaf.shell.api.action.Argument;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.Option;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-
-@Command(scope = "jms", name = "consume", description = "Consume messages from a JMS queue.")
-@Service
-public class ConsumeCommand extends JmsConnectionCommandSupport {
-
- @Argument(index = 1, name = "queue", description = "The JMS queue where to consume messages", required = true, multiValued = false)
- String queue;
-
- @Option(name = "-s", aliases = { "--selector" }, description = "The selector to use to select the messages to consume", required = false, multiValued = false)
- String selector;
-
- @Override
- public Object execute() throws Exception {
- System.out.println(getJmsService().consume(connectionFactory, queue, selector, username, password) + " message(s) consumed");
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/src/main/java/org/apache/karaf/jms/command/CountCommand.java
----------------------------------------------------------------------
diff --git a/jms/src/main/java/org/apache/karaf/jms/command/CountCommand.java b/jms/src/main/java/org/apache/karaf/jms/command/CountCommand.java
deleted file mode 100644
index 576e8dd..0000000
--- a/jms/src/main/java/org/apache/karaf/jms/command/CountCommand.java
+++ /dev/null
@@ -1,41 +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.karaf.jms.command;
-
-
-import org.apache.karaf.shell.api.action.Argument;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.apache.karaf.shell.support.table.ShellTable;
-
-@Command(scope = "jms", name = "count", description = "Count the number of messages on a JMS queue.")
-@Service
-public class CountCommand extends JmsConnectionCommandSupport {
-
- @Argument(index = 1, name = "queue", description = "The JMS queue name", required = true, multiValued = false)
- String queue;
-
- @Override
- public Object execute() throws Exception {
- ShellTable table = new ShellTable();
- table.column("Messages Count");
- table.addRow().addContent(getJmsService().count(connectionFactory, queue, username, password));
- table.print(System.out);
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/src/main/java/org/apache/karaf/jms/command/CreateCommand.java
----------------------------------------------------------------------
diff --git a/jms/src/main/java/org/apache/karaf/jms/command/CreateCommand.java b/jms/src/main/java/org/apache/karaf/jms/command/CreateCommand.java
deleted file mode 100644
index fb91416..0000000
--- a/jms/src/main/java/org/apache/karaf/jms/command/CreateCommand.java
+++ /dev/null
@@ -1,52 +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.karaf.jms.command;
-
-import org.apache.karaf.shell.api.action.Argument;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.Completion;
-import org.apache.karaf.shell.api.action.Option;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.apache.karaf.shell.support.completers.StringsCompleter;
-
-@Command(scope = "jms", name = "create", description = "Create a JMS connection factory.")
-@Service
-public class CreateCommand extends JmsCommandSupport {
-
- @Argument(index = 0, name = "name", description = "The JMS connection factory name", required = true, multiValued = false)
- String name;
-
- @Option(name = "-t", aliases = { "--type" }, description = "The JMS connection factory type (ActiveMQ or WebsphereMQ)", required = false, multiValued = false)
- @Completion(value = StringsCompleter.class, values = { "activemq", "webspheremq" })
- String type = "ActiveMQ";
-
- @Option(name = "--url", description = "URL of the JMS broker. For WebsphereMQ type, the URL is hostname/port/queuemanager/channel", required = false, multiValued = false)
- String url = "tcp://localhost:61616";
-
- @Option(name = "-u", aliases = { "--username" }, description = "Username to connect to the JMS broker", required = false, multiValued = false)
- String username = "karaf";
-
- @Option(name = "-p", aliases = { "--password" }, description = "Password to connect to the JMS broker", required = false, multiValued = false)
- String password = "karaf";
-
- @Override
- public Object execute() throws Exception {
- getJmsService().create(name, type, url, username, password);
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/src/main/java/org/apache/karaf/jms/command/DeleteCommand.java
----------------------------------------------------------------------
diff --git a/jms/src/main/java/org/apache/karaf/jms/command/DeleteCommand.java b/jms/src/main/java/org/apache/karaf/jms/command/DeleteCommand.java
deleted file mode 100644
index cab3123..0000000
--- a/jms/src/main/java/org/apache/karaf/jms/command/DeleteCommand.java
+++ /dev/null
@@ -1,40 +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.karaf.jms.command;
-
-
-import org.apache.karaf.jms.command.completers.ConnectionFactoriesFileNameCompleter;
-import org.apache.karaf.shell.api.action.Argument;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.Completion;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-
-@Command(scope = "jms", name = "delete", description = "Delete a JMS connection factory")
-@Service
-public class DeleteCommand extends JmsCommandSupport {
-
- @Argument(index = 0, name = "name", description = "The JMS connection factory name", required = true, multiValued = false)
- @Completion(ConnectionFactoriesFileNameCompleter.class)
- String name;
-
- @Override
- public Object execute() throws Exception {
- getJmsService().delete(name);
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/src/main/java/org/apache/karaf/jms/command/InfoCommand.java
----------------------------------------------------------------------
diff --git a/jms/src/main/java/org/apache/karaf/jms/command/InfoCommand.java b/jms/src/main/java/org/apache/karaf/jms/command/InfoCommand.java
deleted file mode 100644
index 354db39..0000000
--- a/jms/src/main/java/org/apache/karaf/jms/command/InfoCommand.java
+++ /dev/null
@@ -1,46 +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.karaf.jms.command;
-
-
-import java.util.Map;
-
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.apache.karaf.shell.support.table.ShellTable;
-
-@Command(scope = "jms", name = "info", description = "Provides details about a JMS connection factory.")
-@Service
-public class InfoCommand extends JmsConnectionCommandSupport {
-
- @Override
- public Object execute() throws Exception {
- ShellTable table = new ShellTable();
- table.column("Property");
- table.column("Value");
-
- Map<String, String> info = getJmsService().info(connectionFactory, username, password);
- for (String key : info.keySet()) {
- table.addRow().addContent(key, info.get(key));
- }
-
- table.print(System.out);
-
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/src/main/java/org/apache/karaf/jms/command/JmsCommandSupport.java
----------------------------------------------------------------------
diff --git a/jms/src/main/java/org/apache/karaf/jms/command/JmsCommandSupport.java b/jms/src/main/java/org/apache/karaf/jms/command/JmsCommandSupport.java
deleted file mode 100644
index 2f5df8f..0000000
--- a/jms/src/main/java/org/apache/karaf/jms/command/JmsCommandSupport.java
+++ /dev/null
@@ -1,36 +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.karaf.jms.command;
-
-import org.apache.karaf.jms.JmsService;
-import org.apache.karaf.shell.api.action.Action;
-import org.apache.karaf.shell.api.action.lifecycle.Reference;
-
-public abstract class JmsCommandSupport implements Action {
-
- @Reference
- private JmsService jmsService;
-
- public JmsService getJmsService() {
- return jmsService;
- }
-
- public void setJmsService(JmsService jmsService) {
- this.jmsService = jmsService;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/src/main/java/org/apache/karaf/jms/command/JmsConnectionCommandSupport.java
----------------------------------------------------------------------
diff --git a/jms/src/main/java/org/apache/karaf/jms/command/JmsConnectionCommandSupport.java b/jms/src/main/java/org/apache/karaf/jms/command/JmsConnectionCommandSupport.java
deleted file mode 100644
index 64adfe4..0000000
--- a/jms/src/main/java/org/apache/karaf/jms/command/JmsConnectionCommandSupport.java
+++ /dev/null
@@ -1,39 +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.karaf.jms.command;
-
-import org.apache.karaf.jms.command.completers.ConnectionFactoriesNameCompleter;
-import org.apache.karaf.shell.api.action.Argument;
-import org.apache.karaf.shell.api.action.Completion;
-import org.apache.karaf.shell.api.action.Option;
-
-/**
- * For commands that need a connection factory and authentication information
- */
-public abstract class JmsConnectionCommandSupport extends JmsCommandSupport {
-
- @Argument(index = 0, name = "connectionFactory", description = "The JMS connection factory name", required = true, multiValued = false)
- @Completion(ConnectionFactoriesNameCompleter.class)
- String connectionFactory;
-
- @Option(name = "-u", aliases = { "--username" }, description = "Username to connect to the JMS broker", required = false, multiValued = false)
- String username = "karaf";
-
- @Option(name = "-p", aliases = { "--password" }, description = "Password to connect to the JMS broker", required = false, multiValued = false)
- String password = "karaf";
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/src/main/java/org/apache/karaf/jms/command/MoveCommand.java
----------------------------------------------------------------------
diff --git a/jms/src/main/java/org/apache/karaf/jms/command/MoveCommand.java b/jms/src/main/java/org/apache/karaf/jms/command/MoveCommand.java
deleted file mode 100644
index a4c8d12..0000000
--- a/jms/src/main/java/org/apache/karaf/jms/command/MoveCommand.java
+++ /dev/null
@@ -1,44 +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.karaf.jms.command;
-
-
-import org.apache.karaf.shell.api.action.Argument;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.Option;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-
-@Command(scope = "jms", name = "move", description = "Move messages from one JMS queue to another one.")
-@Service
-public class MoveCommand extends JmsConnectionCommandSupport {
-
- @Argument(index = 1, name = "source", description = "The source JMS queue", required = true, multiValued = false)
- String source;
-
- @Argument(index = 2, name = "destination", description = "The destination JMS queue", required = true, multiValued = false)
- String destination;
-
- @Option(name = "-s", aliases = { "--selector" }, description = "Selector to move only some messages", required = false, multiValued = false)
- String selector;
-
- @Override
- public Object execute() throws Exception {
- System.out.println(getJmsService().move(connectionFactory, source, destination, selector, username, password) + " message(s) moved");
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/src/main/java/org/apache/karaf/jms/command/QueuesCommand.java
----------------------------------------------------------------------
diff --git a/jms/src/main/java/org/apache/karaf/jms/command/QueuesCommand.java b/jms/src/main/java/org/apache/karaf/jms/command/QueuesCommand.java
deleted file mode 100644
index 7cf1dac..0000000
--- a/jms/src/main/java/org/apache/karaf/jms/command/QueuesCommand.java
+++ /dev/null
@@ -1,43 +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.karaf.jms.command;
-
-
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.apache.karaf.shell.support.table.ShellTable;
-
-@Command(scope = "jms", name = "queues", description = "List the JMS queues.")
-@Service
-public class QueuesCommand extends JmsConnectionCommandSupport {
-
- @Override
- public Object execute() throws Exception {
- ShellTable table = new ShellTable();
-
- table.column("JMS Queues");
-
- for (String queue : getJmsService().queues(connectionFactory, username, password)) {
- table.addRow().addContent(queue);
- }
-
- table.print(System.out);
-
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/src/main/java/org/apache/karaf/jms/command/SendCommand.java
----------------------------------------------------------------------
diff --git a/jms/src/main/java/org/apache/karaf/jms/command/SendCommand.java b/jms/src/main/java/org/apache/karaf/jms/command/SendCommand.java
deleted file mode 100644
index 63d3f4a..0000000
--- a/jms/src/main/java/org/apache/karaf/jms/command/SendCommand.java
+++ /dev/null
@@ -1,44 +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.karaf.jms.command;
-
-
-import org.apache.karaf.shell.api.action.Argument;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.Option;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-
-@Command(scope = "jms", name = "send", description = "Send a message to ")
-@Service
-public class SendCommand extends JmsConnectionCommandSupport {
-
- @Argument(index = 1, name = "queue", description = "The JMS queue name", required = true, multiValued = false)
- String queue;
-
- @Argument(index = 2, name = "message", description = "The JMS message content", required = true, multiValued = false)
- String message;
-
- @Option(name = "-r", aliases = { "--replyTo" }, description = "Set the message ReplyTo", required = false, multiValued = false)
- String replyTo;
-
- @Override
- public Object execute() throws Exception {
- getJmsService().send(connectionFactory, queue, message, replyTo, username, password);
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6d46540f/jms/src/main/java/org/apache/karaf/jms/command/TopicsCommand.java
----------------------------------------------------------------------
diff --git a/jms/src/main/java/org/apache/karaf/jms/command/TopicsCommand.java b/jms/src/main/java/org/apache/karaf/jms/command/TopicsCommand.java
deleted file mode 100644
index b583bc4..0000000
--- a/jms/src/main/java/org/apache/karaf/jms/command/TopicsCommand.java
+++ /dev/null
@@ -1,43 +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.karaf.jms.command;
-
-
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.apache.karaf.shell.support.table.ShellTable;
-
-@Command(scope = "jms", name = "topics", description = "List the JMS topics.")
-@Service
-public class TopicsCommand extends JmsConnectionCommandSupport {
-
- @Override
- public Object execute() throws Exception {
- ShellTable table = new ShellTable();
-
- table.column("JMS Topics");
-
- for (String topic : getJmsService().topics(connectionFactory, username, password)) {
- table.addRow().addContent(topic);
- }
-
- table.print(System.out);
-
- return null;
- }
-
-}