Thursday, November 13, 2014

Commnly used methods in IBM WCS


commitCopyHelper() and refreshCopyHelper()
  refreshCopyHelper()  is to retrieve the fields using primary key.refresh copy helper is treated as "find for update” and it locks that particular row unless or until you are done with entire transaction. So you read something with refreshcopyHelper and you keep doing  no of things and when you are finally done then only these locks are released.RefreshCopyHelper reads the database to update the access bean.
 
 
commitCopyHelper() is to insert or update fields :

Tuesday, November 11, 2014

Websphere commerce Command error handling

Here we are going to discuss types of exceptions that a command can throw, how the exceptions are handled, how message text is stored and used, how the exceptions are logged, and how to use the provided framework in your own commands.

Types of exceptions

A command can throw one of the following exceptions:

ECApplicationException
This exception is thrown if the error is related to user input and will always fail. For example, when a user enters an invalid parameter, an ECApplicationException is thrown. When this exception is thrown, the solution controller does not retry the command, even if it is specified as a retriable command.
ECSystemException
This exception is thrown if a runtime exception or a WebSphere Commerce configuration error is detected. Examples of this type of exception include create exceptions, remote exceptions, and other EJB exceptions. When this type of exception is thrown, the solution controller retries the command if the command is retriable.
In order to throw one of these exceptions, the following information must be specified:
Error view name
The view that will be used to display the error. For Web requests, the Web controller looks up this name in the Struts configuration files.
ECMessage object
ECMessage defines the static information related to the reason for the exception. This value corresponds to the message text contained within a properties file.
ECParameter
ECParameter returns the errors associated with the application. The exception can indicate multiple errors since each part of an application exception represent an error.
Error parameters
These name-value pairs are used to substitute information into the error message. For example, a message may contain a parameter to hold the name of the method which threw the exception. This parameter is set when the exception is thrown, then when the error message is logged, the log file contains the actual method name.
Error data
These are optional attributes that can be made available to the JSP page through the error data bean.

Exception handling in customized code

When creating new commands, it is important to include appropriate exception handling. 

Writing your own exception handling logic, involves the following steps:
  1. Catching the exceptions in your command that require special processing.
  2. Constructing either an ECApplicationException or ECSystemException, based upon the type of exception caught.
  3. If the ECApplicationException uses a new message, defining the message in a new properties file.

Catching and constructing exceptions

To illustrate the first two steps, the following code snippet shows an example of catching a system exception within a command:
try {
// your business logic
}
catch(FinderException e) {
     throw new ECSystemException (ECMessage._ERR_FINDER_EXCEPTION, 
          className, methodName, new Object [] {e.toString()}, e); 
}
The preceding _ERR_FINDER_EXCEPTION ECMessage object is defined as follows:
public static final ECMessage _ERR_FINDER_EXCEPTION = 
new ECMessage (ECMessageSeverity.ERROR, ECMessageType.SYSTEM, 
     ECMessageKey._ERR_FINDER_EXCEPTION);
The _ERR_FINDER_EXCEPTION message text is defined within the ecServerMessages_xx_XX.properties file (where _xx_XX is a locale indicator such as _en_US), as follows:
_ERR_FINDER_EXCEPTION  = 
     The following Finder Exception occurred during processing: "{0}".
When catching a system exception, there is a predefined set of messages that can be used. These are described in the following table:
Message Object Description
_ERR_FINDER_EXCEPTION Thrown when an error is returned from an EJB finder method call.
_ERR_REMOTE_EXCEPTION Thrown when an error is returned from an EJB remote method call.
_ERR_CREATE_EXCEPTION Thrown when an error occurs creating an EJB instance.
_ERR_NAMING_EXCEPTION Thrown when an error is returned from the name server.
_ERR_GENERIC Thrown when an unexpected system error occurs. For example, a null pointer exception.


