Writing you own WCS controller command

Steps involved in writing you own controller command are

  1. Writing controller command interface 
    • As this is  your first command it is best if you stop your server
    • Open WCS developer and  go to Java EE view
    • In the Enterprise Explorer view open WebSphereCommerceServerExtensionsLogic and right click on src folder and create a new interface (new > Interface)
    • In the inftrace creation wizad fill in below details and click finsh:
      • Name:  HelloWcsCmd 
      • Package: com.developernotes.wcs.commands
      • Extended interface:   com.ibm.commerce.command.ControllerCommand  (Click on add button and search for ControllerCommand)
    • In the interface class HelloWcsCmd.java enter below code:
    • // default implement class
        static final String defaultCommandClassName = 
         "com.developernotes.wcs.commands.HelloWcsCmdImpl";
  2. Writing controller command implementation class.
    • In the Enterprise Explorer view open WebSphereCommerceServerExtensionsLogic and right click on src folder and create a new java class (new > Class)
    • In the class creation wizad fill in below details and click finish:
      • Name: HelloWcsCmdImpl
      • Package: com.developernotes.wcs.commands
      • SuperClass:  com.ibm.commerce.command.ControllerCommandImpl (Click browse and search for  ControllerCommandImpl)
      • Interface:  com.developernotes.wcs.commands.HelloWcsCmd (click add search for you interface and add)
    • In the implementation  class HelloWcsCmdImpl.java enter below code: 
    • @Override
      public void performExecute() throws ECException {
       super.performExecute();
       System.out.println("Hello WCS");
      }
  3. Adding Struts entry
    • Open struts-config-ext.xml in Stores web-project in Struts Configuration File Editor
    • Go to Action Mappings tab in Struts Configuration File Editor 
    • Under  Actions Mappings section, click Add button. Delete the default path value(default is /action1) and enter /hellowcs for the path value. 
    • Under Action Mapping attributes, enter com.ibm.commerce.struts.BaseAction in the Type attribute and  in Parameter attribute enter com.test.wcs.commands.HelloWcsCmd . The parameter attribute contains  interface name of the logic/java class that we need to be executed.
    • Save struts-config-ext.xml  
    • Restart your server so that the status changes take effect [Apply Struts changes with out server restart]
  4. Adding controller command in the command registry (optional)
    • You don't need to do this this to make your command work. Command registry is used when you need to specify which implementation the interface class/command should call for a particular store. 
  5. Setting up  access control for a controller command
    • Create a file HelloWcsCmdACPolicy.xml enter below xml in this file.
    • 
      
      
      
      
      
      
      
        
       
       
      
         
       
      
      
       
    • Place the file in  xml\policies\xml directory which you can find with in you WebSphere Commerce Developer installation directory.  
    • Run acplod  [ Acpload command ]
Start you server and go to http://localhost/webapp/wcs/stores/servlet/hellowcs . In the console if  you can see the message "Hello WCS" your first command ran successfully.

Reference : http://publib.boulder.ibm.com/infocenter/wchelp/v7r0m0/index.jsp


No comments:

Post a Comment