Friday, 31 July 2015

JSTL Tag libraries

JSTL tag library is a component technology for J2EE applications handled by Sun microsystems. They are a package of simple tag libraries useful for buiding dynamic jsps. They are easily understandabe and useful for non programmers which can be used as alternative for the scriptlets:

Types of JSTL tags:
c - core
fmt - formatting
x - XML processing
sql - db access
fn - functions

Types of C tags:
1. <c:set var="name" value="sam" />
2. <c:out value="${name}" />
3. <c:choose>
      <c:when test="${}">
           ....
      </c:when>
      <c:otherwise>
          ....
      </c:otherwise>
    </c:choose>
4. <c:if test="${name eq 'same'}" ></c:if>
5. <c:import url="src/main.jsp" />
6. <c:import url="src/main.jsp" >
         <c:param var="id" value="1001" />
    </c:import>
7. <c:url var="main" url="src/main.jsp"/>
8. <c:redirect url="${src/redirect.jsp}" />
etc..

fmt tags:
1. <fmt:setBundle var="storeText" basename="${jspStoreDir}StoreText" /> - set it in a scoped variable
2. <fmt:message bundle="${storeText}" key="errMsg" var="errMsg" />
3. <fmt:setLocale value="${CommandContext.locale}" /> - set defualt locale value for the scope
4. <fmt:bundle basaename="${jspStoreDir}StoreText" prefix="label" /> - sets localization context
5. <fmt:param > EX:
    <fmt:message key="errMsg">
       <fmt:param userId="${userId}" />
    </fmt:message>
6.<fmt:formatNumber  type="currency" value="2.5" />
7. <fmt:formatDate var="bday" value="05/01/99" pattern="MM/DD/YY" />
8. <fmt:formatNumber var="rate" value="400" pattern="###.##" type="number" />
etc..

SQL tags:
For executing SQl queries
1. <sql:query var="users">
     SELECT * FROM USERS WHERE NAME="sam"
    </sql:query>
2. <sql:update var=count>
      UPDATE USERS SET LASTNAME="SSS" WHERE users_id=1001
  </sql:update>
3. sql:param EX:
   <sql:update var=count>
      UPDATE USERS SET LASTNAME="SSS" WHERE users_id=?
     <sql:param value="1001" />
     </sql:update>
4. <sql:transaction>
       <sql:update sql="INSERT INTO USERS VALUES(1002, 'XXX', 'YYY')" />
    </sql:transaction>
etc..

xml tags:
1. <x:parse> - Fo parsing XML content
2. <x:out> printing xpath expression
3. <x:set> -
4. <x:if>
5. <x:choose>
etc..

fn tags
1. fn:replace (string, beforeStr, afterStr)
2. fn:subString (string, beginindex, endIndex)
3. fn:length(string)
4.  fn:escapeXml(string)
5.fn:containsIgnoreCase(string, subString)

etc..

wcbase:useBean tag
<wcbase:useBean id=usersDataBean className=com.ibm.commerce.myBeans.MyDataBean  scope="page">
 <c:set property="my_id" value="1001" target="${usersDataBean}" />
</wcbase:useBean>

Other way of inoking databean from jsp is using jsp:useBean tag
<jsp:useBean id="mydataBean" className="com.ibm.myBeans.MyDataBean" scope="page">
<% com.ibm.commerce.beans.DataBeanManager.actiate(mydataBean,request,response);%>
<jsp:useBean>

Wednesday, 29 July 2015

Command registry framework in websphere commerce

Websphere commerce controller command and task commands are registered in command registry framework.

Interfacename
MyControllerCmd --> extends --> com.ibm.commerce.commands.ControllerCommand

Implementation class:
MyControllerCmdImpl --> extends --> com.ibm.commerce.commands.ControllerCommandImpl
and 
MyControllerCmdImpl implements MyControllerCmd
            
CommandFactory is a bean used for instantiating commands in websphere commerce.
Ex:
MyControllerCmd myCmd   = null;
myCmd  = (MyControllerCmd) CommandFactory.CreateCommand(com.ibm.commerce.myCommands.MyControllerCmd, getStoreId());
myCmd.setComandContext(getCommandContext());
myCmd.setRequestProperties(this.requestProperties);
myCmd.execute();
Where this.requestProperties is a TypedProperty object has all the request properties set.

