Monday, July 12, 2010

custom component on server start

wc-server.xml need to be updated with the new component:

<Components>
<component compclassname="com.ext.common.configuration.EXTStoreConfigUtilityEnvironment"
enable="true" name="update each environment specific configuration values."/>
</Components>


This is extensively useful for taxware or environment specific components update on each environment. You can load environment specific information on server start. This is loaded into the memory on server start.

Create a new class implementing the ComponentConfiguration:

package com.ext.common.configuration.EXTStoreConfigUtilityEnvironment
public class EXTStoreConfigUtilityEnvironment
implements ComponentConfiguration {

public void destroy() {
//Do Nothing
}

public void enable(boolean enable) throws Exception {
//Do nothing
}
* Main method to perform the action of running all the queries
*/
public void init(Element arg0) throws Exception {

}
}

Saturday, July 10, 2010

Jsession CloneID for debugging

WebSphere Commerce Dyna-caching mechanism only supports cookie-based sessions, and not URL rewriting.
CloneID (also known as server ID) is appended to the session ID

Once a browser establishes session affinity with an application server, a JsessionId is created. When a HTTP session is created, the session id is passed back to the browser as part of a cookie or URL encoding

e.g.

JSESSIONID 00004QkpGtFgJZ01zkgdi7qMJvg:14aelsphk

The value after : is the cloneID of the server and is used to identify the server. It is usually appended to the JSESSION ID.

This is very useful in a clustered environment for debugging and looking into logs.

This CloneID is only visible from /config/plugin-cfg.xml.

e.g. location :
/opt/IBM/WebSphere/AppServer/profiles//config/cells/plugin-cfg.xml

search for CloneID

Wednesday, July 7, 2010

Implementing Stackable product promotions site wide

Out of the box, product promotions can not be stacked, which means only 1 product promotion per item.
Production promotions can be stacked with the following configuration and updates in database. I would strongly recommend testing all different kind of custom and out of box promotions.

Step1 disable the policy 'Product: Any order item can only participate in one promotion' from px_policy

Disabling the policy lets multiple product promotions be evaluated, otherwise just the one with the highest priority goes in (or in the case of equal priorities, whichever happened to be evaluated first.)

update px_policy set status=1 where px_policy_id in (select px_policy_id from px_policy where name like 'Product: Any order item can only participate in one promotion')

update px_policy set xmlparam=replace(xmlparam,'Active','Inactive') where px_policy_id in (select px_policy_id from px_policy wherename like 'Product: Any order item can only participate in one promotion')

Step2: Modify WCSPromotionEnginConfig.xml

Modifying the XML lets promotions stack, instead of just evaluating all of them, and picking the best one.

In the WCSPromotionEngineConfig.xml, you have to disable the behavior true to false This change will allow all the price adjustment based on discounted price (or contract price displayed in the shopcart).

Step3: Update all promtions from accelerator. If you want this to affect your exisiting promotions.

