Topic
  • No replies
Robert_Rine
Robert_Rine
4 Posts

Pinned topic WID 7 - Pause inbound MQ endpoint within Java code.

‏2012-11-19T17:20:20Z |
I am attempting to pause an inbound MQ endpoint from within Java code using WID 7/WPS 7. I am using code similar to the following:


AdminService adminService = AdminServiceFactory.getAdminService();   

try 
{ ObjectName queryName = 

new ObjectName(
"*:type=J2CMessageEndpoint,*"); Set endpointSet = adminService.queryNames(queryName, 

null); javax.security.auth.login.LoginContext lc = 

null; javax.security.auth.Subject subject = 

null;   

try 
{ lc = 

new javax.security.auth.login.LoginContext(
"WSLogin", 

new com.ibm.websphere.security.auth.callback.WSCallbackHandlerImpl(
"admin", 
"admin")); 
} 

catch (javax.security.auth.login.LoginException le) 
{ System.out.println(
"Cannot create LoginContext. " + le.getMessage()); 
// Insert the error processing code  
} 

catch(SecurityException se) 
{ 
// Insert the error processing code  
}   

try 
{ lc.login(); subject = lc.getSubject(); 
// setting the subject on the thread to use for outbound requests.  
// Note: This overrides the existing subject which you might want to save first.  com.ibm.websphere.security.auth.WSSubject.setRunAsSubject(subject); 
} 

catch(javax.security.auth.login.LoginException le) 
{ System.out.println(
"Fails to create Subject. " + le.getMessage()); 
// Insert the error processing code 
}     Iterator iter = endpointSet.iterator(); 

for(

int i = 0; i < endpointSet.size(); i++) 
{ ObjectName mBean = (ObjectName)(iter.next()); MBeanInfo mBeanInfo = adminService.getMBeanInfo(mBean); String canonicalName = mBean.getCanonicalName(); String serverName = com.ibm.websphere.runtime.ServerName.getDisplayName(); 

if(canonicalName != 

null) 
{ 

if(!(canonicalName.trim().equals(
""))) 
{ String canonicalNamePrefix = 
"WebSphere:ActivationSpec="; 

if(canonicalName.startsWith(canonicalNamePrefix)) 
{ String actSpecJNDINameWorkString = canonicalName.substring(canonicalNamePrefix.length(), canonicalName.length()); 

int firstComma = actSpecJNDINameWorkString.indexOf(
","); actSpecJNDINameWorkString = actSpecJNDINameWorkString.substring(0, firstComma); 

if(actSpecJNDINameWorkString.equals(
"jndi/TOWPS.EXAMPLE.MQ.AS")) 
{ Object params[] = 
{
}; String signature[] = 
{
}; Object result = adminService.invoke(mBean, 
"pause", params, signature); 
} 
} 
} 
} 
} 
} 

catch(Exception e) 
{ e.printStackTrace(); 
}


The code first switches the process to run as the admin user, since there were errors trying to invoke a method on the Mbean running as UNAUTHENTICATED. Then, I search through all the J2CMessageEndpoint Mbeans to find the one associated with the ActivationSpec I created for the inbound queue. I attempt to invoke pause on the right Mbean, and it just hangs there. The server will hang on that statement until I attempt to stop the server. Only then will it pause the endpoint. Has anyone attempted to do this, or seen similar behavior? Any help will be greatly appreciated.