When catching an application exception, you can either use an existing message that is specified in the appropriate error message properties file, or create a new message that is stored in a new properties file. As specified previously, you must not modify any of the predefined error message properties files.
The following code snippet shows an example of catching an application exception within a command:
try {
// your business logic

}
// catch some new type of application exception
catch(//your new exception)
 {
     throw new ECApplicationException (MyMessages._ERR_CUSTOMER_INVALID, 
          className, methodName, errorTaskName, someNVPs); 
}
The preceding _ERR_CUSTOMER_INVALID ECMessage object is defined as follows:
public static final ECMessage _ERR_CUSTOMER_INVALID = 
     new ECMessage (ECMessageSeverity.ERROR, ECMessageType.USER, 
     MyMessagesKey._ERR_CUSTOMER_INVALID, "ecCustomerMessages");
When constructing new user messages, you should assign them with a type of USER, as follows:
ECMessageType.USER
The text for the _ERR_CUSTOMER_INVALID message is contained in the ecCustomerMessages.properties file. This file must reside in a directory that is in the class path. The text is defined as follows:
_ERR_CUSTOMER_INVALID = Invalid ID "{0}"
 Refrence : Command error handling

Understanding controller command in IBM websphere commerce

Before writing controller command we need to understand what all OOTB method need to implement.

Below six OOTB method available in Controller command :

isGeneric()

In the standard WebSphere Commerce implementation there are multiple types of users. These include generic, guest, and registered users. Within the grouping of registered users there are customers and administrators. The isGeneric method returns a Boolean value which specifies whether the command can be invoked by the generic user. The isGeneric method of a controller command's superclass sets the value to false (meaning that the invoker must be either a registered customer or a guest customer). If your new controller command can be invoked by generic users, override this method to return true.
 

isRetriable()

 
The isRetriable method returns a Boolean value which specifies whether the command can be retried on a transaction rollback exception. The isRetriable method of the new controller command's superclass returns a value of false. You should override this method and return a value of true, if your command can be retried on a transaction rollback exception. 
 

setRequestProperties(com.ibm.commerce.datatype.TypedProperty reqParms)

The setRequestProperties method is invoked by the Web controller to pass all input properties to the controller command. The controller command must parse the input properties and set each individual property explicitly within this method.
 
 

validateParameters()

The validateParameters method is used to do initial parameter checking and any necessary resolution of parameters. For example, it could be used to resolve orderId=*. This method is called before both the getResources and performExecute methods.
 

performExecute()

The performExecute method contains the business logic for your command. It should invoke the performExecute method of the command's superclass before any new business logic is executed. At the end, it must return a view name.
 
 
Under performExecute following
 

    /// Create a new TypedProperties for output purposes.
  TypedProperty rspProp = new TypedProperty();
 
 
  /// The controller command passes variables to the JSP page
 /// add additional parameters in controller command to rspProp for response
    String message1 = "Hello from IBM!";
    rspProp.put("controllerParm1", message1);
    rspProp.put("controllerParm2", "Have a nice day!");
 
 
 /// instantiate the MyNewDataBean databean and set the properties, then add the instance to resProp for response
 MyNewDataBean mndb = new MyNewDataBean();
 mndb.setCallingCommandName(this.getClass().getName());
 mndb.setCalledByControllerCmd(true);
 
 // pass the input information to the databean
 mndb.setUserName(this.getUserName());
 mndb.setPoints(this.getPoints());

 rspProp.put("mndbInstance", mndb);
 

    /// The controller command calls a task command
 MyNewTaskCmd cmd = null;
 try {
  cmd = (MyNewTaskCmd) CommandFactory.createCommand("com.ibm.commerce.sample.commands.MyNewTaskCmd", getStoreId());
        // this is required for all commands
        cmd.setCommandContext(getCommandContext());
  /// set input parameters to task command
  cmd.setInputUserName(getUserName());
  cmd.setInputPoints(getPoints()); // change to Integer

  /// pass rrb instance variable to the task command
  cmd.setUserRegistryAccessBean(rrb);

  /// pass bb instance variable to the task command
  cmd.setBonusAccessBean(bb);
  /// invoke the command's performExecute method
  cmd.execute();
  /// retrieve output parameter from task command, then put it to response properties
  rspProp.put("taskOutputGreetings", cmd.getGreetings());

  ///using access bean to get information from databse
  if (cmd.getFoundUserId() != null) {
   rspProp.put("taskOutputUserId", cmd.getFoundUserId());
  }

  if (cmd.getOldBonusPoints() != null) {
   rspProp.put("oldBonusPoints", cmd.getOldBonusPoints());
  }

     ///Instantiate the bonus databean , then put it into response properties
        BonusDataBean bdb  = new com.ibm.commerce.sample.databeans.BonusDataBean(cmd.getBonusAccessBean());
     rspProp.put("bdbInstance", bdb );

 } catch (ECException ex) {
  /// throw the exception as is
  throw (ECException) ex;
 }
 
    /// see how the controller command calls the JSP
 rspProp.put(ECConstants.EC_VIEWTASKNAME, "MyNewView");
 setResponseProperties(rspProp);

}
 
 

Monday, November 10, 2014

javax.servlet.ServletException: Filter [LikeMindsFilter]: could not be loaded

