Sunday, January 31, 2016

NPE thrown while accessing Hybris custom b2c_acc_responsive storefront


This issue seems to have plagued Hybris commerce suite right from version 5.6 to the most recent version 5.7.0.5, There have been several solutions being discussed on the hybris expert forums to workaround the issue. However, I wanted to share the official answer from SAP to workaround this error.

NPE exception while accessing custom store generated using modulegen

Steps for Reconstruction


>install.bat -r b2c_acc_responsive  
>ant all  
>ant modulegen -Dinput.module=accelerator -Dinput.name=myb2c -Dinput.package=org.myb2c  

Added following to localextensions.xml

  1. <hybrisconfig xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='../bin/platform/resources/schemas/extensions.xsd'>  
  2.   <extensions>  
  3.     <path dir='${HYBRIS_BIN_DIR}' />  
  4.     <extension name='mcc' />  
  5.     <extension name='backoffice' />  
  6.     <extension name='commercesearchbackoffice' />  
  7.     <extension name='commerceservicesbackoffice' />  
  8.     <extension name='solrfacetsearchbackoffice' />  
  9.     <extension name='solrserver' />  
  10.       
  11.     <!-- OOB Store -->      
  12.     <!-- https://localhost:9002/yacceleratorstorefront/electronics/en/?site=electronics -->  
  13.     <!--extension name='yacceleratorcockpits' />  
  14.     <extension name='yacceleratorinitialdata' />  
  15.     <extension name='yacceleratorstorefront' />  
  16.     <extension name='yacceleratorfulfilmentprocess'/-->  
  17.       
  18.   <!-- Custom Store -->  
  19.   <!-- https://localhost:9002/myb2cstorefront/electronics/en/?site=electronics -->  
  20.   <extension dir="${HYBRIS_BIN_DIR}/custom/myb2c/myb2ccore"/>  
  21.   <extension dir="${HYBRIS_BIN_DIR}/custom/myb2c/myb2cfacades"/>  
  22.   <!--extension dir="${HYBRIS_BIN_DIR}/custom/myb2c/myb2ctest"/-->  
  23.   <extension dir="${HYBRIS_BIN_DIR}/custom/myb2c/myb2cfulfilmentprocess"/>  
  24.   <extension dir="${HYBRIS_BIN_DIR}/custom/myb2c/myb2cstorefront"/>  
  25.   <extension dir="${HYBRIS_BIN_DIR}/custom/myb2c/myb2cinitialdata"/>  
  26.   <extension dir="${HYBRIS_BIN_DIR}/custom/myb2c/myb2ccockpits"/>  
  27.   
  28.   
  29.     <extension name='yaddon' />  
  30.     <extension name='ycommercewebservices' />  
  31.     <extension name='electronicsstore' />  
  32.     <extension name='apparelstore' />  
  33.     <extension name='liveeditaddon' />  
  34.       <extension name='acceleratorwebservicesaddon' />  
  35.   </extensions>  
  36. </hybrisconfig>  

>install.bat -r b2c_acc_responsive  
>ant all  
>ant modulegen -Dinput.module=accelerator -Dinput.name=myb2c -Dinput.package=org.myb2c  

Navigate to

Workaround for the issue

3 properties should be added for the custom storefront in local.properties

  1. myb2cstorefront.additionalWebSpringConfigs.liveeditaddon=classpath:/liveeditaddon/web/spring/liveeditaddon-storefront-web-spring.xml  
  2. cmsPageBeforeViewHandler=org.myb2c.storefront.interceptors.beforeview.CmsPageBeforeViewHandler  
  3. uiThemeResourceBeforeViewHandler=org.myb2c.storefront.interceptors.beforeview.UiThemeResourceBeforeViewHandler  

after that, please do  'ant clean all', and restart hybris server
Navigate to

A defect has been logged with hybris to fix this issue in version 5.7, until the fix is available you may use the workaround provide by SAP to circumvent this error.

Thursday, October 22, 2015

Working with HSQLDB and Hybris

Synopsis


Hybris by default includes HSQLDB as the embedded DB for development mode, Out of the box option to query database includes running Flex or SQL query from the admin console.
In this blog we explore few other convenience options to query the database by making use of external SQL clients, we further explore the option of configuring Hybris with a standalone version of HSQL server

Hybris Version: 5.6.0.2
HSQL DB Version: 2.2.9

Embedded Database

By default hybris creates embedded database data file at ~/hybris5602/hybris/data/hsqldb/ , the data file name is mydb
We will provide this information while connecting from SQuirrel SQL Client or any other client of your choice.

jdbc:hsqldb:file:~/hybris5602/hybris/data/hsqldb/mydb;readonly=true



Standalone Database Server


You may refer following WIKI link to verify the supported version of DB https://wiki.hybris.com/display/release5/Third-Party+Compatibility+-+Release+5.0

Create server.properties with following content, this configuration will create a database with the name hybris running on port 9999

#Hybris DB configuration file
# Databases:
server.database.0=file:hybris/hybris
server.dbname.0=hybrisdb
# =====
# Other configuration:
# Port
server.port=9999
# Show stuff on the console (change this to true for production):
server.silent=false
# Don't show JDBC trace messages on the console:
server.trace=false
server.no_system_exit=false
# Do not allow remote connections to create a database:
server.remote_open=true
# =====

HSQLDB download does not include a startup script by default for MAC OS or Unix, you may create a startup script as follows.
#hsqldb/bin/runServer.sh
java -cp ../lib/hsqldb.jar org.hsqldb.server.Server --props ../../datafile/server.properties
Make the script executable chmod 777 runServer.sh
Run the server by executing
./runServer.sh
This should start the new DB server on port 9999

Try connecting from SQuirrel SQL client first.
You may use username SA and blank password to connect, however, it is recommended to make use of a non  - DBA user account.

jdbc:hsqldb:hsql://localhost:9999/hybrisdb

Add following in local.properties

db.url=jdbc:hsqldb:hsql://localhost:9999/hybrisdb
db.driver=org.hsqldb.jdbcDriver
db.username=HYBRIS
db.password=hybris
db.tableprefix=
hsqldb.usecachedtables=false

Perform ant all
Start server and initialize to load schema and tables to the new standalone database.
you should now be able to connect to the database using SQL Client as follows.