Advertisement
Guest User

Untitled

a guest
Feb 19th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. import java.util.Hashtable;
  2. import javax.management.MBeanServerConnection;
  3. import javax.management.remote.JMXConnector;
  4. import javax.management.remote.JMXConnectorFactory;
  5. import javax.management.remote.JMXServiceURL;
  6. import javax.management.ObjectName;
  7. import javax.naming.Context;
  8. import weblogic.management.mbeanservers.runtime.RuntimeServiceMBean;
  9.  
  10. public class PurgeWLSQueue {
  11.  
  12. private static final String WLS_USERNAME = "weblogic";
  13. private static final String WLS_PASSWORD = "weblogic";
  14. private static final String WLS_HOST = "localhost";
  15. private static final int WLS_PORT = 7001;
  16. private static final String JMS_SERVER = "wlsbJMSServer";
  17. private static final String JMS_DESTINATION = "test.q";
  18.  
  19. private static JMXConnector getMBeanServerConnector(String jndiName) throws Exception {
  20. Hashtable<String,String> h = new Hashtable<String,String>();
  21. JMXServiceURL serviceURL = new JMXServiceURL("t3", WLS_HOST, WLS_PORT, jndiName);
  22. h.put(Context.SECURITY_PRINCIPAL, WLS_USERNAME);
  23. h.put(Context.SECURITY_CREDENTIALS, WLS_PASSWORD);
  24. h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote");
  25. JMXConnector connector = JMXConnectorFactory.connect(serviceURL, h);
  26. return connector;
  27. }
  28.  
  29. public static void main(String[] args) {
  30. try {
  31. JMXConnector connector =
  32. getMBeanServerConnector("/jndi/"+RuntimeServiceMBean.MBEANSERVER_JNDI_NAME);
  33. MBeanServerConnection mbeanServerConnection =
  34. connector.getMBeanServerConnection();
  35.  
  36. ObjectName service = new ObjectName("com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean");
  37. ObjectName serverRuntime = (ObjectName) mbeanServerConnection.getAttribute(service, "ServerRuntime");
  38. ObjectName jmsRuntime = (ObjectName) mbeanServerConnection.getAttribute(serverRuntime, "JMSRuntime");
  39. ObjectName[] jmsServers = (ObjectName[]) mbeanServerConnection.getAttribute(jmsRuntime, "JMSServers");
  40. for (ObjectName jmsServer: jmsServers) {
  41. if (JMS_SERVER.equals(jmsServer.getKeyProperty("Name"))) {
  42. ObjectName[] destinations = (ObjectName[]) mbeanServerConnection.getAttribute(jmsServer, "Destinations");
  43. for (ObjectName destination: destinations) {
  44. if (destination.getKeyProperty("Name").endsWith("!"+JMS_DESTINATION)) {
  45. Object o = mbeanServerConnection.invoke(
  46. destination,
  47. "deleteMessages",
  48. new Object[] {""}, // selector expression
  49. new String[] {"java.lang.String"});
  50. System.out.println("Result: "+o);
  51. break;
  52. }
  53. }
  54. break;
  55. }
  56. }
  57. connector.close();
  58. } catch (Exception e) {
  59. e.printStackTrace();
  60. }
  61. }
  62. }
  63.  
  64. connect('weblogic', 'weblogic', 't3://localhost:7005')
  65. serverRuntime()
  66.  
  67. cd('/JMSRuntime/ManagedSrv1.jms/JMSServers/MyAppJMSServer/Destinations/MyAppJMSModule!QueueNameToClear')
  68.  
  69. cmo.deleteMessages('')
  70.  
  71. ObjectName service = new ObjectName("com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement