@POST @Consumes("application/activemq.jms.topic+xml") public Response createJmsTopic(@Context UriInfo uriInfo, Document document) { ActiveMQRestLogger.LOGGER.debug("Handling POST request for \"" + uriInfo.getPath() + "\""); try { TopicConfiguration topic = FileJMSConfiguration.parseTopicConfiguration(document.getDocumentElement()); ActiveMQTopic activeMQTopic = ActiveMQDestination.createTopic(topic.getName()); String topicName = activeMQTopic.getAddress(); ClientSession session = manager.getSessionFactory().createSession(false, false, false); try { ClientSession.AddressQuery query = session.addressQuery(new SimpleString(topicName)); if (!query.isExists()) { session.createAddress(SimpleString.toSimpleString(topicName), RoutingType.MULTICAST, true); } else { throw new WebApplicationException(Response.status(412).type("text/plain").entity("Queue already exists.").build()); } } finally { try { session.close(); } catch (Exception ignored) { } } URI uri = uriInfo.getRequestUriBuilder().path(topicName).build(); return Response.created(uri).build(); } catch (Exception e) { if (e instanceof WebApplicationException) throw (WebApplicationException) e; throw new WebApplicationException(e, Response.serverError().type("text/plain").entity("Failed to create queue.").build()); } }
@POST @Consumes("application/activemq.jms.topic+xml") public Response createJmsTopic(@Context UriInfo uriInfo, Document document) { ActiveMQRestLogger.LOGGER.debug("Handling POST request for \"" + uriInfo.getPath() + "\""); try { TopicConfiguration topic = FileJMSConfiguration.parseTopicConfiguration(document.getDocumentElement()); ActiveMQTopic activeMQTopic = ActiveMQDestination.createTopic(topic.getName()); String topicName = activeMQTopic.getAddress(); ClientSession session = manager.getSessionFactory().createSession(false, false, false); try { ClientSession.AddressQuery query = session.addressQuery(new SimpleString(topicName)); if (!query.isExists()) { session.createAddress(SimpleString.toSimpleString(topicName), RoutingType.MULTICAST, true); } else { throw new WebApplicationException(Response.status(412).type("text/plain").entity("Queue already exists.").build()); } } finally { try { session.close(); } catch (Exception ignored) { } } URI uri = uriInfo.getRequestUriBuilder().path(topicName).build(); return Response.created(uri).build(); } catch (Exception e) { if (e instanceof WebApplicationException) throw (WebApplicationException) e; throw new WebApplicationException(e, Response.serverError().type("text/plain").entity("Failed to create queue.").build()); } }
private void deploy() throws Exception { if (config == null) { return; } List<ConnectionFactoryConfiguration> connectionFactoryConfigurations = config.getConnectionFactoryConfigurations(); for (ConnectionFactoryConfiguration cfConfig : connectionFactoryConfigurations) { createConnectionFactory(false, cfConfig, cfConfig.getBindings()); } List<JMSQueueConfiguration> queueConfigs = config.getQueueConfigurations(); for (JMSQueueConfiguration qConfig : queueConfigs) { createQueue(false, qConfig.getName(), qConfig.getSelector(), qConfig.isDurable(), qConfig.getBindings()); } List<TopicConfiguration> topicConfigs = config.getTopicConfigurations(); for (TopicConfiguration tConfig : topicConfigs) { createTopic(false, tConfig.getName(), tConfig.getBindings()); } }
@Test public void testParsing() throws Exception { Configuration config = createDefaultInVMConfig() // anything so the parsing will work .addConnectorConfiguration("netty", new TransportConfiguration()); String conf = "activemq-jms-for-JMSServerDeployerTest.xml"; FileJMSConfiguration jmsconfig = new FileJMSConfiguration(); FileDeploymentManager deploymentManager = new FileDeploymentManager(conf); deploymentManager.addDeployable(jmsconfig); deploymentManager.readConfiguration(); assertEquals(1, jmsconfig.getQueueConfigurations().size()); JMSQueueConfiguration queueConfig = jmsconfig.getQueueConfigurations().get(0); assertEquals("fullConfigurationQueue", queueConfig.getName()); assertEquals(1, jmsconfig.getTopicConfigurations().size()); TopicConfiguration topicConfig = jmsconfig.getTopicConfigurations().get(0); assertEquals("fullConfigurationTopic", topicConfig.getName()); }
List<CoreAddressConfiguration> coreAddressConfigurations = configuration.getAddressConfigurations(); coreAddressConfigurations.add(new CoreAddressConfiguration() .setName(topicConfig.getName()) .addRoutingType(RoutingType.MULTICAST));
Assert.assertTrue(o instanceof Topic); Topic topic = (Topic) o; Assert.assertEquals(topicConfig.getName(), topic.getTopicName());