There are 2 ways of defining implementation class for the inteface in websphere commerce:

1) defaultCommandClassName -The implementation class for the interface is defined in the interface by defaultCommandClassname
Ex:
public interface MyControllerCmd  extends ControllerCommand {
public Static final String defaultCommandClassName = com.ibm.commerce.myCommands.MyControllerCmdImpl;
}
      
2) CMDREG entry- Command Registry
 This table has following columns:
STORE_ID- 0 if the same implementation command  is used for all the stores.                    
INTERFACENAME- Name of the interface
CLASSNAME - implementation class name
DESCRIPTION - short description about the command
PROPERTIES - properties that are to be passed to command

CMDREG is preferred when different implementation classes are used for different stores. i.e the logic implementation changes based on the storeID

If suppose there is different entry in defaultCommandClassName and CMDREG table for the implementation class then Command Registry takes the precedence.

Simillarly for the taskcommands
Interfacename
myTaskCommand extends  --> com.ibm.commerce.commands.TaskCommand

Implementation class:
myTaskCommandImpl extends --> com.ibm.commerce.commands.TaskCommandImpl
and 
myTaskCommandImpl implements myTaskCommand

Imp Points:
  • A controller command and task command both can be called from a controller command.
  • A task command can call a taskcommand and even controller command.
  • Both task command and controller command can have entry in CMDREG table.

Differences between controller command and task command:


Controller Command
Task Command
This is the entry point for fulfilling any request
This contains a part f business logic to be executed
This has struts entry
This cannot have an entry in struts file
Access Control policy (ACP) is enabled by default
ACP is not enabled
It has a viewname entry for redirecting the flow to the viewname after successful execution
It does not have viewname, the control is returned back to the called command.
Can be called from JSP
Cannot be called from JSP

Tuesday, 28 July 2015

View the detalis of SSL certificate

If we have a SSL certificate with .pfx extension and want to view the details of it, we can view them using Keymanager tool. The .bat file related to this will be present n appserver / bin folder

F:\IBM\WebSphere\AppServer\bin\ikeyman.bat

Click on the bat file it opens the UI screen as below:


Click on
Open --> choose PKCS12 for .pfx file --> Give the path --> Open
You are prompted to give a .pfx file password. The default key.p12 password in the config file is webAS.

You can view here the certificate details, start date , end date etc..


Monday, 13 July 2015

Data Load Utility

DataLoad utility is the new enhanced business object based utility available in websphere commerce where input data is converted to business objects and then business objects to physical data.

Following user Roles generally interact with dataload utility in Websphere Commerce:

1. Business user- Responsible for preparing business data / input data.
2. Developer - Responsible for creating data source templates (EX: CSV files.. From FEP6 onwards XML input files are also accepted) business object mappings in business object configuration files (Ex: XML files) and customizing the data load utility.
3. Site Administrator - Responsible for day- to - day dataload utility. - Like creating environment based files, Run the coniguration files to load the data into websphere commerce database.

There are 3 configuration files involved in dataload utility
1. Environment configuration file. - prepared by Site administrator
    <_config:DataLoadEnvConfiguration >
                 ........
    </_config:DataLoadEnvConfiguration>
This configuration file has -  dbname, dbusername, password, server, port number, schema information.
Ex;
<_config:Database type="db2" name="XXX" user="db2admin" password="Szv3RSJ0AYLgRmGpKekdvw==" server="localhost" port="50000" schema="db2admin" /> Also has information about storeIdentifier like
<_config:BusinessContext storeIdentifier="Extended sites catalog asset store" catalogIdentifier="Extended sites catalog asset store" languageId="-1" currency="USD"/>

2. DataLoad configuration file. - prepared by Site administrator
   <_config:DataLoadConfiguration >
              .....
   </_config:DataLoadConfiguration>
 This file has the entry for the data input file, business object configuration file, environment configuration file.
