• Entries (RSS)
  • Comments (RSS)

Retrieving Merchant Key value from WebSphere Commerce Server

Posted by | Posted in WebSphere Commerce | Posted on 23-08-2010

Tagged Under : , , ,

Retrieving Merchant Key value from WebSphere Commerce Server

Merchant Key

The merchant key is the encryption key used in WebSphere Commerce Server. Merchant key is a 16 digit hexadecimal number that has at least one numeric character, at least one alphabetic character (a-f) with no upper case letter. The merchant key cannot contain the same character more than four times and four consecutive occurrence of the same character is not allowed. The merchant key will be present in WebSphere commerce instance xml file in encrypted format. To get the plain text version of the merchant key, place the following text in any WCS view and run it on the server.

<%
	System.out.println("Merchant Key :"+com.ibm.commerce.server.ConfigProperties.singleton().getMerchantKey());
%>

Reset password in WCS

Posted by | Posted in WebSphere Commerce | Posted on 22-08-2010

Tagged Under : , , ,

Resetting user password in WCS

There will be situations where you may have forgotten the password of a user and you want to reset the password in WCS. In WebSphere Commerce all the passwords are one way encrypted with a salt and Merchant Key. The main purpose of a salt is to add more security to storing passwords. With the help of Salt during encrypting the password, WCS makes sure that two users that have the same password will not have the same encrypted string as their password.

Reset by updating DB
Resetting the password is easy if you already know the password of at least one user. For e.g.: if you already know the password of user with users_id 9000 and you want to reset the password of user with users_id = 9001, then execute the following query in the database.

UPDATE USERREG SET LOGONPASSWORD = (SELECT LOGONPASSWORD FROM USERREG WHERE USERS_ID = 9000), SALT = (SELECT SALT FROM USERREG WHERE USERS_ID = 9000), PASSWORDINVALID= (SELECT PASSWORDINVALID FROM USERREG WHERE USERS_ID = 9000), STATUS = (SELECT STATUS FROM USERREG WHERE USERS_ID = 9000) WHERE USERS_ID=9001;

Now user 9001 can login with user 9000′s password. In the above case we copied the details like salt, logonpassword etc of user 9000 to user 9001

Reset with the help of wcs_password utility.
Consider case where you do not know the password any of the users. Now to reset the password you need to generate the password by yourself. To generate the encrypted password for any string, WCS has a utility, ‘wcs_password’. wcs_password utility takes three parameter as the input. The syntax for wcs_password utility is given below

wcs_password <password> <salt> <key>

Where password is the new password, salt is the salt for the user and key is the Merchant Key

Once we provide all these details, the command will give the encrypted password in both ASCII and hex format. Take the ASCII formatted string and update the USERREG.LOGONPASSWORD column with that value. E.g.: The SQL to update the password for wcsadmin is given below

UPDATE userreg SET logonpassword='output of wcs_password utility' WHERE logonid = 'wcsadmin'

Now you can login with the new password.

The wcs_password.bat utility will be available in your bin directory.

Reset with chgwcspwd utility
The third way of resetting the password is with the help of chgwcspwd utility. This utility changes the password directly in the db. So we do not need to execute any SQL commands by our own. But this tool is available only in IBM iSeries. So I have not tried this yet. The syntax to use this utility is

chgwcspwd.sh -database <dbname> -dbHostname <db host name> -schema <schema name> -instance <instance name> -instancePwd <db password>-merKey <key> -wcsUser <wcs username> -wcsUserPwd <user's new password>

WebSphere Commerce feature pack installation

Posted by | Posted in WebSphere Commerce | Posted on 14-03-2010

Tagged Under : , , ,

WebSphere Commerce Feature pack installation

WebSphere Commerce Feature pack installation is a straight forward job. Follow the below steps for installation of Feature packs in your machine. In order to install feature packs our WCS installation needs to be in some desired fix level. So the first thing is to apply the required fix levels in our WC installation.

We need WebSphere Commerce Update installer for installing WCS fix packs. So follow the below steps to install WebSphere Commerce update installer.

1. Download WebSphere Commerce Update installer from location

http://www.ibm.com/support/docview.wss?uid=swg24013502

2. Extract the contents and double click on install.exe and follow onscreen instructions. Please make sure that there is no space in your directory structure.

Too simple? Yeah we are done with the installation of WCS update installer. Now let us apply the fix packs to make our WCS installation to the required level.

3. Download the latest WCS fix pack from http://www-01.ibm.com/support/docview.wss?rs=3046&uid=swg21246009. I have downloaded fix pack 9 (6.0.0-WS-WCDeveloper-FP009.pak) from here.

4. Save the fix pack to %WCS_UPDATE_INSTALL_DIRECTORY%/maintenance directory.

