Monday, July 24, 2017

REST - Interoperability (manage sessions on multiple channel) WCtoken and Web Identitytoken

Interoperability of Commerce Tokens between web and rest Channel at same time 

WebSphere commerce FEP8 onwards supports concurrent active session for user on web as well as on Rest channel as same time. However if you are on a lower version of Commerce below are the steps to make your application work seamlessly.

Step 1: If you are on a version lower than WCS 7, FEP 8;  you need to install an APAR JR45670.
Step 2: After installation of APAR you need to extend the Command SimultaneousLogonHelperCmdImpl and override functions as below:

    public boolean isReusingActivityTokenAllowed() {
        final String METHODNAME = "isReusingActivityTokenAllowed";
        LOGGER.logp(Level.INFO, CLASSNAME, METHODNAME, " Setting isReusingActivityTokenAllowed to TRUE ");
        return true;
    }
    public boolean shouldInvalidateLogons() {
        final String METHODNAME = "shouldInvalidateLogons";
        LOGGER.logp(Level.INFO, CLASSNAME, METHODNAME, " Setting shouldInvalidateLogons to FALSE ");
        return false;
    }

Step 3: Generate WCToken using code below:
        String userCookieName = "WC_USERACTIVITY_"+userId.toString();
        LOGGER.logp(Level.INFO, CLASSNAME, methodName,"UserId "+userId + " userCookieName "+userCookieName);
        String currentCookieValue = null;
        try    {
            Cookie [] cookieArray = getHttpRequest().getCookies();
            if(null!=cookieArray && cookieArray.length>0){
                for (int i=0;i                    if(cookieArray[i].getName().equalsIgnoreCase(userCookieName)){
                        currentCookieValue = cookieArray[i].getValue();
                        break;
                    }
                }
            }
            ActivityToken activityToken=null;
            String cookieValue=null;
            WCUserSession userSession = new WCCookieUserSession(currentCookieValue, CommerceTokenHelper.getSessionKey());
            activityToken = userSession.getConversationToken();
            activityToken.setTemporary(false);
            ActivityTokenProcessor.refreshSignature(activityToken);
      
            // generate the WCToken
            String merchantKey = CommerceTokenHelper.getSessionKey();
            WCCookieUserSession cookieUserSession = new WCCookieUserSession(null, null, merchantKey, null, null);
            cookieUserSession.setUserId(userId);
            cookieUserSession.setConversationToken(activityToken);            
            cookieValue = cookieUserSession.serialize();
          
            // retrieve the encrypted part
            String encryptedPart = cookieValue.substring(cookieValue.lastIndexOf(SessionConstants.COOKIE_SEPARATOR) + 1);
            StringBuffer cookieValueBuffer = new StringBuffer(userId.toString().length() + 1 + encryptedPart.length());
            // add the user ID part
            cookieValueBuffer.append(userId);
            cookieValueBuffer.append(SessionConstants.COOKIE_SEPARATOR);
            // add the encrypted part
            cookieValueBuffer.append(encryptedPart);
            wcToken = URLUTF8Encoder.encode(cookieValueBuffer.toString());  //This is the wcToken.
            LOGGER.logp(Level.INFO, CLASSNAME, methodName,"wcToken" +wcToken);

        }catch (Exception e) {
            throw new ECApplicationException(XXXXMessage._ERR_TOKENGENERATION_ERR, CLASSNAME, methodName, new Object[]{e});
        }

WebSphere Commerce - Shipping Modes and Calculations

Troubleshooting Shipping Modes and charges:

It happens that sometimes we set up Shipping modes and charges properly for a Store but we are not able see those values on our shipping billing page or where ever we display Shipping mode types or shipping charges does not get reflected whenever you change the shipping modes.

If you are sure that your set up is correct and still you are not able to see charges, please validate your data in tables with below queries:

SELECT * FROM CALCODE WHERE CODE = 'ShippingCODE';

SELECT * FROM CALRULE WHERE CALCODE_ID = (SELECT CALCODE_ID FROM CALCODE WHERE CODE = 'ShippingCODE');

SELECT * FROM CALSCALE WHERE CODE = 'ShippingScale like FedEx Overnight';

SELECT * FROM CALRANGE WHERE CALSCALE_ID = (SELECT CALsCALe_ID FROM CALSCALE WHERE CODE = 'ShippingScale like FedEx Overnight');

