Customize to start Nucleus manually inside your java class

There is  a  simple approach to Initiate nucleus manually.Knowing this may help to customize Nucleus,like Override the default behavior,writing a custom junit test for testing profiles,repositories, etc.

ATG has tools which Initiate Nucleus as a standalone to perform  some of their tasks.You might have used StartSqlRepository,the StartSqlRepositoy
Initiate the nucleus as standalone.You need to take care of mapping the Repositories to appropriate Datasources.This is generally achieved through FakeXAComponents.All this are already available OOTB,but you can also start Nucleus manually doing some simple customization.


Below are the customizations you need to do to start Nucleus manually,the modules given here are OOTB,additionally you need to include your respective modules and custom modules to resolve the necessary components.

Define a component mynucleus and configure it in your build path.

atg.dynamo.home=C:\\ATG\\ATG10.2\\home
atg.dynamo.root=C:\\ATG\\ATG10.2
atg.dynamo.modules=DafEar.Admin;DAS;DPS;DSS;
atg.dynamo.display=
atg.dynamo.modulepath=C:\\ATG\\ATG10.2
atg.dynamo.layers=
atg.config.path=C:\\ATG\\ATG10.2\\DAS\\config\\config.jar;\
C:\\ATG\\ATG10.2\\DafEar\\base\\config\\dafconfig.jar;\
C:\\ATG\\ATG10.2\\DPS\\config\\userprofiling.jar;\
C:\\ATG\\ATG10.2\\DPS\\config\\profile.jar;\
C:\\ATG\\ATG10.2\\DPS\\config\\targeting.jar;\
C:\\ATG\\ATG10.2\\DSS\\config\\config.jar;\
C:\\ATG\\ATG10.2\\home\\localconfig;\
C:\\ATG\\ATG10.2\\home\\servers\\myserver\\localconfig
dataDir=C:\\ATG\\ATG10.2\\home\\data
atg.dynamo.server.home=C:\\ATG\\ATG10.2\\home\\servers\\myserver
serverName=myserver
java.protocol.handler.pkgs=atg.net.www.protocol
java.naming.factory.url.pkgs=atg.jndi.url
java.naming.factory.initial=weblogic.jndi.WLInitialContextFactory


Do the below Imports in your file.

import atg.applauncher.dynamo.DynamoServerLauncher;
import atg.naming.NameResolver;
import atg.nucleus.Nucleus;
import atg.servlet.*;
import atg.servlet.pipeline.HeadPipelineServlet;
import java.io.PrintStream;
import java.util.Enumeration;
import java.util.ResourceBundle;


Give Below the code for Class,you need to implements the interface NameResolver and write the implementation for the method resolvename in your code.


public class mynucleus implements NameResolver{


    public mynucleus()
    {
    }


public DynamoHttpServletRequest getRequest()
    {
        return request;
    }
 public DynamoHttpServletResponse getResponse()
    {
        return response;
    }
 public static Nucleus getTestNucleus()
    {
        return testNucleus;
    }

 private static void loadNucleusPath()
        {
            String key;
            for(Enumeration em = RESOURCE_BUNDLE.getKeys(); em.hasMoreElements(); System.setProperty(key,

RESOURCE_BUNDLE.getString(key)))
            {
                key = (String)em.nextElement();
                System.out.println((new StringBuilder(String.valueOf(key))).append(":").append

(RESOURCE_BUNDLE.getString(key)).toString());
            }

        }

        private static void startNucleus()
        {
            String as[] = {
                System.getProperty("atg.dynamo.modules"), System.getProperty("atg.config.path"), "-

prefix", System.getProperty("serverName")
            };
            DynamoServerLauncher.main(as);
            HeadPipelineServlet headpipelineservlet = (HeadPipelineServlet)Nucleus.getGlobalNucleus

().resolveName("/atg/dynamo/servlet/dafpipeline/DynamoHandler");
            request = headpipelineservlet.getRequest(null);
            testNucleus = Nucleus.getGlobalNucleus();
            response = new DynamoHttpServletResponse();
            response.setResponse(new GenericHttpServletResponse());
            response.setOutputStream(new ByteArrayServletOutputStream());
        }

        private static Nucleus testNucleus = null;
        private static LoggerUtil loggerInstance;
        private static DynamoHttpServletRequest request = null;
        private static DynamoHttpServletResponse response = null;
        private static final String BUNDLE_NAME = "com.atg.MyConfig";
        private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle

("com.atg.MyConfig");

        static
        {
            loggerInstance = LoggerUtil.getInstance();
            loadNucleusPath();
            startNucleus();
            loggerInstance.setLoggingDebug(true);
        }

 public Object resolveName(String s)
    {
        return getRequest().resolveName(s);
    }
}

Finally from your test class call the method to resolve the component
eg:
Profile profile = (Profile) resolveName("/atg/userprofiling/Profile");

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...