5. Open WebSphere Commerce update installer.(Just double click on the update.bat from %WCS_UPDATE_INSTALL_DIRECTORY% )

6. Specify the WebSphere Commerce Developer installation directory, and click next.

7. Select Install Maintenance Package. Click Next.

8. Select the %WCS_UPDATE_INSTALL_DIRECTORY%/maintenance directory and click next.

9. Select the 6.0.0-WS-WCDeveloper-FP009.pak file and click next.

10. You are prompted to update the database. Select Yes to update your database automatically.

11. On the summary page, review the information and click Next.

12. Fix pack installation begin and the final screen will be displayed with a success message on the screen. If it failed please check the log files for trouble shooting. Click on Finish from this screen

13. Download the WebSphere Commerce feature pack package and extract to a temporary location

14. Double click on install.bat. The installation wizard opens. Click on Next

15. Accept the license agreement. Click on Next

16. Production selection page opens. Select the location where you have installed WebSphere Commerce Developer on this page. Click On Next

17. Installation summary page will be displayed. Click on Next

18. Click on Finish in installation result page

We have successfully installed the WCS feature pack in our machine.

CNTR0031W: Error starting CMP bean wcfull#WebSphereCommerceServerExtensionsData.jar

Posted by | Posted in WebSphere Commerce | Posted on 24-05-2009

Tagged Under : , , ,

CNTR0031W: Error starting CMP bean wcfull#WebSphereCommerceServerExtensionsData.jar#XXXX: 
 javax.naming.NameNotFoundException: Context: localhost/nodes/localhost/servers/server1, name: jdbc/Default: First component in name Default not found.  Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0
	at com.ibm.ws.naming.ipcos.WsnOptimizedNamingImpl.do_resolve_complete_info(WsnOptimizedNamingImpl.java:968)
	at com.ibm.ws.naming.cosbase.WsnOptimizedNamingImplBase.resolve_complete_info(WsnOptimizedNamingImplBase.java:1431)
	at com.ibm.WsnOptimizedNaming._NamingContextStub.resolve_complete_info(Unknown Source)
	at com.ibm.ws.naming.jndicos.CNContextImpl.cosResolve(CNContextImpl.java:3493)
	at com.ibm.ws.naming.jndicos.CNContextImpl.doLookup(CNContextImpl.java:1521)
	..............................
 
JDBCPersister W CNTR0032W: Error creating CMP persister using datasource: jdbc/Default
BeanMetaData  E CNTR0035E: EJB container caught com.ibm.ejs.container.ContainerException: ; nested exception is: 
	com.ibm.websphere.cpi.CPIException: Persister creation failed.The bean's J2EEName is wcfull#WebSphereCommerceServerExtensionsData.jar#XXXX. The data source name is jdbc/Default.; nested exception is: 
	javax.naming.NameNotFoundException: Context: localhost/nodes/localhost/servers/server1, name: jdbc/Default: First component in name Default not found. [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]
	at com.ibm.ejs.container.BeanMetaData.completeInitialization(BeanMetaData.java:1299)
	at com.ibm.ws.runtime.component.EJBContainerImpl.createBeanMetaData(EJBContainerImpl.java:1039)
	at com.ibm.ws.runtime.component.EJBContainerImpl.createModuleMetaData(EJBContainerImpl.java:830)
	at com.ibm.ws.runtime.component.EJBContainerImpl.createMetaData(EJBContainerImpl.java:1575)
	at com.ibm.ws.runtime.component.MetaDataMgrImpl.createFactoryMetaData(MetaDataMgrImpl.java:115)
	......................

This was the exception I got when I tried to start my WebSphere Commerce Full Test environment after creating a new EJB. Even though the solution was very simple, for me it took some time to figure it out what exactly went wrong. If any of you facing the same problem, then here is the fix.

Open your ibm-ejb-jar-bnd.xmi file. Search for jdbc/Default. Here jdbc/Default is the name of the data source that was not found by the server. You will be able to see an entry like

	<defaultDatasource xmi:id="ResourceRefBinding_1242722240919" jndiName="jdbc/Default"/>

Just to remove the above line and your server will again start properly.

Oracle CLOB data type and Entity Beans in WebSphere Commerce Server

Posted by | Posted in WebSphere Commerce | Posted on 06-04-2009

Tagged Under : , ,

Oracle CLOB data type and Entity Beans in WebSphere Commerce Server.

We all know how to create an entity bean and access bean for a table that we have added newly if it contains String, Integer, Long etc data types. But when our new table has Oracle CLOB as the data type for one of the column, our access bean will not work properly. In this case in order to make our access bean working with CLOB/BLOB data type we need to edit the entity bean methods and use a session bean to store and retrieve the CLOB data. Follow the below steps to access an Oracle CLOB field from a CMP Entity bean. The trick is to use the JDBC calls to store and retrieve the CLOB data.