In server startup I am getting following log :

AbstractEJBRu E   WSVR0068E:
Attempt to start EnterpriseBean
<bean name> failed with exception:
org.eclipse.jst.j2ee.commonarchivecore.internal.exception.Deploy
mentDescriptorLoadException: META-INF/ejb-jar.xml
Stack Trace:
com.ibm.ws.webcontainer.webapp.WebAppErrorReport: javax.servlet.ServletException: Filter LikeMindsFilter: could not be loaded at com.ibm.ws.webcontainer.servlet.ServletWrapper.constructErrorReport(ServletWrapper.java:1101) at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:940) at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:444) at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:175) at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3622) at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:276) at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:927) at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1566) at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:175) at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:455) at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:384) at



Resolution :

Add/Remove WC from server and publish  : Mostly it resolve the issue.
This issue comes due to db2 datasource is not configured properly. mainly the DB2 JAR file is not registered.

Make sure below files pointing to correct DB :


WC/META-INF/<some more folders>/security.xml
variables.xml
deployment.xml

wc-server.xml

Friday, November 7, 2014

Integrating facebook with ibm websphere commerce

To display Facebook connectivity including the "Like" button in the starter store, We must enable an option in the Store Management tool in Management Center.

Procedure
1.Open the Store Management tool.
2.In the explorer view, click Stores.
3.Right-click the store to which we want to add Facebook integration; then click Open. The available store functions for the store are displayed within separate tabs beside the Store Properties tab.
4.Click the Customer Interactions tab.
5.Select the Facebook integration check box, if it is not already selected.
6.Click Save to save your changes and then click Close.
7.Close Management Center.






Creating a Facebook application for your store for Facebook integration


For your store to communicate with Facebook, it is necessary to create a Facebook application. The Connect to Facebook, and Activity Feed plugins rely on the Facebook application and the communication it allows.

Procedure
1.Register the store application with Facebook at http://developers.facebook.com/setup/.

a.In the Site name field, specify the name of your application, for example, CheapProducts.com.
b.In the Site URL field, specify the fully qualified hostname of the Websphere Commerce Server where the application will redirect traffic to.

2.Specify the subdomain in the Site Domain field. Facebook enables server authentication at a subdomain level when the application is installed on multiple machines. For example, example.com enables all *.example.com servers to make use of this registered application.

Once the application is registered, Facebook provides an Application ID and a Secret ID for use with this application.










Inserting a Facebook Application ID into store


When you configure a store to use Facebook integration, a Facebook Application ID must be inserted into the STORECONF table for both the preview and runtime environments.

Procedure
1.Insert the Facebook Application ID you obtained upon creating a Facebook application for the runtime environment: insert into storeconf values (store_id,'wc.facebook.application_id', 'fb_app_id_rt', 0);
Where:◦store_id is the ID of the store the Application ID will be associated with.
◦fb_app_id_rt is your Facebook Application ID for the runtime environment.

Note: If using Social Bridging make sure the Social Bridging applicationID in the adapter.config file is using the same Facebook Application ID.

2.If you have created a second Facebook Application ID for your store's preview environment, insert it as well: insert into storeconf values (store_id,'wc.facebook.preview_application_id', 'fb_app_id_preview', 0);
Where:◦store_id is the ID of the store the Application ID will be associated with.
◦fb_app_id_preview is your Facebook Application ID for the preview mode environment.

Note: Both entries should be inserted, even if they use the same value for the Application ID.

3.Repeat for all stores, including extended sites.





Testing Facebook integration in the storefront


In this lesson, you test Facebook integration as a shopper in the Madisons store by 'liking' the home page.

To ensure that Facebook integration has been implemented correctly, complete the following steps to 'like' the store's home page.

Procedure
1.To view the Madisons store, in a new web browser type http://host_name/webapp/wcs/stores/servlet/StoreView?storeId=storeId. 
Where:storeIdis the store entity ID as defined in the STORE_ID column of the STORE table.host_nameis the fully qualified host name of your WebSphere Commerce Server (for example, wcserver.mydomain.ibm.com is fully qualified).
2.Navigate to the store home page.
3.Click Connect to Facebook. a.Log in to Facebook.
b.Authorize the Facebook application. The Connect to Facebook button should be replaced with your name and Facebook profile picture.

4.Click Like. a.If desired, enter a comment about the store home page.
b.Click Post to Facebook.

5.Check on Facebook to see if the post has been published to your timeline.

You have now successfully connected the store to your Facebook account and 'liked' the store home page on Facebook.

