/** * Parse the JMS Configuration XML */ public void parseConfiguration(final Node rootnode) throws Exception { ArrayList<JMSQueueConfiguration> queues = new ArrayList<>(); ArrayList<TopicConfiguration> topics = new ArrayList<>(); Element e = (Element) rootnode; String[] elements = new String[]{QUEUE_NODE_NAME, TOPIC_NODE_NAME}; for (String element : elements) { NodeList children = e.getElementsByTagName(element); for (int i = 0; i < children.getLength(); i++) { Node node = children.item(i); Node keyNode = node.getAttributes().getNamedItem(NAME_ATTR); if (keyNode == null) { ActiveMQJMSServerLogger.LOGGER.jmsConfigMissingKey(node); continue; } if (node.getNodeName().equals(TOPIC_NODE_NAME)) { topics.add(parseTopicConfiguration(node)); } else if (node.getNodeName().equals(QUEUE_NODE_NAME)) { queues.add(parseQueueConfiguration(node)); } } } String domain = XMLConfigurationUtil.getString(e, JMX_DOMAIN_NAME, ActiveMQDefaultConfiguration.getDefaultJmxDomain(), Validators.NO_CHECK); newConfig(queues, topics, domain); }
@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()); } }