I am assuming that you have created a new entity bean (say NewTableBean) that has a field named ‘value’ which is of type Oracle CLOB. The data type for value field in our entity bean is a String.

1. The first step in making CLOB working for an entity bean is to create a session bean to perform our JDBC calls. When creating the session bean make sure that you have extended the session bean from com.ibm.commerce.base.helpers.BaseJDBCHelper

2. Add a method for retrieving the CLOB data using JDBC calls. The code for reading CLOB using JDBC is given below. In this case I named the method as findValueByPrimaryKey.

	public String findValueByPrimaryKey(Long primaryKey) 
			throws NamingException, SQLException {
		makeConnection();
 
		PreparedStatement ps = getPreparedStatement(
				"SELECT VALUE FROM XNEWTABLE WHERE NEWTABLE_ID = ?");
		ps.setLong(1, primaryKey.longValue());
 
		String stringTemp = null;
 
		try {
			ResultSet rs = executeQuery(ps, false);
 
			if (rs.next()) {
				Clob clobTemp = rs.getClob(1);
 
				if ((clobTemp == null) || ((int) clobTemp.length() == 0)) {
					stringTemp = null;
				} else {
					stringTemp = clobTemp.getSubString(1,
							(int) clobTemp.length());
				}
			}
		} finally {
			closeConnection();
		}
 
		return stringTemp;
	}

3. Add a method for updating the CLOB data using JDBC calls. The code for updating CLOB using JDBC is given below. In this case I have named my method as updateValueByPrimaryKey

	 public int updateValueByPrimaryKey(Long primaryKey,
		String value) throws NamingException, SQLException {
		int rowCount = -1;
		makeConnection();
 
		PreparedStatement stmt = getPreparedStatement(
				"UPDATE SET VALUE =? WHERE NEWTABLE_ID  =?");
		stmt.setLong(2, primaryKey.longValue());
 
		if (value == null) {
			stmt.setNull(1, Types.CLOB);
			rowCount = executeUpdate(stmt, false);
		} else {
			try {
				PreparedStatement stmt1 = getPreparedStatement(
						"UPDATE XNEWTABLE SET VALUE = empty_clob()  WHERE NEWTABLE_ID = ?");
				stmt1.setLong(1, primaryKey.longValue());
				stmt1.executeUpdate();
 
				PreparedStatement stmt2 = getPreparedStatement(
						"SELECT VALUE FROM XNEWTABLE WHERE NEWTABLE_ID=? FOR UPDATE");
				stmt2.setLong(1, primaryKey.longValue());
 
				ResultSet rs = stmt2.executeQuery();
 
				if (rs.next()) {
					Clob myClob = rs.getClob("VALUE");
					Writer writer = null;
					writer = ((oracle.sql.CLOB) myClob).getCharacterOutputStream();
 
					char[] aXMLDataData = value.toCharArray();
					writer.write(aXMLDataData);
					writer.flush();
					writer.close();
				} else {
					throw new ObjectNotFoundException();
				}
 
				rs.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
 
			rowCount = 1;
		}
 
		return rowCount;
	}

Now we have both the methods for updating and reading the CLOB column is ready. The next step is to call these functions from our entity bean so that the CLOB columns also will be updated/retrieved when we use our access bean.

4. Open the entity bean class we have created and search for a method called _copyFromEJB. Replace the following code

	h.put("value", getType());

with this code.

	NewTableHelperSessionBean sbNewTable = new NewTableHelperSessionBean();
 
	try {
		h.put("value",
			sbNewTable.findValueByPrimaryKey(
				newTableId));
	} catch (NamingException e) {
		e.printStackTrace();
	} catch (SQLException e) {
		e.printStackTrace();
	}

Here NewTableHelperSessionBean is the session bean we have created for performing our CLOB JDBC operations.

The above code will make sure that our session bean code will be called when we access the CLOB field.

5. The next step is to call the session bean update method whenever we update our entity bean. For that open the entity bean class we have created and search for a method called _copyToEJB. Replace the following code

	 if (h.containsKey("value")) {
		setValue((localValue));
	}

With this one.

	NewTableHelperSessionBean sbNewTable = new NewTableHelperSessionBean();
 
	try {
		if (h.containsKey("value")) {
			sbNewTable.updateValueByPrimaryKey(newTableId,localValue);
		}
	} catch (NamingException e) {
		e.printStackTrace();
	} catch (SQLException e) {
		e.printStackTrace();
	}

This will make sure that whenever the user calls the commitCopyHeler our CLOB field will be properly updated by calling the new session bean method.

We are done with all the required changes to make our entity bean working even for a CLOB column type. Now generate the deployment and RMIC code and start using your access bean/ entity bean. Have fun.