diff --git a/History.md b/History.md
index aecb45d4e..2bd3d9a78 100644
--- a/History.md
+++ b/History.md
@@ -2,6 +2,8 @@
- Adds basic compatibility with JRuby 10.0
- Drop unnecessary jruby.compat.version and RackConfig.getCompatVersion() API
+- Drop JMS support
+- update (bundled) rack to 2.2.16
## 1.2.4 (UNRELEASED)
diff --git a/examples/servers/Apache-Tomcat-6-0-14.txt b/examples/servers/Apache-Tomcat-6-0-14.txt
index 690f952fe..3f11a1fe5 100644
--- a/examples/servers/Apache-Tomcat-6-0-14.txt
+++ b/examples/servers/Apache-Tomcat-6-0-14.txt
@@ -35,8 +35,6 @@ filter_adds_html = true
filter_verifies_resource = false
ignore_environment = true
initial_runtimes =
-jms_connection_factory =
-jms_jndi_properties =
logger = org.jruby.rack.logging.ServletContextLogger@7a14b43d
logger_class_name = servlet_context
logger_name = jruby.rack
diff --git a/examples/servers/Apache-Tomcat-7-0-2.txt b/examples/servers/Apache-Tomcat-7-0-2.txt
index 963c133f9..74f937722 100644
--- a/examples/servers/Apache-Tomcat-7-0-2.txt
+++ b/examples/servers/Apache-Tomcat-7-0-2.txt
@@ -35,8 +35,6 @@ filter_adds_html = true
filter_verifies_resource = false
ignore_environment = true
initial_runtimes =
-jms_connection_factory =
-jms_jndi_properties =
logger = org.jruby.rack.logging.ServletContextLogger@398a3257
logger_class_name = servlet_context
logger_name = jruby.rack
diff --git a/examples/servers/GlassFish-v3.txt b/examples/servers/GlassFish-v3.txt
index 437cc671f..33d4eeb87 100644
--- a/examples/servers/GlassFish-v3.txt
+++ b/examples/servers/GlassFish-v3.txt
@@ -37,8 +37,6 @@ filter_adds_html = true
filter_verifies_resource = false
ignore_environment = true
initial_runtimes =
-jms_connection_factory =
-jms_jndi_properties =
logger = org.jruby.rack.logging.ServletContextLogger@46ee45a5
logger_class_name = servlet_context
logger_name = jruby.rack
diff --git a/examples/servers/JBoss-Web-2-1-3-GA.txt b/examples/servers/JBoss-Web-2-1-3-GA.txt
index c3038f439..f0b535ac9 100644
--- a/examples/servers/JBoss-Web-2-1-3-GA.txt
+++ b/examples/servers/JBoss-Web-2-1-3-GA.txt
@@ -37,8 +37,6 @@ filter_adds_html = true
filter_verifies_resource = false
ignore_environment = true
initial_runtimes =
-jms_connection_factory =
-jms_jndi_properties =
logger = org.jruby.rack.logging.ServletContextLogger@1a20433b
logger_class_name = servlet_context
logger_name = jruby.rack
diff --git a/examples/servers/JBoss-Web-3-0-0-CR1.txt b/examples/servers/JBoss-Web-3-0-0-CR1.txt
index acce0b6ad..22a2c4eb8 100644
--- a/examples/servers/JBoss-Web-3-0-0-CR1.txt
+++ b/examples/servers/JBoss-Web-3-0-0-CR1.txt
@@ -36,8 +36,6 @@ filter_adds_html = true
filter_verifies_resource = false
ignore_environment = true
initial_runtimes =
-jms_connection_factory =
-jms_jndi_properties =
logger = org.jruby.rack.logging.ServletContextLogger@7ee18d93
logger_class_name = servlet_context
logger_name = jruby.rack
diff --git a/examples/servers/Resin-4-0-13.txt b/examples/servers/Resin-4-0-13.txt
index 8bc3c692c..68dd49b88 100644
--- a/examples/servers/Resin-4-0-13.txt
+++ b/examples/servers/Resin-4-0-13.txt
@@ -35,8 +35,6 @@ filter_adds_html = true
filter_verifies_resource = false
ignore_environment = true
initial_runtimes =
-jms_connection_factory =
-jms_jndi_properties =
logger = org.jruby.rack.logging.ServletContextLogger@6c538793
logger_class_name = servlet_context
logger_name = jruby.rack
diff --git a/examples/servers/Winstone-Servlet-Engine-v0-9-10.txt b/examples/servers/Winstone-Servlet-Engine-v0-9-10.txt
index 77293e220..56e19417b 100644
--- a/examples/servers/Winstone-Servlet-Engine-v0-9-10.txt
+++ b/examples/servers/Winstone-Servlet-Engine-v0-9-10.txt
@@ -36,8 +36,6 @@ filter_adds_html = true
filter_verifies_resource = false
ignore_environment = true
initial_runtimes =
-jms_connection_factory =
-jms_jndi_properties =
logger = org.jruby.rack.logging.ServletContextLogger@397af435
logger_class_name = servlet_context
logger_name = jruby.rack
diff --git a/examples/servers/jetty-6-1-25.txt b/examples/servers/jetty-6-1-25.txt
index 088ce9aa5..72e86d1c5 100644
--- a/examples/servers/jetty-6-1-25.txt
+++ b/examples/servers/jetty-6-1-25.txt
@@ -36,8 +36,6 @@ filter_adds_html = true
filter_verifies_resource = false
ignore_environment = true
initial_runtimes =
-jms_connection_factory =
-jms_jndi_properties =
logger = org.jruby.rack.logging.ServletContextLogger@1303368e
logger_class_name = servlet_context
logger_name = jruby.rack
@@ -149,13 +147,13 @@ SERVER_PORT = 8080
SERVER_SOFTWARE = jetty/6.1.25
java.servlet_context = org.jruby.rack.servlet.DefaultServletRackContext@f0c0ef2
java.servlet_request = GET /sinatra/env HTTP/1.1
-User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5
-Host: localhost:8080
-Accept: */*
-
+User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5
+Host: localhost:8080
+Accept: */*
+
java.servlet_response = HTTP/1.1 200
-Date: Thu, 22 Sep 2011 23:10:50 GMT
-
+Date: Thu, 22 Sep 2011 23:10:50 GMT
+
jruby.rack.dynamic.requests.only = true
jruby.rack.jruby.version = 1.6.4
jruby.rack.rack.release = 1.3
diff --git a/examples/servers/jetty-7-1-6-v20100715.txt b/examples/servers/jetty-7-1-6-v20100715.txt
index 3a57946be..6491724bf 100644
--- a/examples/servers/jetty-7-1-6-v20100715.txt
+++ b/examples/servers/jetty-7-1-6-v20100715.txt
@@ -35,8 +35,6 @@ filter_adds_html = true
filter_verifies_resource = false
ignore_environment = true
initial_runtimes =
-jms_connection_factory =
-jms_jndi_properties =
logger = org.jruby.rack.logging.ServletContextLogger@773fc437
logger_class_name = servlet_context
logger_name = jruby.rack
@@ -147,7 +145,7 @@ SERVER_SOFTWARE = jetty/7.1.6.v20100715
java.servlet_context = org.jruby.rack.servlet.DefaultServletRackContext@32645ccb
java.servlet_request = [GET /sinatra/env]@9171491 org.eclipse.jetty.server.Request@8bf223
java.servlet_response = HTTP/1.1 200
-
+
jruby.rack.dynamic.requests.only = true
jruby.rack.jruby.version = 1.6.4
jruby.rack.rack.release = 1.3
diff --git a/pom.xml b/pom.xml
index 5afc80345..c30602758 100644
--- a/pom.xml
+++ b/pom.xml
@@ -110,12 +110,6 @@
2.3.6
provided
-
- jakarta.jms
- jakarta.jms-api
- 2.0.3
- provided
-
commons-logging
commons-logging
diff --git a/src/main/java/org/jruby/rack/DefaultRackConfig.java b/src/main/java/org/jruby/rack/DefaultRackConfig.java
index 603b260e5..197c970d5 100644
--- a/src/main/java/org/jruby/rack/DefaultRackConfig.java
+++ b/src/main/java/org/jruby/rack/DefaultRackConfig.java
@@ -208,16 +208,6 @@ public boolean isFilterVerifiesResource() {
return getBooleanProperty("jruby.rack.filter.verifies.resource", false);
}
- @Override
- public String getJmsConnectionFactory() {
- return getProperty("jms.connection.factory");
- }
-
- @Override
- public String getJmsJndiProperties() {
- return getProperty("jms.jndi.properties");
- }
-
public String getLoggerName() {
return getProperty("jruby.rack.logging.name", "jruby.rack");
}
diff --git a/src/main/java/org/jruby/rack/RackConfig.java b/src/main/java/org/jruby/rack/RackConfig.java
index 4da4db422..2916b8117 100644
--- a/src/main/java/org/jruby/rack/RackConfig.java
+++ b/src/main/java/org/jruby/rack/RackConfig.java
@@ -168,26 +168,7 @@ public interface RackConfig {
*/
@Deprecated
boolean isFilterVerifiesResource();
-
- /**
- * Return the JNDI name of the JMS connection factory.
- *
- * @return the JMS connection factory
- * @deprecated JMS is rarely used thus should not be here
- */
- @Deprecated
- String getJmsConnectionFactory();
-
- /**
- * Return the JNDI properties for JMS.
- *
- * @return the JNDI properties
- * @deprecated JMS is rarely used thus should not be here
- */
- @Deprecated
- String getJmsJndiProperties();
-
- /**
+ /**
* General property retrieval for custom configuration values.
*
* @param key the key
diff --git a/src/main/java/org/jruby/rack/embed/Config.java b/src/main/java/org/jruby/rack/embed/Config.java
index fb63cdd92..707873451 100644
--- a/src/main/java/org/jruby/rack/embed/Config.java
+++ b/src/main/java/org/jruby/rack/embed/Config.java
@@ -195,14 +195,4 @@ public boolean isFilterVerifiesResource() {
throw new UnsupportedOperationException("isFilterVerifiesResource()");
}
- // JMS configuration not used with embed :
-
- public String getJmsConnectionFactory() {
- throw new UnsupportedOperationException("getJmsConnectionFactory()");
- }
-
- public String getJmsJndiProperties() {
- throw new UnsupportedOperationException("getJmsJndiProperties()");
- }
-
}
diff --git a/src/main/java/org/jruby/rack/jms/DefaultQueueManager.java b/src/main/java/org/jruby/rack/jms/DefaultQueueManager.java
deleted file mode 100644
index 9396004d4..000000000
--- a/src/main/java/org/jruby/rack/jms/DefaultQueueManager.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Copyright (c) 2010-2012 Engine Yard, Inc.
- * Copyright (c) 2007-2009 Sun Microsystems, Inc.
- * This source code is available under the MIT license.
- * See the file LICENSE.txt for details.
- */
-
-package org.jruby.rack.jms;
-
-import org.jruby.Ruby;
-import org.jruby.RubyModule;
-import org.jruby.RubyObjectAdapter;
-import org.jruby.javasupport.JavaEmbedUtils;
-import org.jruby.rack.RackApplication;
-import org.jruby.rack.RackApplicationFactory;
-import org.jruby.rack.RackContext;
-import org.jruby.rack.servlet.ServletRackContext;
-import org.jruby.runtime.builtin.IRubyObject;
-
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.Destination;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageListener;
-import javax.jms.Session;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import java.io.ByteArrayInputStream;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- *
- * @author nicksieger
- */
-public class DefaultQueueManager implements QueueManager {
- private ConnectionFactory connectionFactory = null;
- private ServletRackContext context;
- private Context jndiContext;
- private Map queues = new HashMap();
- private RubyObjectAdapter rubyObjectAdapter = JavaEmbedUtils.newObjectAdapter();
-
- public DefaultQueueManager() {
- }
-
- public DefaultQueueManager(ConnectionFactory qcf, Context ctx) {
- this.connectionFactory = qcf;
- this.jndiContext = ctx;
- }
-
- public void init(RackContext context) throws Exception {
- this.context = (ServletRackContext) context;
- @SuppressWarnings("deprecation")
- String jndiName = context.getConfig().getJmsConnectionFactory();
- if (jndiName != null && connectionFactory == null) {
- Properties properties = new Properties();
- @SuppressWarnings("deprecation")
- String jndiProperties = context.getConfig().getJmsJndiProperties();
- if (jndiProperties != null) {
- properties.load(new ByteArrayInputStream(jndiProperties.getBytes("UTF-8")));
- }
- jndiContext = new InitialContext(properties);
- connectionFactory = (ConnectionFactory) jndiContext.lookup(jndiName);
- }
- }
-
- public synchronized void listen(String queueName) {
- Connection conn = queues.get(queueName);
- if (conn == null) {
- try {
- conn = connectionFactory.createConnection();
- Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Destination dest = (Destination) lookup(queueName);
- MessageConsumer consumer = session.createConsumer(dest);
- consumer.setMessageListener(new RubyObjectMessageListener(queueName));
- queues.put(queueName, conn);
- conn.start();
- } catch (Exception e) {
- context.log("Unable to listen to '"+queueName+"': " + e.getMessage(), e);
- }
- // } else { ... already listening on that queue
- }
- }
-
- public synchronized void close(String queueName) {
- Connection conn = queues.remove(queueName);
- if (conn != null) {
- closeConnection(conn);
- }
- }
-
- public ConnectionFactory getConnectionFactory() {
- return connectionFactory;
- }
-
- public Object lookup(String name) throws NamingException {
- return jndiContext.lookup(name);
- }
-
- public void destroy() {
- for ( Map.Entry entry : queues.entrySet() ) {
- closeConnection(entry.getValue());
- }
- queues.clear();
- connectionFactory = null;
- }
-
- private void closeConnection(Connection conn) {
- try {
- conn.close();
- } catch (Exception e) {
- context.log("exception while closing connection: " + e.getMessage(), e);
- }
- }
-
- private class RubyObjectMessageListener implements MessageListener {
- private String queueName;
- private RackApplicationFactory rackFactory;
- public RubyObjectMessageListener(String name) {
- this.queueName = name;
- this.rackFactory = context.getRackFactory();
- }
-
- public void onMessage(Message message) {
- RackApplication app = null;
- try {
- app = rackFactory.getApplication();
- Ruby runtime = app.getRuntime();
- RubyModule mod = runtime.getClassFromPath("JRuby::Rack::Queues");
- IRubyObject obj = mod.getConstant("Registry");
- rubyObjectAdapter.callMethod(obj, "receive_message", new IRubyObject[] {
- JavaEmbedUtils.javaToRuby(runtime, queueName),
- JavaEmbedUtils.javaToRuby(runtime, message)});
- }
- catch (Exception e) {
- context.log("exception during message reception: " + e.getMessage(), e);
- }
- finally {
- if (app != null) {
- rackFactory.finishedWithApplication(app);
- }
- }
- }
- }
-}
diff --git a/src/main/java/org/jruby/rack/jms/QueueContextListener.java b/src/main/java/org/jruby/rack/jms/QueueContextListener.java
deleted file mode 100644
index 1b250fa45..000000000
--- a/src/main/java/org/jruby/rack/jms/QueueContextListener.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (c) 2010-2012 Engine Yard, Inc.
- * Copyright (c) 2007-2009 Sun Microsystems, Inc.
- * This source code is available under the MIT license.
- * See the file LICENSE.txt for details.
- */
-
-package org.jruby.rack.jms;
-
-import org.jruby.rack.RackApplicationFactory;
-import org.jruby.rack.RackContext;
-
-import javax.servlet.ServletContext;
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-
-/**
- *
- * @author nicksieger
- */
-public class QueueContextListener implements ServletContextListener {
- private QueueManagerFactory factory;
-
- public QueueContextListener() {
- this.factory = null;
- }
-
- public QueueContextListener(QueueManagerFactory qmf) {
- this.factory = qmf;
- }
-
- public void contextInitialized(ServletContextEvent event) {
- final ServletContext servletContext = event.getServletContext();
- RackContext rackContext = (RackContext) servletContext.getAttribute(RackApplicationFactory.RACK_CONTEXT);
-
- try {
- QueueManager qm = newQueueManagerFactory().newQueueManager();
- qm.init(rackContext);
- servletContext.setAttribute(QueueManager.MGR_KEY, qm);
- } catch (Exception e) {
- servletContext.log("Error initializing queue manager:" + e.getMessage(), e);
- }
- }
-
- public void contextDestroyed(ServletContextEvent event) {
- QueueManager qm = (QueueManager) event.getServletContext().getAttribute(QueueManager.MGR_KEY);
- if (qm != null) {
- event.getServletContext().removeAttribute(QueueManager.MGR_KEY);
- qm.destroy();
- }
- }
-
- private QueueManagerFactory newQueueManagerFactory() {
- if (factory != null) {
- return factory;
- }
- return new QueueManagerFactory() {
- public QueueManager newQueueManager() {
- return new DefaultQueueManager();
- }
- };
- }
-}
diff --git a/src/main/java/org/jruby/rack/jms/QueueManager.java b/src/main/java/org/jruby/rack/jms/QueueManager.java
deleted file mode 100644
index 44c0af3b9..000000000
--- a/src/main/java/org/jruby/rack/jms/QueueManager.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (c) 2010-2012 Engine Yard, Inc.
- * Copyright (c) 2007-2009 Sun Microsystems, Inc.
- * This source code is available under the MIT license.
- * See the file LICENSE.txt for details.
- */
-
-package org.jruby.rack.jms;
-
-import org.jruby.rack.RackContext;
-
-import javax.jms.ConnectionFactory;
-
-/**
- *
- * @author nicksieger
- */
-public interface QueueManager {
- String MGR_KEY = "rack.queue.manager";
-
- void init(RackContext context) throws Exception;
- void listen(String queueName);
- void close(String queueName);
- ConnectionFactory getConnectionFactory();
- Object lookup(String name) throws javax.naming.NamingException;
- void destroy();
-}
diff --git a/src/main/java/org/jruby/rack/jms/QueueManagerFactory.java b/src/main/java/org/jruby/rack/jms/QueueManagerFactory.java
deleted file mode 100644
index b3e9e0bea..000000000
--- a/src/main/java/org/jruby/rack/jms/QueueManagerFactory.java
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * Copyright (c) 2010-2012 Engine Yard, Inc.
- * Copyright (c) 2007-2009 Sun Microsystems, Inc.
- * This source code is available under the MIT license.
- * See the file LICENSE.txt for details.
- */
-
-package org.jruby.rack.jms;
-
-/**
- *
- * @author nicksieger
- */
-public interface QueueManagerFactory {
- QueueManager newQueueManager();
-}
diff --git a/src/main/ruby/jruby/rack/queues.rb b/src/main/ruby/jruby/rack/queues.rb
deleted file mode 100644
index 1b7844013..000000000
--- a/src/main/ruby/jruby/rack/queues.rb
+++ /dev/null
@@ -1,209 +0,0 @@
-#--
-# Copyright (c) 2010-2012 Engine Yard, Inc.
-# Copyright (c) 2007-2009 Sun Microsystems, Inc.
-# This source code is available under the MIT license.
-# See the file LICENSE.txt for details.
-#++
-
-module JRuby
- module Rack
- module Queues
- Session = Java::JavaxJms::Session
- MARSHAL_PAYLOAD = "ruby_marshal_payload"
-
- class QueueRegistry
- def initialize
- setup_rails_dispatcher_prepare_hook
- end
-
- # Called into by the JRuby-Rack java code when an asynchronous message
- # is received.
- def receive_message(queue_name, message)
- listener = listeners[queue_name]
- raise_dispatch_error(message) unless listener
- listener.dispatch(message)
- end
-
- # Sends a message to the named queue. The message is assumed to be a Ruby
- # object that will be marshalled and delivered to a Ruby receiver.
- #
- # If a block is given, the JMS session object is yielded, and allows custom
- # message construction. The block should return a JMS Message object.
- def publish_message(queue_name, message_data = nil, &block)
- with_jms_connection do |connection|
- queue = queue_manager.lookup(queue_name)
- session = connection.createSession(false, Session::AUTO_ACKNOWLEDGE)
- producer = session.createProducer(queue)
- if block
- message = yield session
- elsif String === message_data
- message = session.createTextMessage
- message.setText message_data
- else
- message = session.createBytesMessage
- message.setBooleanProperty(MARSHAL_PAYLOAD, true)
- message.writeBytes(Marshal.dump(message_data).to_java_bytes)
- end
- producer.send(message)
- end
- end
-
- # Register a Ruby listener on the given queue.
- def register_listener(queue_name, listener = nil, &block)
- array_dispatcher = (listeners[queue_name] ||= ArrayMessageDispatcher.new)
- array_dispatcher.add_dispatcher MessageDispatcher.new(block.nil? ? listener : block)
- queue_manager.listen(queue_name)
- end
-
- def unregister_listener(listener)
- listeners.delete_if do |k,v|
- v.delete_listener listener
- if v.empty?
- queue_manager.close(k)
- true
- end
- end
- end
-
- def listeners
- @listeners ||= {}
- end
-
- def clear_listeners
- listeners.clear
- end
-
- # Helper method that yields a JMS connection resource, closing it after
- # the block completes.
- def with_jms_connection
- conn = queue_manager.getConnectionFactory.createConnection
- begin
- yield conn
- ensure
- conn.close
- end
- end
-
- def queue_manager
- @queue_manager ||= JRuby::Rack.context.getAttribute(Java::OrgJrubyRackJms::QueueManager::MGR_KEY)
- end
-
- def raise_dispatch_error(message)
- JRuby::Rack.context.log "Unable to dispatch: #{message.inspect}"
- raise "Unable to dispatch: #{message.inspect}"
- end
-
- def setup_rails_dispatcher_prepare_hook
- if defined?(::Rails)
- begin # Rails 3
- require 'action_dispatch'
- ActionDispatch::Callbacks.to_prepare do
- ::JRuby::Rack::Queues::Registry.clear_listeners
- end
- return
- rescue Exception => e
- end
- begin # Rails 2
- require 'dispatcher'
- dispatcher = defined?(ActionController::Dispatcher) &&
- ActionController::Dispatcher || defined?(::Dispatcher) && ::Dispatcher
- if dispatcher && dispatcher.respond_to?(:to_prepare)
- dispatcher.to_prepare do
- ::JRuby::Rack::Queues::Registry.clear_listeners
- end
- end
- rescue Exception => e
- end
- end
- end
- end
-
- Registry = QueueRegistry.new
-
- class MessageDispatcher
- attr_reader :listener
-
- def initialize(listener)
- @listener = listener
- end
-
- def dispatch(message, listener = nil)
- listener ||= @listener
- begin
- if listener.respond_to?(:on_jms_message)
- listener.on_jms_message(message)
- return
- end
-
- message = convert_message(message)
-
- if listener.respond_to?(:call)
- listener.call(message)
- return
- elsif listener.respond_to?(:on_message)
- listener.on_message(message)
- return
- end
- rescue Exception => e
- JRuby::Rack.context.log("Error during message dispatch: " +
- e.to_s + "\nMessage: #{message.inspect}")
- raise
- end
-
- if Class === listener
- dispatch(message, listener.new)
- else
- JRuby::Rack::Queues::Registry.raise_dispatch_error(message)
- end
- end
-
- def convert_message(message)
- if message.getBooleanProperty(MARSHAL_PAYLOAD)
- payload = ""
- java_bytes = Java::byte[1024].new
- while (bytes_read = message.readBytes(java_bytes)) != -1
- payload << String.from_java_bytes(java_bytes)[0..bytes_read]
- end
- message = Marshal.load(payload)
- elsif message.respond_to?(:getText)
- message = message.getText
- end
- message
- end
- end
-
- class ArrayMessageDispatcher
- def initialize
- @dispatchers = []
- end
-
- def add_dispatcher(d)
- @dispatchers << d unless @dispatchers.detect {|dispatcher| dispatcher.listener == d.listener }
- self
- end
-
- def delete_listener(l)
- @dispatchers.delete_if {|dispatcher| dispatcher.listener == l }
- end
-
- def empty?
- @dispatchers.empty?
- end
-
- def dispatch(message)
- raised_exception = nil
- @dispatchers.each do |l|
- begin
- l.dispatch(message)
- rescue Exception => e
- raised_exception ||= e
- end
- end
- raise raised_exception if raised_exception
- end
- end
- end
- end
-end
-
-require 'jruby/rack/queues/pubsub'
diff --git a/src/main/ruby/jruby/rack/queues/activemq.rb b/src/main/ruby/jruby/rack/queues/activemq.rb
deleted file mode 100644
index 85996ebce..000000000
--- a/src/main/ruby/jruby/rack/queues/activemq.rb
+++ /dev/null
@@ -1,75 +0,0 @@
-#--
-# Copyright (c) 2010-2012 Engine Yard, Inc.
-# Copyright (c) 2007-2009 Sun Microsystems, Inc.
-# This source code is available under the MIT license.
-# See the file LICENSE.txt for details.
-#++
-
-require 'jruby/rack/queues/local'
-
-# Configure ActiveMQ and set up queues and topics to be used. Example:
-#
-# ActiveMQ.configure do |mq|
-# mq.url = 'tcp://somehost:61616'
-# mq.topics = %w(broadcast)
-# mq.queues = %w(point2point)
-# end
-class JRuby::Rack::Queues::ActiveMQ
- def self.configure
- activemq = new
- yield activemq
- ensure
- activemq.register_jndi_properties
- ::JRuby::Rack::Queues::Registry.start_queue_manager
- at_exit do
- ::JRuby::Rack::Queues::Registry.stop_queue_manager
- end
- end
-
- attr_writer :url, :topics, :queues
- attr_accessor :username, :password
-
- def url
- @url ||= "vm://localhost"
- end
-
- def queues
- @queues ||= []
- end
-
- def topics
- @topics ||= []
- end
-
- def register_jndi_properties
- # Based on http://activemq.apache.org/jndi-support.html
- ::JRuby::Rack::Queues::LocalContext.init_parameters["jms.jndi.properties"] = <<-JNDI
-java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
-
-# use the following property to configure the default connector
-java.naming.provider.url = #{url}
-
-#{username && ("java.naming.security.principal = " + username) || ""}
-#{password && ("java.naming.security.credentials = " + password) || ""}
-
-# use the following property to specify the JNDI name the connection factory
-# should appear as.
-#connectionFactoryNames = connectionFactory, queueConnectionFactory, topicConnectionFactory
-
-# register some queues in JNDI using the form
-# queue.[jndiName] = [physicalName]
-#{generate_list('queue.', queues)}
-
-# register some topics in JNDI using the form
-# topic.[jndiName] = [physicalName]
-#{generate_list('topic.', topics)}
-JNDI
- end
-
- private
- def generate_list(prefix, names)
- list = ''
- names.each {|n| list << "#{prefix}#{n} = #{n}\n"}
- list
- end
-end
diff --git a/src/main/ruby/jruby/rack/queues/local.rb b/src/main/ruby/jruby/rack/queues/local.rb
deleted file mode 100644
index bc2f45e00..000000000
--- a/src/main/ruby/jruby/rack/queues/local.rb
+++ /dev/null
@@ -1,96 +0,0 @@
-#--
-# Copyright (c) 2010-2012 Engine Yard, Inc.
-# Copyright (c) 2007-2009 Sun Microsystems, Inc.
-# This source code is available under the MIT license.
-# See the file LICENSE.txt for details.
-#++
-
-require 'jruby/rack/queues'
-
-module JRuby
- module Rack
- module Queues
- class QueueRegistry
- def start_queue_manager
- @queue_manager ||= begin
- dqm = Java::OrgJrubyRackJms::DefaultQueueManager.new
- dqm.init(LocalContext.new)
- dqm
- end
- end
-
- def stop_queue_manager
- @queue_manager.destroy
- end
- end
-
- class LocalRackApplication < java.lang.Object
- include Java::OrgJrubyRack::RackApplication
- def getRuntime
- @runtime ||= begin
- require 'jruby'
- JRuby.runtime
- end
- end
- end
-
- class LocalRackApplicationFactory < java.lang.Object
- include Java::OrgJrubyRack::RackApplicationFactory
- def newApplication
- getApplication
- end
-
- def getApplication
- @app ||= LocalRackApplication.new
- end
-
- def finishedWithApplication(app)
- end
- end
-
- class LocalConfig < java.lang.Object
- include Java::OrgJrubyRack::RackConfig
-
- def getJmsJndiProperties
- LocalContext.init_parameters['jms.jndi.properties']
- end
-
- def getJmsConnectionFactory
- LocalContext.init_parameters['jms.connection.factory']
- end
- end
-
- class LocalContext < java.lang.Object
- include Java::OrgJrubyRack::RackContext
-
- def self.init_parameters
- @params ||= {'jms.connection.factory' => 'ConnectionFactory'}
- end
-
- def self.init_parameters=(params)
- @params = params
- end
-
- def getConfig
- @rack_config ||= LocalConfig.new
- end
-
- def getInitParameter(k)
- self.class.init_parameters[k]
- end
-
- def log(msg, exception = nil)
- puts msg
- while exception.respond_to?(:getCause) && exception.getCause
- exception = exception.getCause
- end
- exception.printStackTrace
- end
-
- def getRackFactory
- @rack_factory ||= LocalRackApplicationFactory.new
- end
- end
- end
- end
-end
diff --git a/src/main/ruby/jruby/rack/queues/pubsub.rb b/src/main/ruby/jruby/rack/queues/pubsub.rb
deleted file mode 100644
index d5e8d52e1..000000000
--- a/src/main/ruby/jruby/rack/queues/pubsub.rb
+++ /dev/null
@@ -1,86 +0,0 @@
-#--
-# Copyright (c) 2010-2012 Engine Yard, Inc.
-# Copyright (c) 2007-2009 Sun Microsystems, Inc.
-# This source code is available under the MIT license.
-# See the file LICENSE.txt for details.
-#++
-
-require 'jruby/rack/queues'
-
-module JRuby::Rack::Queues
- # Include or extend from this module to subscribe to a queue.
- #
- # class MySubscriber
- # extend JRuby::Rack::Queues::MessageSubscriber
- #
- # subscribes_to "MyQ"
- #
- # def on_message(message)
- # # process message here
- # end
- # end
- #
- # An alternative is to pass a block to #subscribe_to for customized
- # message dispatching:
- #
- # class MySubscriber
- # extend JRuby::Rack::Queues::MessageSubscriber
- #
- # subscribes_to "MyQ" do |message|
- # self.new.dispatch msg
- # end
- #
- # def dispatch(message)
- # # process message here
- # end
- # end
- #
- # To receive a message, implement one of #on_jms_message or
- # #on_message. The former has priority and receives the raw JMS message
- # object, while the second receives either the unmarshalled Ruby
- # object or the text content of the message.
- module MessageSubscriber
- def subscribes_to(queue, &block)
- JRuby::Rack::Queues::Registry.register_listener(queue, self, &block)
- end
- end
-
- # Include this module in any class to add a #publish_message method for
- # easy message dispatching. Default queue names can be configured
- # either by defining a #default_destination method that returns the
- # queue name, or by including a custom module returned by the #To
- # method:
- #
- # class MyShinyObject
- # include JRuby::Rack::Queues::MessagePublisher::To("ShinyQ")
- # end
- # obj = MyShinyObject.new
- # obj.publish_message "hi" # => sends to "ShinyQ"
- #
- # The default queue name can still be overridden on a per-call basis
- # by prepending a queue name argument.
- #
- # obj.publish_message "DullQ", "hi" # => sends to "DullQ"
- #
- module MessagePublisher
- def self.To(queue)
- m = Module.new do
- include JRuby::Rack::Queues::MessagePublisher
- define_method :default_destination do
- m.default_destination
- end
- end
- class << m; attr_accessor :default_destination; end
- m.default_destination = queue
- m
- end
-
- def publish_message(*args, &block)
- args_length = args.length + (block ? 1 : 0)
- if args_length < 2 && respond_to?(:default_destination)
- args.unshift default_destination
- end
- JRuby::Rack::Queues::Registry.publish_message(*args[0..1], &block)
- end
- end
-end
diff --git a/src/spec/ruby/jruby/rack/queues/activemq_spec.rb b/src/spec/ruby/jruby/rack/queues/activemq_spec.rb
deleted file mode 100644
index 09f810974..000000000
--- a/src/spec/ruby/jruby/rack/queues/activemq_spec.rb
+++ /dev/null
@@ -1,66 +0,0 @@
-#--
-# Copyright (c) 2010-2012 Engine Yard, Inc.
-# Copyright (c) 2007-2009 Sun Microsystems, Inc.
-# This source code is available under the MIT license.
-# See the file LICENSE.txt for details.
-#++
-
-require File.expand_path('../../../spec_helper', File.dirname(__FILE__))
-require 'jruby/rack/queues/activemq'
-
-describe JRuby::Rack::Queues::ActiveMQ do
- before :each do
- @amq = JRuby::Rack::Queues::ActiveMQ.new
- end
-
- def jndi_properties
- JRuby::Rack::Queues::LocalContext.init_parameters["jms.jndi.properties"]
- end
-
- it "configure should start the queue manager and register an at_exit handler to stop it" do
- JRuby::Rack::Queues::Registry.should_receive(:start_queue_manager).ordered
- JRuby::Rack::Queues::Registry.should_receive(:stop_queue_manager).ordered
- active_mq = JRuby::Rack::Queues::ActiveMQ
- def active_mq.at_exit(&block)
- @exit_block = block
- end
- def active_mq.exit_block
- @exit_block
- end
- active_mq.configure do |amq|
- amq
- end
- active_mq.exit_block.call
- end
-
- it "should put the specified URL in the JNDI properties" do
- @amq.url = "tcp://localhost:61616"
- @amq.register_jndi_properties
- jndi_properties.should =~ /url\s*=\s*tcp:\/\/localhost:61616/
- end
-
- it "should put the username and password in the JNDI properties if present" do
- @amq.register_jndi_properties
- jndi_properties.should_not =~ /java\.naming\.security\.principal/
- jndi_properties.should_not =~ /java\.naming\.security\.credentials/
- @amq.username = 'foo'
- @amq.password = 'bar'
- @amq.register_jndi_properties
- jndi_properties.should =~ /principal\s*=\s*foo/
- jndi_properties.should =~ /credentials\s*=\s*bar/
- end
-
- it "should add one queue entry for each named queue" do
- @amq.queues << "foo" << "bar"
- @amq.register_jndi_properties
- jndi_properties.should =~ /queue\.foo\s*=\s*foo/
- jndi_properties.should =~ /queue\.bar\s*=\s*bar/
- end
-
- it "should add one topic entry for each named topic" do
- @amq.topics << "foo" << "bar"
- @amq.register_jndi_properties
- jndi_properties.should =~ /topic\.foo\s*=\s*foo/
- jndi_properties.should =~ /topic\.bar\s*=\s*bar/
- end
-end
diff --git a/src/spec/ruby/jruby/rack/queues/pubsub_spec.rb b/src/spec/ruby/jruby/rack/queues/pubsub_spec.rb
deleted file mode 100644
index 8f9415d28..000000000
--- a/src/spec/ruby/jruby/rack/queues/pubsub_spec.rb
+++ /dev/null
@@ -1,67 +0,0 @@
-#--
-# Copyright (c) 2010-2012 Engine Yard, Inc.
-# Copyright (c) 2007-2009 Sun Microsystems, Inc.
-# This source code is available under the MIT license.
-# See the file LICENSE.txt for details.
-#++
-
-require File.expand_path('../../../spec_helper', File.dirname(__FILE__))
-require 'jruby/rack/queues'
-
-describe JRuby::Rack::Queues::MessagePublisher do
- it "should delegate #publish_message to JRuby::Rack::Queues::Registry.publish_message" do
- JRuby::Rack::Queues::Registry.should_receive(:publish_message).with("FooQ", "hello")
- obj = Object.new
- obj.extend JRuby::Rack::Queues::MessagePublisher
- obj.publish_message("FooQ", "hello")
- end
-
- it "should allow setting up a default queue name with MessagePublisher::To()" do
- JRuby::Rack::Queues::Registry.should_receive(:publish_message).with("FooQ", "hello").ordered
- JRuby::Rack::Queues::Registry.should_receive(:publish_message).with("BarQ", "hello").ordered
- obj = Object.new
- obj.extend JRuby::Rack::Queues::MessagePublisher::To("FooQ")
- obj.publish_message("hello")
- obj.publish_message("BarQ", "hello")
- end
-
- it "should allow setting up a default queue name with #default_destination" do
- JRuby::Rack::Queues::Registry.should_receive(:publish_message).with("FooQ", "hello")
- obj = Object.new
- obj.extend JRuby::Rack::Queues::MessagePublisher
- def obj.default_destination
- "FooQ"
- end
- obj.publish_message("hello")
- end
-
- it "should ignore unnecessary extra arguments" do
- JRuby::Rack::Queues::Registry.should_receive(:publish_message).with("FooQ", "hello")
- obj = Object.new
- obj.extend JRuby::Rack::Queues::MessagePublisher
- obj.publish_message("FooQ", "hello", 1, 2, 3)
- end
-
- it "should allow omitting the message argument and specifying a block" do
- message = double "message"
- JRuby::Rack::Queues::Registry.should_receive(:publish_message).with("FooQ").ordered.and_yield message
- JRuby::Rack::Queues::Registry.should_receive(:publish_message).with("BarQ").ordered.and_yield message
- obj = Object.new
- obj.extend JRuby::Rack::Queues::MessagePublisher::To("FooQ")
- obj.publish_message do |msg|
- msg.should == message
- end
- obj.publish_message "BarQ" do |msg|
- msg.should == message
- end
- end
-end
-
-describe JRuby::Rack::Queues::MessageSubscriber do
- it "should allow publishing to a queue when including the module" do
- subscriber = Object.new
- subscriber.extend JRuby::Rack::Queues::MessageSubscriber
- JRuby::Rack::Queues::Registry.should_receive(:register_listener).with("FooQ", subscriber)
- subscriber.subscribes_to("FooQ")
- end
-end
diff --git a/src/spec/ruby/jruby/rack/queues_spec.rb b/src/spec/ruby/jruby/rack/queues_spec.rb
deleted file mode 100644
index 857b0afce..000000000
--- a/src/spec/ruby/jruby/rack/queues_spec.rb
+++ /dev/null
@@ -1,245 +0,0 @@
-#--
-# Copyright (c) 2010-2012 Engine Yard, Inc.
-# Copyright (c) 2007-2009 Sun Microsystems, Inc.
-# This source code is available under the MIT license.
-# See the file LICENSE.txt for details.
-#++
-
-require File.expand_path('../../spec_helper', File.dirname(__FILE__))
-require 'jruby/rack/queues'
-
-describe JRuby::Rack::Queues do
-
- before :each do
- JRuby::Rack.context = @servlet_context
- @queue_manager = double "queue manager"
- @servlet_context.stub(:getAttribute).and_return @queue_manager
- @registry = JRuby::Rack::Queues::QueueRegistry.new
- end
-
- after(:all) { JRuby::Rack.context = nil }
-
- def mock_connection
- conn_factory = double "connection factory"
- @queue_manager.should_receive(:getConnectionFactory).and_return conn_factory
- conn = double "connection"
- conn_factory.should_receive(:createConnection).ordered.and_return conn
- conn
- end
-
- def mock_message(text)
- message = double "message"
- message.stub(:getBooleanProperty).and_return false
- message.stub(:getText).and_return text
- message
- end
-
- it "#with_jms_connection should yield a JMS connection" do
- conn = mock_connection
- conn.should_receive(:createMessage).ordered
- conn.should_receive(:close).ordered
-
- @registry.with_jms_connection do |c|
- c.createMessage
- end
- end
-
- it "#publish_message should create a session, producer and message" do
- conn = mock_connection
- queue = double "queue"
- session = double "session"
- producer = double "producer"
- message = double "message"
- @queue_manager.should_receive(:lookup).with("FooQ").and_return queue
- conn.should_receive(:createSession).and_return session
- conn.should_receive(:close)
- session.should_receive(:createProducer).with(queue).and_return producer
- session.should_receive(:createBytesMessage).and_return message
- message.should_receive(:setBooleanProperty).with(JRuby::Rack::Queues::MARSHAL_PAYLOAD, true)
- message.should_receive(:writeBytes)
- producer.should_receive(:send).with(message)
- @registry.publish_message("FooQ", Object.new)
- end
-
- it "#publish_message should accept a block that allows construction of the message" do
- conn = mock_connection
- queue = double "queue"
- session = double "session"
- producer = double "producer"
- message = double "message"
- @queue_manager.should_receive(:lookup).with("FooQ").and_return queue
- conn.should_receive(:createSession).and_return session
- conn.should_receive(:close)
- session.should_receive(:createProducer).with(queue).and_return producer
- session.should_receive(:createTextMessage).and_return message
- producer.should_receive(:send).with(message)
- @registry.publish_message "FooQ" do |sess|
- session.createTextMessage
- end
- end
-
- it "#publish_message should create a text message when handed a string message argument" do
- conn = mock_connection
- queue = double "queue"
- session = double "session"
- producer = double "producer"
- message = double "message"
- @queue_manager.should_receive(:lookup).with("FooQ").and_return queue
- conn.should_receive(:createSession).and_return session
- conn.should_receive(:close)
- session.should_receive(:createProducer).with(queue).and_return producer
- session.should_receive(:createTextMessage).and_return message
- message.should_receive(:setText).with("hello")
- producer.should_receive(:send).with(message)
- @registry.publish_message "FooQ", "hello"
- end
-
- it "#register_listener should ensure the queue manager is listening and store the listener" do
- listener = double "listener"
- @queue_manager.should_receive(:listen).with "FooQ"
- @registry.register_listener "FooQ", listener
- listener.should_receive(:call).with("hi")
- @registry.receive_message("FooQ", mock_message("hi"))
- end
-
- it "#unregister_listener should remove the listener and close the queue" do
- listener = double "listener"
- @queue_manager.should_receive(:listen).with "FooQ"
- @registry.register_listener "FooQ", listener
- @queue_manager.should_receive(:close).with "FooQ"
- @registry.unregister_listener(listener)
- lambda { @registry.receive_message("FooQ", mock_message("msg")) }.should raise_error(RuntimeError)
- end
-
- it "#receive_message should raise an exception if there is no listener for the queue" do
- lambda { @registry.receive_message("NoQ", "hi") }.should raise_error(RuntimeError)
- end
-
- it "#register_listener should allow multiple listeners per queue" do
- listener1 = double "listener 1"
- listener2 = double "listener 2"
- @queue_manager.stub(:listen)
- @registry.register_listener "FooQ", listener1
- @registry.register_listener "FooQ", listener2
- listener1.should_receive(:call).with("hi")
- listener2.should_receive(:call).with("hi")
- @registry.receive_message("FooQ", mock_message("hi"))
- end
-
- it "#register_listener should only allow a given listener to be registered once per queue" do
- listener = double "listener"
- @queue_manager.stub(:listen)
- @registry.register_listener "FooQ", listener
- @registry.register_listener "FooQ", listener
- listener.should_receive(:call).with("hi").once
- @registry.receive_message("FooQ", mock_message("hi"))
- end
-
-
- it "#unregister_listener should only remove the given listener and not close the queue" do
- listener1 = double "listener 1"
- listener2 = double "listener 2"
- @queue_manager.stub(:listen)
- @queue_manager.should_not_receive(:close)
- @registry.register_listener "FooQ", listener1
- @registry.register_listener "FooQ", listener2
- @registry.unregister_listener listener2
- listener1.should_receive(:call).with("hi")
- @registry.receive_message("FooQ", mock_message("hi"))
- end
-
- it "should deliver the message to all listeners, but raise the first of any exceptions raised" do
- listener1 = double "listener 1"
- listener2 = double "listener 2"
- @queue_manager.stub(:listen)
- @registry.register_listener "FooQ", listener1
- @registry.register_listener "FooQ", listener2
- listener1.should_receive(:call).with("hi").and_raise "error 1"
- listener2.should_receive(:call).with("hi").and_raise "error 2"
- lambda { @registry.receive_message("FooQ", mock_message("hi")) }.should raise_error("error 1")
- end
-end
-
-describe JRuby::Rack::Queues::MessageDispatcher do
- before :each do
- $servlet_context = @servlet_context
- @message = double "JMS message"
- @listener = double "listener"
- end
-
- it "should dispatch to an object that responds to #on_jms_message and provide the JMS message" do
- @listener.should_receive(:on_jms_message)
- JRuby::Rack::Queues::MessageDispatcher.new(@listener).dispatch(@message)
- end
-
- it "should unmarshal the message if the marshal payload property is set" do
- @message.should_receive(:getBooleanProperty).with(JRuby::Rack::Queues::MARSHAL_PAYLOAD).and_return true
- first = false
- @message.should_receive(:readBytes).twice do |byte_array|
- if first
- -1
- else
- first = true
- bytes = Marshal.dump("hello").to_java_bytes
- java.lang.System.arraycopy bytes, 0, byte_array, 0, bytes.length
- bytes.length
- end
- end
- @listener.should_receive(:call).with("hello")
- JRuby::Rack::Queues::MessageDispatcher.new(@listener).dispatch(@message)
- end
-
- it "should grab text out of the message if it responds to #getText" do
- @message.stub(:getBooleanProperty).and_return false
- @message.should_receive(:getText).and_return "hello"
- @listener.should_receive(:call).with("hello")
- JRuby::Rack::Queues::MessageDispatcher.new(@listener).dispatch(@message)
- end
-
- it "should pass the message through otherwise" do
- @message.stub(:getBooleanProperty).and_return false
- @listener.should_receive(:call).with(@message)
- JRuby::Rack::Queues::MessageDispatcher.new(@listener).dispatch(@message)
- end
-
- it "should dispatch to a listener that responds to #call" do
- @message.stub(:getBooleanProperty).and_return false
- @listener.should_receive(:call).with(@message)
- JRuby::Rack::Queues::MessageDispatcher.new(@listener).dispatch(@message)
- end
-
- it "should dispatch to a listener that responds to #on_message" do
- @message.stub(:getBooleanProperty).and_return false
- @listener.should_receive(:on_message).with(@message)
- JRuby::Rack::Queues::MessageDispatcher.new(@listener).dispatch(@message)
- end
-
- class Listener
- def self.message; @@message; end
- def on_message(msg)
- @@message = msg
- end
- end
-
- it "should instantiate a class and dispatch to it" do
- @message.stub(:getBooleanProperty).and_return false
- JRuby::Rack::Queues::MessageDispatcher.new(Listener).dispatch(@message)
- Listener.message.should == @message
- end
-
- it "should log and re-raise any exceptions that are raised during dispatch" do
- @message.stub(:getBooleanProperty).and_return false
- @listener.should_receive(:on_message).and_raise "something went wrong"
- @servlet_context.should_receive(:log).with(/something went wrong/)
- lambda do
- JRuby::Rack::Queues::MessageDispatcher.new(@listener).dispatch(@message)
- end.should raise_error(RuntimeError)
- end
-
- it "should raise an exception if it was unable to dispatch to anything" do
- @message.stub(:getBooleanProperty).and_return false
- lambda do
- JRuby::Rack::Queues::MessageDispatcher.new(@listener).dispatch(@message)
- end.should raise_error(RuntimeError)
- end
-end
diff --git a/src/spec/ruby/rack/jms_spec.rb b/src/spec/ruby/rack/jms_spec.rb
deleted file mode 100644
index e94c999df..000000000
--- a/src/spec/ruby/rack/jms_spec.rb
+++ /dev/null
@@ -1,86 +0,0 @@
-#--
-# Copyright (c) 2010-2012 Engine Yard, Inc.
-# Copyright (c) 2007-2009 Sun Microsystems, Inc.
-# This source code is available under the MIT license.
-# See the file LICENSE.txt for details.
-#++
-
-require File.expand_path('spec_helper', File.dirname(__FILE__) + '/..')
-
-java_import org.jruby.rack.jms.QueueContextListener
-java_import org.jruby.rack.jms.QueueManager
-java_import org.jruby.rack.jms.DefaultQueueManager
-
-describe QueueContextListener do
- before :each do
- @qmf = double "queue manager factory"
- @qm = QueueManager.impl {}
- @listener_event = javax.servlet.ServletContextEvent.new @servlet_context
- @listener = QueueContextListener.new @qmf
- end
-
- it "should create a new QueueManager, initialize it and store it in the application context" do
- @qmf.should_receive(:newQueueManager).ordered.and_return @qm
- @qm.should_receive(:init).ordered
- @servlet_context.should_receive(:setAttribute).with(QueueManager::MGR_KEY, @qm).ordered
- @listener.contextInitialized(@listener_event)
- end
-
- it "should capture exceptions during initialization and log them to the servlet context" do
- @qmf.should_receive(:newQueueManager).and_return @qm
- @qm.should_receive(:init).and_raise StandardError.new("something happened!")
- @listener.contextInitialized(@listener_event)
- end
-
- it "should remove the QueueManager and destroy it" do
- qm = QueueManager.impl {}
- @servlet_context.should_receive(:getAttribute).with(QueueManager::MGR_KEY).and_return qm
- @servlet_context.should_receive(:removeAttribute).with(QueueManager::MGR_KEY)
- qm.should_receive(:destroy)
- @listener.contextDestroyed(@listener_event)
- end
-end
-
-describe DefaultQueueManager do
- before :each do
- @connection_factory = double "jms connection factory"
- @context = double "jndi context"
- @queue_manager = DefaultQueueManager.new(@connection_factory, @context)
- @queue_manager.init(@rack_context)
- end
-
- it "should set up a connection with a message listener" do
- app_factory = Java::OrgJRubyRack::RackApplicationFactory.impl {}
- @rack_context.should_receive(:getRackFactory).and_return app_factory
- conn = double "connection"
- @connection_factory.should_receive(:createConnection).and_return conn
- session = double "session"
- conn.should_receive(:createSession).and_return session
- dest = javax.jms.Destination.impl {}
- @context.should_receive(:lookup).with("myqueue").and_return dest
- consumer = double "consumer"
- session.should_receive(:createConsumer).and_return consumer
- consumer.should_receive(:setMessageListener)
- conn.should_receive(:start)
- @queue_manager.listen("myqueue")
- end
-
- it "should shutdown a connection when closed" do
- app_factory = Java::OrgJRubyRack::RackApplicationFactory.impl {}
- @rack_context.stub(:getRackFactory).and_return app_factory
- conn = double "connection"
- @connection_factory.stub(:createConnection).and_return conn
- session = double "session"
- conn.stub(:createSession).and_return session
- dest = javax.jms.Destination.impl {}
- @context.stub(:lookup).with("myqueue").and_return dest
- consumer = double "consumer"
- session.stub(:createConsumer).and_return consumer
- consumer.stub(:setMessageListener)
- conn.should_receive(:start)
- @queue_manager.listen("myqueue")
-
- conn.should_receive(:close)
- @queue_manager.close("myqueue")
- end
-end