com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links' is unknown.
Adding JMX Subscriptions to a Resource
- A JMX type Subscription can be added to a resource through UI just like any other Subscription. To learn how to add Subscriptions to a resources please refer Managing Subscriptions and Notifications.
Likewise any other subscription it is also possible to write an external client to add JMX subscriptions to a resource. Since we have not provide any API methods to perform Subscription related operations it is necessary to use one of the Admin Services of Registry to do the relevant. In the given below example we have used
InfoAdminService
to add a subscription to a resource.public class JMXSubscriptionClient { private static final Log log = LogFactory.getLog(JMXSubscriptionClient.class); private static InfoAdminServiceStub stub; private static ConfigurationContext itsConfigCtx; //server URL of a running GReg instance private static String serverURL = "https://localhost:9443/services/"; //username and password of that running Greg instance private static String username = "admin"; private static String password = "admin"; private static String cookie; public static void main(String[] args) { try { // admin service endpoint URL String Endpoint = serverURL + "InfoAdminService"; //creating the configuration context Initialization(); //authenticating and logging to access the service authenticate(itsConfigCtx); //creating the InfoAdminServiceStub out of the service stub = new InfoAdminServiceStub(itsConfigCtx, Endpoint); //setting Axis2 options ServiceClient client = stub._getServiceClient(); Options option = client.getOptions(); option.setManageSession(true); option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie); try { //Add a Subscription to the /_system/governance/clientResource SubscriptionBean bean = stub.subscribe("/_system/governance/clientResource", "jmx://", "ResourceUpdated", cookie); } catch (RemoteException e) { e.printStackTrace(); } catch (RegistryExceptionException e) { String msg = "Error occurred while doing subscription operations"; log.error(msg, e); } } catch (AxisFault axisFault) { String msg = axisFault.getMessage(); log.error(msg, axisFault); } } private static boolean authenticate(ConfigurationContext itsConfigCtx) { String serviceEPR = serverURL + "AuthenticationAdmin"; AuthenticationAdminStub stub = null; try { stub = new AuthenticationAdminStub(itsConfigCtx, serviceEPR); ServiceClient client = stub._getServiceClient(); Options options = client.getOptions(); options.setManageSession(true); try { // login to the defined server instance boolean result = stub.login(username, password, new URL(serviceEPR).getHost()); if (result) { cookie = (String) stub._getServiceClient().getServiceContext().getProperty(HTTPConstants.COOKIE_STRING); } return result; } catch (Exception e) { String msg = "Error occurred while logging in" + e.getMessage(); log.error(msg, e); } } catch (AxisFault axisFault) { String msg = axisFault.getMessage(); log.error(msg, axisFault); } return false; } private static void Initialization() { // location of the server String GREG_HOME = "/home/test/wso2greg-4.5.0"; String axis2Repo = GREG_HOME + File.separator + "repository" + File.separator + "deployment" + File.separator + "client"; String axis2Conf = GREG_HOME + File.separator + "repository" + File.separator + "conf" + File.separator + "axis2" + File.separator + "axis2_client.xml"; String trustStore = GREG_HOME + File.separator + "repository" + File.separator + "resources" + File.separator + "security" + File.separator + "wso2carbon.jks"; System.setProperty("javax.net.ssl.trustStore", trustStore); System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon"); System.setProperty("javax.net.ssl.trustStoreType", "JKS"); System.setProperty("carbon.repo.write.mode", "true"); try { // creating the configuration context itsConfigCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(axis2Repo, axis2Conf); } catch (AxisFault axisFault) { String msg = "An Error occured while creating the Configuration Context" + axisFault.getMessage(); log.error(msg, axisFault); } } }
- To write and run this client it is necessary to have
InfoAdminServiceStub
andAuthenticationAdminStub
in the classpath of the project.AuthenticationAdminStub
would get added to the classpath when user run ant inside$GREG_HOME/bin
and point classpath of the project to$GREG_HOME/repository/lib.
But the user have to separately add InfoAdminServiceStub
to classpath from$GREG_HOME/repository/components/plugins
. - In this sample we have only added a JMX type subscription to a resource. Similarly it is possible to use the stub class to
unsubscribe()
andgetSubscriptions()
from a resource as well. - When adding subscriptions it is necessary to pass the following parameters
- path of the resource to where the subscription should get added to.
- subscription endpoint as
jmx://
to make the subscription JMX. - event typeof subscription as user preferred. E.g. - ResourceUpdated.
- session Cookie.
- According to the given above sample now a subscription is added to the resource at
/_system/governance/clientResource.
When the resource is accessed from the UI the added subscription would be visible to the user. And when ever the resource get updated the user would be able to view corresponding event through JMX Console. Refer Using JConsole to Monitor and Manage Governance Registry
com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links2' is unknown.