/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.messaging.test; import java.net.HttpURLConnection; import java.net.URL; import java.util.List; import org.jboss.dmr.ModelNode; import org.jboss.dmr.Property; /** * Semi-emulates what the console does in its JMS handling in an attempt to debug AS7-1641. * * @author Brian Stansberry (c) 2011 Red Hat Inc. */ public class Test1641 { public static void main(String[] args) { try { ModelNode operation = new ModelNode(); operation.get("operation").set("read-resource"); operation.get("recursive").set(true); operation.get("address").add("subsystem", "messaging"); URL url = new URL("http://localhost:9990/management/"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Content-Type", "application/dmr-encoded"); connection.setRequestMethod("POST"); connection.setDoOutput(true); connection.connect(); operation.writeBase64(connection.getOutputStream()); ModelNode httpnode = ModelNode.fromBase64(connection.getInputStream()); System.out.println(httpnode.toString()); ModelNode result = httpnode.get("result"); parseFactories(result); parseQueues(result); parseTopics(result); } catch (Exception e) { e.printStackTrace(); } } private static void parseQueues(ModelNode response) { System.out.println("Queues"); List propList = response.get("jms-queue").asPropertyList(); for(Property prop : propList) { System.out.println(prop.getName()); ModelNode propValue = prop.getValue(); System.out.println(propValue.get("entries").asList().get(0).asString()); if(propValue.hasDefined("durable")) System.out.println(propValue.get("durable").asBoolean()); if(propValue.hasDefined("selector")) System.out.println(propValue.get("selector").asString()); } } private static void parseTopics(ModelNode response) { System.out.println("Topics"); List propList = response.get("jms-topic").asPropertyList(); for(Property prop : propList) { String name =prop.getName(); ModelNode propValue = prop.getValue(); String jndi = propValue.get("entries").asList().get(0).asString(); System.out.println(name + " has jndi name " + jndi); } } private static void parseFactories(ModelNode response) { try { // factories System.out.println("Connection factories"); List factories = response.get("connection-factory").asPropertyList(); for(Property factoryProp : factories) { String name = factoryProp.getName(); ModelNode factoryValue = factoryProp.getValue(); String jndi = factoryValue.get("entries").asList().get(0).asString(); System.out.println(name + " has jndi name " + jndi); } } catch (Throwable e) { e.printStackTrace(); } } }