SELECT * FROM CALRLOOKUP WHERE CALRANGE_ID in (SELECT CALRANGE_ID FROM CALRANGE WHERE CALSCALE_ID = 
(SELECT CALSCALE_ID FROM CALSCALE WHERE CODE = 'ShippingScale like FedEx Overnight'));
SELECT * FROM CRULESCALE WHERE CALSCALE_ID = (SELECT CALSCALE_ID FROM CALSCALE WHERE CODE = 'ShippingScale like FedEx Overnight');

SELECT * FROM CRULESCALE WHERE CALrule_ID in (SELECT CALRULE_ID FROM CALRULE WHERE CALCODE_ID = 
(SELECT CALCODE_ID FROM CALCODE WHERE CODE = 'ShippingCODE'));
SELECT * FROM CATENCALCD WHERE CALCODE_ID = (SELECT CALCODE_ID FROM CALCODE WHERE CODE = 'ShippingCODE');

SELECT * FROM SHPJCRULE WHERE CALrule_ID in (SELECT CALrule_ID FROM CALRULE WHERE CALCODE_ID = (SELECT CALCODE_ID FROM CALCODE WHERE CODE = 'ShippingCODE'));
SELECT * FROM FFMCENTER f , STOREENT s WHERE s.MEMBER_ID = f.MEMBER_ID AND s.IDENTIFIER ='StoreIdentifier';

Tuesday, February 28, 2017

WCS - Change default port 80

Change Default Port 80 to 81


WCS localhost runs on port 80 and 443. In case these ports are used by other application, WCS will not start and it will give error port 80 already in use. In order to resolve this, we need to end the process which uses port 80.

Sometimes it is really difficult to figure out which application is running on port 80. Below are the steps to determine which application is running on that port

Step 1: Go to command prompt

Step 2: Type in netstat –anb

Step 3: Search for application running on port 80:



Step 4: Kill the process which is running on port 80 OR uninstall the application if not required.
After killing the application running on port 80, your WCS will start properly and you will be able to run application.

If you have trouble in executing steps 1 to 4, try below steps:

Step 1: netstat -n -o -a | findstr 0.0:443

            Get the processId from above result. in my case it is 10136

Step 2: taskkill /F /PID 10136

             Kill the process

If you do not want to kill the process or uninstall the application running on port 80, you need to change the port for WCS so that it listens to any port other than 80. Steps to do this.


Step 1: Start application server

Step 2: Login to admin console:  URL will be like https://localhost:9043/ibm/console

Step 3: Navigate to Server Types à Websphere application servers



Step 4: Select server1 (click on server1)



Step 5: Click on ports (Right side menu item) and look for WC_defaulthost and WC_defaulthost_secure.



Change port 80 to 81 (or any other desired port) and 443 to 444 (or any other desired port).
Step 5: Save changes
Step 6: From left side menu Navigate to Environment à Virtual hosts



Step 7: Click on WC_default_host



Click Host Aliases



Change 80 to 81 (or other desired port number); 443 to 444 (or other desired port number)

Note: Keep changed port number same as in step5.

Step 8: Save changes

Step9: Restart server

Step10: Validate your application if it is running on changed port:

Example: for madisons store:



WCS Toolkit - Fix Out of Memory Issue

We have often encountered Out of memory error during WCS toolkit installation and this error occurs during last step while configuring workspace


Below are the steps mentioned to avoid this error and have successful WCS toolkit installation;

Step 1: Uninstall WCS through IBM installation manager, if it is partially installed (WCS is installed but workspace is not configured )

Step2: Delete WCDE folder and its contents

Step3: Start installation again using IBM installation manager

Step4: During process of WCS installation, some zip folders are extracted. Watch for file generation of file setenv.bat ( in folder WCDE_Install_DIR\bin like C:\IBM\WCDE_ENT70\bin ). As soon as this file gets generated, Please make sure that you make this change
a>    Search for line
set ECLIPSE_ANT=%RAD_HOME%\jdk\bin\java -cp "%ECLIPSE_CP%" org.eclipse.equinox.launcher.Main -application com.ibm.etools.j2ee.ant.RunAnt

b>    Add -Xmx1024m to this line. After change this line should look like
set ECLIPSE_ANT=%RAD_HOME%\jdk\bin\java -Xmx1024m -cp "%ECLIPSE_CP%" org.eclipse.equinox.launcher.Main -application com.ibm.etools.j2ee.ant.RunAnt


Step 5: Save file

Step 4, 5 needs to be performed during installation process.