I'm trying to figure out how to stop a service on Sonic ESB 7.6;


In the class I defined for this, I've a status component, which I cannot seem to get running correctly, as I do keep getting either null pointers or invoke errors:

What I tried so far:

(already connected with ESBAPI esbApi, as well as a JMSConnectorClient connector)


        IContainerConfigAPI cca = esbApi.getContainerConfigAPI();

        String containernames[] = cca.listESBContainers();
        for(String containername : containernames)
        {

               String mfcontainers[] = cca.listMFContainersWithESBContainer(containername);

            for(String mfcontainer : mfcontainers)
            {
                if(mfcontainer.contains("MyName")) /* there's a specific reason why I catch this one, for now to reduce a bit of overhead */
                {
                    System.out.printf("Container: %s \n", mfcontainer);
                    try{
                        IAgentProxy iap = MFProxyFactory.createAgentProxy(connector,
                                new ObjectName(sci.domainName + "." + mfcontainer + ":ID=AGENT"));
                        System.out.printf("%s is %s\n",mfcontainer,iap.getStateString());
                   
                        //IContainerConfig icc = cca.getESBContainer(sci.domainName + "." + mfcontainer + ":ID=" + containername); /* something goes wrong here, as I keep getting null */
                        IContainerConfig icc = cca.getESBContainer(iap.getConfigID());                                                                      /* goes wrong as well, also getting null */
                       
                        if(iap.getStateString().equals("Online"))
                        {
                            ICollectionsMonitorProxy icmp = MFProxyFactory.createCollectionsMonitorProxy(connector,
                                    new ObjectName(sci.domainName + "." + mfcontainer + ":ID=" + containername));
                            System.out.printf("iap: %s; icmp: %s\n",iap.toString(),icmp.toString());
                            System.out.printf("AgentProxy: %s.%s:ID=AGENT\n",sci.domainName,mfcontainer);
                            System.out.printf("IContainerConfig: %s.%s:ID=%s\n", sci.domainName,mfcontainer,containername);
                            if(icc == null)
                            {
                                System.out.printf("ContainerConfig: <null>\n"); /* this is the output I get and do not want */
                            }
                            else
                            {
                                System.out.printf("ContainerConfig: Name: %s\n",icc.getName());
                            }
                            if(icmp == null)
                            {
                                System.out.printf("icmp is null...\n");
                            }
                            else
                            if(icmp.getStateString().equals("Online"))
                            {
                                System.out.printf("Info: mfcontainer: %s, containername %s\n",mfcontainer,containername);
                                IContainerRuntimeAPI cra = esbApi.getContainerRuntimeAPI(mfcontainer,containername);
                                System.out.printf("Info: Container Runtime API created.\n");
                                ESBArtifactInfo artifacts[] = cra.getArtifacts(); /* this one always causes a stack trace "Failed invoke" */
                                ESBArtifactInfo pi =  cra.getProcessInfo("monitorService");
                               
                                System.out.printf("Info: Obtained artifacts.\n");
                                for(ESBArtifactInfo artifact : artifacts)
                                {
                                    int ArtifactState = artifact.getCurrentState();
                                    String ArtifactName = artifact.getName();
                                    System.out.printf("%s is %d\n", ArtifactName,ArtifactState);
                                }
                            }
                        }
                        else
                        {
                            System.out.printf("Container: %s is not active.\n",mfcontainer);
                        }
                    }
                    catch(Exception e)
                    {
                        e.printStackTrace();
                    }
                }
                else
                {
                    System.out.printf("Container \"%s\" not matched.\n",mfcontainer); /* to show that we do iterate */
                }
            }

Anyone who can tell what is wrong in my approach?