invoke(method, name); }
public static void destroyDestination(Class type, String name) throws Exception { String method = null; if (type == Topic.class) { method = "destroyTopic"; } else if (type == Queue.class) { method = "destroyQueue";} invoke(method, name); }
protected static void invoke(String method, String destName) throws Exception { try { MBeanServer server = (MBeanServer) MBeanServerFactory.findMBeanServer(null).iterator().next(); invokeViaMBean(method, destName); }catch(Exception ex) { invokeViaUrl(method, destName);} } protected static void invokeViaUrl(String method, String destName) throws Exception { String action = "action=invokeOp&methodIndex=6&name=jboss.mq%3Aservice%3DDestinationManager&arg0=" + destName; String arg = BASE_URL_ARG + action; URL url = new URL("http", HOST, PORT, arg); HttpURLConnection con = (HttpURLConnection)url.openConnection(); con.connect();
InputStream is = con.getInputStream(); java.io.ByteArrayOutputStream os = new java.io.ByteArrayOutputStream(); byte[] buff = new byte[1024]; for(;;) { int size = is.read( buff ); if (size == -1 ) { break; } os.write(buff, 0, size); } os.flush();
if (con.getResponseCode() != HttpURLConnection.HTTP_OK ) { throw new Exception ("Could not invoke url: " + con.getResponseMessage() ); } else { System.out.println("Invoked URL: " + method + " for destination " + destName + "got resonse: " + os.toString()); } } protected static void invokeViaMBean(String method, String destName) throws Exception { MBeanServer server = (MBeanServer)MBeanServerFactory.findMBeanServer(null).iterator().next(); server.invoke(new ObjectName("JBossMQ", "service", "DestinationManager"), method, new Object[] { destName }, new String[] { "java.lang.String" }); } public static void main(String[] args) { try { if (args.length >0){ destroyDestination(Topic.class,"myCreated"); }else { createDestination(Topic.class,"myCreated"); } }catch(Exception ex) { System.out.println("Error in administering destination: " + ex); ex.printStackTrace(); } }
} 编辑命令: javac -classpath C:jboss-3.0.6_tomcat-4.1.18clientjbossall-client.jar;C:jboss-3.0.6_tomcat-4.1.18libjboss-jmx.jar;. DestinationHelper.java 运行命令 java -classpath C:jboss-3.0.6_tomcat-4.1.18clientjbossall-client.jar;C:jboss-3.0.6_tomcat-4.1.18libjboss-jmx.jar;. DestinationHelper
上一篇:JBoss v3.0 与Tibco JMS的整合
下一篇:JBoss-3.0.1RC1_Tomcat-4.0.4中的安全
|