EX:
<_config:DataLoadEnvironment configFile="wc-dataload-env.xml" />
<_config:LoadOrder commitCount="1000"  maxError="10" batchSize="500" dataLoadMode="Insert"><_config:property name="firstLineIsHeader" value="true" />
 <!-- Store Locator -->       
 <_config:LoadItem name="StoreLocation" businessObjectConfigFile="wc-loader-store-location.xml" >
              <_config:DataSourceLocation location="myData.csv" />
 </_config:LoadItem>

3. Business object configuration file. - prepared by Developer
   <_config:DataloadBusinessObjectConfiguration
            ...........
   </_config:DataloadBusinessObjectConfiguration>
This files contains entry for :
OOB CSV Reader
<_config:DataReader className="com.ibm.commerce.foundation.dataload.datareader.CSVReader" firstLineIsHeader="true" >
 <_config:BusinessObjectBuilder className="com.ibm.commerce.foundation.dataload.businessobjectbuilder.TableObjectBuilder" >

Data Load utility - user interaction diagram 

Source - Infocenter

  1. The business user provides the developer with the business data.
  2. The developer creates a data source template, which defines how source data must be formatted before the data is loaded.
  3. The developer also creates the business object configuration file, which defines how the Data Load utility maps the input data to the business object and how to transform the business object to physical data.
  4. The site administrator uses the business object configuration file to define and create the load order configuration file.
  5. The site administrator sets the store and database settings in the environment configuration file.
  6. The business data is formatted according to the rules of the data source template before the data is loaded to the database.
  7. The formatted source data is provided to the site administrator.
  8. The site administrator runs the Data Load utility along with the three configuration files (environment, load order, and business object configuration files) to load the formatted source data into the WebSphere Commerce database. After the utility runs, the site administrator also verifies the results of the load.
  9. The business data is available in WebSphere Commerce to be managed by the business user.
How to Run dataload utility for custom tables:
1. Take back up of tables that are going to be modified / take DB backup.
2. Note the count of rows for the tables that are going to be modified.
3. Generate a CSV file for the input data - verify the CSV file using CSV reader just to make sure that the CSV file is error free.
4. Create a new folder with the name of unit for which you want to load data.
 For ex: F:\IBM\WebSphere\CommerceServer70\samples\DataLoad\StoreLocactor
5. Copy the wc-dataload-env.xml, wc-dataload.xml and wc-loader.xml files from different folders that you already have into F:\IBM\WebSphere\CommerceServer70\samples\DataLoad\StoreLocactor and modify the required fields in these xml files.
6. Name the xml files to avoid confusion like Ex:
  env file as - wc-dataload-env.xml
  loader file - wc-dataload-stloc.xml (This is the entry point for execution)
 Business Object Configuration file - wc-loader-store-location.xml
6. Check the wc-dataload-env.xml file for DB configurations.
7. Update the proper Input CSV file path, business object config file path in wc-dataload-stloc.xml.
8.Add the table column mapping with the CSV column in wc-loader-store-location.xml.
9. Run the dataload command from command prompt.

F:\IBM\WebSphere\CommerceServer70\bin>dataload F:\IBM\WebSphere\CommerceServer70\samples\DataLoad\StoreLocator\wc-dataload-stloc.xml

Useful Link : https://www.youtube.com/watch?v=jCVOwqH0Rhw
http://www-01.ibm.com/support/knowledgecenter/SSZLC2_7.0.0/com.ibm.commerce.data.doc/refs/rmldataloadsample.htm 

Friday, 3 July 2015

Delete SSL certificate from WCS WAS admin console

Once there was a requirement for me to delete an existing soon to expire SSL certificate from Websphere commerce server. I did with just delete option that we have for signer and personal certificate. But the problem occurred when stopping the server. The personal certificate reference was used in Dynamic end point configuration while it was deleted from key store, which gave error while stopping the server and the server did not start successfully and the test environment was all messed up:). Luckily I had a config backup, which I used it and the environment became all fine. But keep in mind before modifying anything in WAS admin console be sure to take config folder back up.  The config folder can be found in WCS installable folder as  for ex: C:\IBM\WebSphere\CommerceServer70\config

Steps to delete SSL certficate from WAS admin console in non clustered environment.

