I am trying to pause a JMS Queue from a Message Driven Bean on a weblogic server using JMX. The idea is that if the message fails to execute a set number of times then it pauses the queues consumption. When I attempt to connect via JMX it is failing, even though it is running within the WebLogic container.
Following is the code I am using, which fails on the call to JMSRuntimeHelper.getJMSDestinationRuntimeMBean( ctx, queue );
The code below works fine if I run it within a Session Facade bean called via a business delegate (i.e. t3/rmi connection).
Category access = OpenTwinsClientProperties.getInstance().getCategory( OpenTwinsClientProperties.CATEGORY_ACCESS );
String destinationAddresses = access.getValue( OpenTwinsClientProperties.ACCESS_PROVIDER_URL );
final String protocol = StringUtils.substringBefore( destinationAddresses, "://" );
destinationAddresses = StringUtils.removeStart( destinationAddresses, protocol );
final String[] destinations = StringUtils.split( destinationAddresses, ',' );
String[] hostAndPort = null;
for ( String destination : destinations ) {
hostAndPort = destination.split( ":" );
}
JMXServiceURL serviceURL;
JMXConnector jmxConnection = null;
String jndiName = null;
try {
serviceURL = new JMXServiceURL( protocol, hostAndPort[1].split( "//" )[1], Integer.parseInt( hostAndPort[2] ), "/jndi/" + DomainRuntimeServiceMBean.MBEANSERVER_JNDI_NAME );
Hashtable<String, String> h = new Hashtable<String, String>();
h.put( Context.SECURITY_PRINCIPAL, "weblogic" );
h.put( Context.SECURITY_CREDENTIALS, "password1" );
h.put( JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote" );
MBeanServerConnection bco;
jmxConnection = JMXConnectorFactory.connect( serviceURL, h );
bco = jmxConnection.getMBeanServerConnection();
InitialContext ctx = OpenTwinsFrontendUtilities.getInitialContext( false );
//ctx.addToEnvironment( Context.SECURITY_PRINCIPAL, "weblogic" );
//ctx.addToEnvironment( Context.SECURITY_CREDENTIALS, "password1" );
Destination queue = (Destination) ctx.lookup( "jms/JMSAccessNotificationQueue" );
JMSDestinationRuntimeMBean destMBean = JMSRuntimeHelper.getJMSDestinationRuntimeMBean( ctx, queue );
destMBean.pauseProduction();
destMBean.pauseConsumption();
} catch(NameNotFoundException ex){
ex.printStackTrace();
} catch(Throwable ex){
ex.printStackTrace();
} finally {
if ( jmxConnection != null ) {
try {
jmxConnection.close();
} catch ( IOException ex1 ) {
}
}
Following is the exception message I get:
Caused By: javax.naming.NoPermissionException: User <anonymous> does not have permission on weblogic.management.mbeanservers to perform lookup operation.
at weblogic.jndi.internal.ServerNamingNode.checkPermission(ServerNamingNode.java:449)
at weblogic.jndi.internal.ServerNamingNode.checkLookup(ServerNamingNode.java:429)
at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:180)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:206)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:220)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:220)
at weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:254)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:413)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at weblogic.management.remote.wlx.ClientProvider.findRMIServer(ClientProvider.java:131)
at weblogic.management.remote.wlx.ClientProvider.newJMXConnector(ClientProvider.java:98)
at javax.management.remote.JMXConnectorFactory.newJMXConnector(JMXConnectorFactory.java:339)
at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248)
at weblogic.jms.common.JMSEditHelper.lookupMBeanServerConnection(JMSEditHelper.java:79)
at weblogic.jms.common.JMSEditHelper.getRuntimeService(JMSEditHelper.java:137)
at weblogic.jms.common.JMSEditHelper.getDomainRuntimeService(JMSEditHelper.java:165)
- I have tried to provide the credentials in the initial context, but this made no difference.
- I have tried to tick Anonymous Admin Lookup Enabled in the WebLogic console, but this made no difference.
How can I gain the trust of the WebLogic container within a message driven bean so that I can pause the queue?