After you publish the MadisonsEnhancements.sar store archive and enable the Facebook Integration feature, the home page will include Facebook social plugins to display the Like button and Activity feed plugin. The Like button is an easy way for Facebook users to share things they like on the web with their Facebook friends and the activity feed plugin shows users what their friends have liked and shared from your site. Facebook users can log in to their account like the home page and/or view their friends' comments.



We need to include following jsp files to see the change :


JSP files
Madisons\ShoppingArea\CatalogSection\CatalogSubsection\TopCategoriesDisplay.jsp, represents the entire page and includes Facebook Open Graph tags for formatting purposes.
Includes:
•Madisons\include\styles\style1\CachedHeaderDisplay.jsp, displays the store's header.
Includes:
◦ 1  Madisons\include\styles\style1\CachedHeaderDisplayFacebook.jspf, allows a Facebook user to login, authorize the application and connect to Facebook. Once connected, the user can also disconnect the store from facebook.


Includes:
•Madisons\include\styles\style1\CachedRightSidebarDisplay.jsp, represents the right sidebar advertising space, one or more e-Marketing Spots and displays the Facebook Social plugins.
Includes:
◦ 2  Madisons\include\styles\style1\CachedRightSidebarFacebook.jspf, pulls in the Facebook plugins: Like and Activity Feed as shown in the screen capture.



Links and buttons
• 2 a. . When a shopper clicks Connect to Facebook, it allows the user to log in to their account, prompts the user for application authorization if the user is not already authorized, and finally connects the user to Facebook.
• 2 b.  When a shopper clicks Disconnect from Facebook, their Facebook account is disconnected from the store and is no longer connected to the application. Disconnecting does not de-authorize the application. To de-authorize the application, it must be removed in Facebook.

Facebook integration introduces the following Facebook functionality to the Madisons store:
Like button Social Plugin on the home and product pages
Send button Social Plugin on product pages
Facebook Activity Feed on the home page
Connect to Facebook
The Customer participates in Social Commerce trigger and target have been updated to capture 'Liking' on Product or Home pages via the marketing and promotions activities


Refrence :
Facebook Integration

Thursday, November 6, 2014

Database Cleanup utility

The Database Cleanup utility refers to the CLEANCONF table to determine which tables and which rows to delete when a particular object and object type are specified.
 To get an accurate listing of all statements, see the cleanconf rows in the wcs.staging.xml file:
  • WC_installdir/schema/database_type/wcs.staging.xml (In server environment)
  •  WCDE_installdir/schema/database_type/wcs.staging.xml (In toolkit)
Out of the box, commerce provides a table for adding these queries CLEANCONF table, which is good enough for most basic queries for complex cleanup operations, it is very important to use store procedures.

Cleaning up unnecessary data in a WebSphere Commerce site can improve performance, decrease the amount of storage needed to host the WebSphere Commerce site, and decrease the amount of time required to do future upgrades and migrations. A number of different tables can be cleaned up, and this cleanup can be done on an individual basis, depending on the needs of the site. If rows need to be deleted from a WebSphere Commerce database.

WCS have OOTB utility to clean data called dbclean utility script. To use this:

Run the utility as follows: WC_installdir/bin/dbclean.sh <parameters>

Parameter values
object : The name of the object to be deleted. For more information about the object names, see Database Cleanup utility objects.

type : The type of object you want to delete. For more information about the type to specify with an object, see Database Cleanup utility objects.

instancexml :The absolute path to the WebSphere Commerce configuration file.

 e.g : To clean user object :

dbclean -object user -type registered -instancexml C:\WebSphere\WebSphereCommerce\instances\demo\xml\demo.xml -db CD040302 -check_object_only yes


CD040302 - DB Name

Adding a configuration to the Database Cleanup utility

We can add new objects to the database table to define which tables and rows to clean, by updating the Database Cleanup utility configuration data in the CLEANCONF table. To extend the Database Cleanup utility, specify values for the jdbcDriver and jdbcUrlPrefix parameters when running the utility.




Tuesday, November 4, 2014

Making page as non-secure page in IBM websphere commerce


Open : struts-config-ext and search for command which we need to make nonsecure/secure :
Then in set-property tag set https value = "<store_id : 0/1>
0 - Disable
1- Enable
e.g :

<action path="/LoyaltyAPI" type="com.ibm.commerce.struts.BaseAction">
            <set-property property="https" value="10151:1"/>
        </action>


To make it enable : <set-property property="https" value="10151:1"/>
 Not a https page : <set-property property="https" value="10151:0"/>