1) First delete the certificate reference from Dynamic endpoint configuration
SSL certificate and Management -> Dynamic outbound end point SSL configiguration -> Select the required NodeDefaultConfiguration entry and delete.  
2) Go to cellDefaultkeystore -> personal certificate -> Select the required certificate and choose replace--> select both option for delete in the next page -> then click apply.
3) Go to cellDefaultTruststore -> signer certificate -> If there is any signer certificate select it and delete.
4) Go to nodeDefaultTruststore -> signer certificate-> select the required
signer certificate and delete.
5)  Go to nodeDefaultkeystore --personal certificate -> Select the required certificate and choose delete(need not replace here)
6) check all the 4 places (signer and personal - node and cell) in keystore and truststore the certificate entry should not be there.
7) In dynamic endpoint try creating new entry (don't save it) and c if the aliases dropdown should not contain the certificate name that you deleted. If it still contains the personal certificate name that you have deleted then it means it has not reflected in security.xml and certificate deletion is not done properly and you might get error while stopping server and face issues in the application.

In Non clustered environments it's more simpler:
1) First delete the certificate reference from Dynamic endpoint configuration
SSL certificate and Management -> Dynamic outbound end point SSL configiguration -> Select the required NodeDefaultConfiguration entry and delete. 
2) Go to nodeDefaultTruststore -> signer certificate-> select the required signer certificate and delete.
3)  Go to nodeDefaultkeystore --personal certificate -> Select the required certificate and choose replace--> select both option for delete in the next page -> then click apply.
 
Do not forget to delete the signer entry if found in nodeDefaultkeystore / cellDefaultkeystore.


Thursday, 2 July 2015

SSL Certificate installation

SSL is a Self Signed certificate which is installed in the client machine and used when establishing a secured connection and exchanging data with the 3rd party vendor. In websphere commerce the SSL certificate is managed from WAS admin console.

In WAS admin console we have the options for :
1. Installing Singer certificate.
2. Install personal certificate.
3. Certificate expiry monitoring.
4. Delete/ Replace expired certificates.

Websphere commerce server environment can be either clustered (federated) / non clustered.  and N number of certificates can be installed in both of these server types.

We will see below steps on how to install SSL certificate through WAS admin console:   
But keep in mind before modifying anything in WAS admin console be sure to take config folder back up.  The config folder can be found in WCS installable folder as  for
ex: C:\IBM\WebSphere\CommerceServer70\config
Before beginning with Certificate installation in WAS admin console first we need to check that SSL Settings are configured properly.
  1. Go to Security -> SSL Certificate and Key Management ->Manage end point security configurations 

2. Select the particular node / cell in outbound configurations based on the clustering.


3.      See to it that there is no certificate alias name selected in the Specific SSL configurations, it should be “none”: (Otherwise the alias selected certificate will only work in the server other certificates installed will not work)


4. Then go to Security -> SSL Certificate and Key Management -> SSL Configurations and select the NodeDefaultSSLSettings that was chose in step 3. 


5. In General Properties for NodeDefaultSSLSettings, see that ‘Default Server certificate alias’ and ‘Default client certificate alias’ is selected as “None” - (Otherwise the alias selected certificate will only work in the server, the other certificates will not work)


5.  Then the rest of the procedure is same that we follow for any SSL certificate installation: For ex:  
  1. Cell Default trust store -> signer certificate ->retrieve from port number ->Give hostname and post number (default port number is 443) ->Save.   
  1. NodeDefaulttrust store -> signer certificate -> retrieve from port number ->Give hostname and post number (default port number is 443) -> Save.
  1. CelldefaultKeystore -> Personal certificate -> Import certificates -> Get Key file alias ->Give the path of the signer certificate from the serverGive the path of the signer certificate from the server Ex:  C:\Users\..\Desktop\certificateName.pfx Save.      Key file name -- Should be the file name including the path where it is placed.
  1. Node default key store -> Personal certificate -> Import certificates -> Get key file alias -Ex:  C:\Users\..\Desktop\certificateName.pfx key file password - Password for the signer certificate Save     
  1. SSL certificate and Management -> Dynamic outbound end point SSL config -> new -> NodeDefaultConfig
    https, https://... ,443 -> Add -> Save 
         Basically the entry should be in this form “https, hostname, 443” (443 is the default port)

Note : If you already have NodeDefaultConfig entry in your WAS server then you can use different name like NodeDefaultConfig1

Then restart the server.