you have to update all the promotions ( don't need to change anything, but need to resave the promotion in order to get promotion XML updated). After that, all the promotions for the same product can be combined.

Saturday, July 3, 2010

Business Auditing feature in WCS

IBM websphere commerce uses : WebSphere Commerce uses the industry standard Triple DES (data encryption standard)

This ensures that a third party using network-sniffing programs cannot snoop on the network when a user submits a password.
Passwords are never decrypted during the authentication process, as is the common security practice.
All user passwords are one-way hashed using the SHA-1 hashing scheme and encrypted using a 128-bit key based on the merchant key.


Business Auditing:

Business auditing is the capturing of the business logic and objects during a WebSphere Commerce operation.A report on business auditing is available in the Administration Console.

WebSphere Commerce business auditing records the information about the execution of business logic, such as the command, request, response, command context, and other information. For example, if a Customer Service Representative overrides a price for a particular ordered item within an order, this needs to be captured, and is useful to resolve any discrepancies between the price quoted to the customer and the customer's bill.

If an error occurs while executing any business logic, WebSphere Commerce attempts to execute the business logic, and this attempt is recorded to indicate that the request failed.

To use the business auditing feature, you must first enable it using Configuration Manager. By default, when you install WebSphere Commerce, the business auditing feature is already enabled. The WebSphere Commerce system captures the execution of specific business logic based on some default configuration. You can further customize which commands you want captured during a business audit (that is, enable existing or add new commands) by configuring the BusinessAuditDataCapture.xml file. The data captured by WebSphere Commerce system is stored in the BUSAUDIT table.


customization: BusinessAuditDataCapture.xml
enabling: For servers it is enabled using the configuration manager

Adding custom commands:
<AuditCommand eventType="MBR" command="com.custom.commands.CustomActivityControllerCmd" audit="true"/>
<AuditCommand eventType="MBR" command="com.custom.commands.CustomOrderSearchControllerCmd" audit="true"/>

Commerce where can I find?

This information below is for WCS 6.0

Accelerator:
https://localhost:8000/webapp/wcs/tools/servlet/ToolsLogon?XMLFile=common.mcLogon&storeId=0

Admin Console:
https://localhost:8002/webapp/wcs/admin/servlet/ToolsLogon?XMLFile=adminconsole.AdminConsoleLogon&storeId=0

Org Admin Console:
https://localhost:8004/webapp/wcs/orgadmin/servlet/ToolsLogon?XMLFile=buyerconsole.BuyAdminConsoleLogon&storeId=0

Dynacache:
https://localhost:8002/cachemonitor/

Nifstack.xml:
\properties\version\update\backup
/opt/IBM/WebSphere/CommerceServer60/properties/version/update/backup/NIFStack.xml

wc-server.xml:

\xml\config\wc-server.xml
WC_LIVE_CELL and WC_LIVE would need to be replaced with the node name.
/opt/IBM/WebSphere/AppServer/profiles/LIVE/installedApps/WC_LIVE_cell/WC_LIVE.ear/xml/config



Temp folder:
\wasprofile\temp
/opt/IBM/WebSphere/AppServer/profiles/LIVE

Logs:
\wasprofile\logs
LIVE and WC_SS_LIVE_1 need to be replaced with appropriate instance names.
/opt/IBM/WebSphere/AppServer/profiles/LIVE/logs/WC_SS_LIVE_1


Tracing:
log into wasconsole
https://hostname:9043/ibm/console
or
Toolkit, right click on the server->goto admin console.

Application servers > Change Log Detail Levels
e.g. after changes done to enable WC_SERVER
*=info:enable.trace.log.*=all:com.ibm.websphere.commerce.WC_USER=all:
com.ibm.websphere.commerce.WC_SERVER=all:
com.ibm.websphere.commerce.WC_ACCESSCONTROL=all

Regular Expressions in Java\WCS Examples

REGEX 101:
Regular expressions are a powerful (and fairly standardized) way of searching, replacing, and parsing text with complex patterns of characters.

. is a wild character
e.g b.t in text could search bat bit bet bot b*t b t

[] search to Limit to a range of characters.

e.g. b[aeio]t : bat bet bit bot

() search more than 1 characters. (can not use [] to search more than 1 character)
e.g. b(a|e|i|o|oo)t : bat bet bit bot boot

* 0 or more times
+ 1 or more times
? 0 or 1 time
{n} Exactly n number of times
{n,m} n to m number of times
- Indicates a range that would match any number\character.
\ used for escaping regexp special characters.
"^" notation is also called the NOT notation. If used in brackets, "^" indicates the character you don't want to match.
\s Search spaces and tabs.
Simpler short cuts:
\d [0-9]
\D [^0-9]
\w [A-Z0-9]
\W [^A-Z0-9]
\s [ \t\n\r\f]
\S [^ \t\n\r\f]

e.g. US telephone number 858-343-1111
Regexp expression to be used: [0-9]{3}\-[0-9]{3}\-[0-9]{4}

If - is optional: 8583431111
Regexp expression to be used: [0-9]{3}\-?[0-9]{3}\-?[0-9]{4}

e.g. 8836KV [0-9]{4} [A-Z]{2}
(first 4 numbers)(last 2 characters.)

e.g. May 11, 2010 : [A-Z]\s+[0-90{1,2},\s*[0-9]{4}
[A-Z]+(first 3 characters)\s+(mandatory space),\s* (0 or more spaces)[0-9]{4}

E.g. These examples are with JDK 1.4.2 API.

import java.util.regex.Matcher;
import java.util.regex.Pattern;

Pattern class:

An instance of the Pattern class represents a regular expression that is specified in string form in a syntax similar to that used by Perl.

A regular expression, specified as a string, must first be compiled into an instance of the Pattern class. The resulting pattern is used to create a Matcher object that matches arbitrary character sequences against the regular expression. Many matchers can share the same pattern because it is stateless.

The compile method compiles the given regular expression into a pattern, then the matcher method creates a matcher that will match the given input against this pattern. The pattern method returns the regular expression from which this pattern was compiled

Matcher Class

Instances of the Matcher class are used to match character sequences against a given string sequence pattern. Input is provided to matchers using the CharSequence interface to support matching against characters from a wide variety of input sources.

A matcher is created from a pattern by invoking the pattern's matcher method. Once created, a matcher can be used to perform three different kinds of match operations:

  • The matches method attempts to match the entire input sequence against the pattern.
  • The lookingAt method attempts to match the input sequence, starting at the beginning, against the pattern.
  • The find method scans the input sequence looking for the next sequence that matches the pattern.

Each of these methods returns a boolean indicating success or failure. More information about a successful match can be obtained by querying the state of the matcher.

This class also defines methods for replacing matched sequences by new strings whose contents can, if desired, be computed from the match result.

The appendReplacement method appends everything up to the next match and the replacement for that match. The appendTail appends the strings at the end, after the last match.


Sample methods :



public static String removeDuplicateWhitespace(String inputStr) {
String patternStr = "\\s+";
String replaceStr = " ";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(inputStr);
return matcher.replaceAll(replaceStr);
}


public static String replaceSpecialCharsWithHTMLTags(Map splCharsMap, String patternStr, String input)
{
final String METHODNAME ="replaceSpecialCharsWithHTMLTags";

Pattern r = Pattern.compile(patternStr, Pattern.CASE_INSENSITIVE);
Matcher m = r.matcher(input);

m.reset();
StringBuffer sb = new StringBuffer();
String replaceStr = null;
String supTagElement = null;

while (m.find())
{
supTagElement = input.substring(m.start(), m.end());

if (splCharsMap.containsKey(supTagElement))
{
replaceStr = (String) splCharsMap.get(supTagElement);
}

if ( replaceStr!=null && replaceStr.length > 0 )
m.appendReplacement(sb, replaceStr);
else
m.appendReplacement(sb, supTagElement);
}

m.appendTail(sb);
return sb.toString();
}

WCS:

There is application for regular expression in both for front validation JSP validation for feeds and also during string search\replace in the back end.



Ref:
http://java.sun.com/developer/technicalArticles/releases/1.4regex/