Friday, November 25, 2011

JSP / javascript escape "$" / EL expression

http://www.velocityreviews.com/forums/t129212-ot-jsp-escape-el-expressions.html

:

The problem:
Using JQuery template,
The javascript when included in the JSP, evaluated fields like "${name}" into JSP EL expressions as obvious. But I wanted them to be included in the templates as is.

Solution:
${'${'}name}

Note:
Using
<script id="searchFriendTemplate" type="text/x-jquery-tmpl">
for declaring the template.
http://api.jquery.com/template/

:).

Spring security and JPA

Always remember to declare
"Spring OpenEntityManagerInViewFilter" before "springSecurityFilterChain" in web.xml.
Otherwise JPA calls to load entities would return entities successfully but without all properties (null values for entity fields).

Correct:

<filter-mapping>
<filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
        ...
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

Thursday, November 24, 2011

Eclipse/IDE build failing - version problems

Here's what the issue was:
Developing on a project having a complex build process:
Spring Roo generating AspectJ sources - GWT - Datanucleus enhancing the outcome etc.

The project was initially built on STS with an older version (lets say V1) with all the required classpath and preferences to compile-build the project using STS. (Later command line build was introduced using maven).
It was checked-in to an SVN repo with all the complex eclipse/STS preferences and classpath.

Downloaded the project from SVN.
Installed a later version of STS-V2.
The project won't build.
Well, actually I won't need the IDE build as the project was building well with maven on command-line, but I guess IDE build would be required for debug to map classes to sources- not sure of that though.

When I looked at the changes in an SVN client, IDE had changed the IDE prefs and classpath to match the STSV2 plugins/mechanisms.

Reverted the changes, project built on IDE with a few errors related to project configurations. No compile errors-that important.

Started debug from command line- connected to the debug from IDE by debugging the app as "External app". All well.
:)

Wednesday, November 23, 2011

Clean URLs with Drupal-UrlRewriteFilter-Quercus-Jboss


http://www.brianshowalter.com/blog/running_drupal_on_quercus - There's a nice RewriteRule-RewriteMatch combo classes for UrlRewriteFilter posted at this blog.
But it's designed  for tomcat and didn't work on following JBoss configuration right away.
The JBoss config:
1. JBoss-4.2.2
2. Deploying the Quercus web-app(with Drupal inside) as exploded war (Folder name= "myapp.war").
3. Quercus 403
4. Drupal-6.17.
5. UrlRewriteFilter-320
Steps that worked for me:
1. Follow  the above blog at brianshowalter.com.
2. Download UrlRewriteFilter source code from http://code.google.com/p/urlrewritefilter/
(http://code.google.com/p/urlrewritefilter/downloads/detail?name=urlrewritefilter-3.2.0-src.zip&can=2&q=)
3. You must have already downloaded drupalrewrite_0.1 in step1.
4. Couldn't find a link for posting comments on above blog. Hence posting the modified source code here. Kindly setup UrlRewriteFilter and drupalrewrite_0.1 sources with all required libs in eclipse etc. and copy the compiled classes to your myapp.war/WEB-INF/classes.
5. Checkout updated sources for drupalrewrite fromhttp://drupalrewritefilter.googlecode.com (http://code.google.com/p/drupalrewritefilter/source/checkout) and compile/jar and copy to WEB-INF/lib(jar) or WEB-INF/classes(class) as you wish.
6. Good to go.

Thank you.

Sunday, November 13, 2011

Spring intercept-url patterns "/** Vz /*"

http://stackoverflow.com/questions/5240794/spring-intercept-url-patterns : "Melv" says that  the difference between /* and /** is as follows
Eg:

Main.java
directory/Main.java
/*: Files only at the / directory level are matched. Contents of directories are not processed. Thus only Main.java is returned.
/**: Pattern matcher recurses into directories also. Thus /**/*.java returns the directory/Main.java too along with /Main.java.

Thursday, November 10, 2011

Bash script to build and deploy GWT-SpringRoo-MVN app to tomcat


Following is a bash script that I wrote to perform following batch of tasks:
1. Invoke ROO shell to perform a startup scan to update generated sources. Optional(--rooscan option)
2. Somehow ROO updated the project POM to use GWT-2.3.0. Hence after scan is complete, using "sed" to update the POM(--modpom).
3. There is an option to do an "mvn gwt:run" or
to do an "mvn package" and deploy it to tomcat installation(--deploy) and copy some extra libs into the deployed app(--cpextjars)



#!/bin/sh
####################################################
#
# Author: Tapomay Dey
# Start Date: 9th November 2011
#
####################################################
# Please change the following variables to match your environment

project_home=
roo_home=
maven_home=
tomcat_deploydir=/var/lib/tomcat6/webapps
version=0.1.0.BUILD-SNAPSHOT

CLEAN=clean
ROOSCAN=false
DEPLOY=false
MODPOM=false
CPEXTJARS=false
GWTVERSION=2.2.0

usage() {
  echo "Usage: argument descriptions"
  echo "${0} [--rooscan] [--deploy] [--noclean] [--modpom] [--extjars]"
  echo "--rooscan: invokes roo shell for auto scan before proceeding"
  echo "--deploy: deploys app to tomcat. If not set, the app is run using gwt:run"
  echo "--noclean: mvn clean is not performed"
  echo "--modpom: Modifies project POM to reset GWT version to 2.2.0 and sets datanucleus fork=true."
  echo "--extjars: After deploying app to tomcat, copies external jars to deployment and restarts tomcat."
}

rooscan() {
  cd $project_home
  echo "Running ROO shell in $project_home ....."

  TEMP_FILE=`mktemp -t input.XXXXXX.tmp`
  echo 'quit' >> $TEMP_FILE
  $roo_home/bin/roo.sh < $TEMP_FILE
}

maven_run() {
  echo "Running APP....."
  cd $project_home
  pwd
  echo "$maven_home/bin/mvn ${CLEAN} ..... gwt:run -e";
  $maven_home/bin/mvn ${CLEAN}..... gwt:run -e

}

maven_deploy() {
  echo "Deploying to tomcat....."
  cd $project_home
  pwd
  echo "$maven_home/bin/mvn ${CLEAN} ..... package -e"
  $maven_home/bin/mvn ${CLEAN} ..... package -e

  cd target
  cp project-${version}.war project.war
  sudo cp project.war ${tomcat_deploydir}
  sudo /etc/init.d/tomcat6 restart
  echo 'Deployed to tomcat.....Press Enter'
  read s
}

modpom() {
  file=pom.xml
  temp_file=pOmTeMp.tmp
sed "
  # Change fork value for datanucleus to true
  /<groupId>org.datanucleus<\/groupId>/,/<\/plugin>/ {
  s/<fork>false<\/fork>/<fork>true<\/fork>/
  }
  # Set GWT versions to 2.2.0
  /<artifactId>gwt-maven-plugin<\/artifactId>/,/<\/plugin>/ {
  s/<version>.*<\/version>/<version>${GWTVERSION}<\/version>/
  }
  " <${file} > ${temp_file}
 
  mv ${temp_file} ${file}
}

cpextjars() {
  echo "Copying external jars to tomcat deployment....."
  cd $project_home
  sudo cp externaljars/extralib1.jar ${tomcat_deploydir}/project/WEB-INF/lib
  sudo cp externaljars/extralib2.jar ${tomcat_deploydir}/project/WEB-INF/lib
  sudo /etc/init.d/tomcat6 restart
  echo 'Deployed External JARs to tomcat.....Press Enter'
  read s
}

echo "WELCOME ${USER}"
cd $project_home
pwd

echo "Options Selected: $*"
for i in $*
do
case $i in
    --help)
usage
exit
;;
    --rooscan)
echo 'Rooscan option detected.'
ROOSCAN=true
;;
    --noclean)
echo 'No-clean option detected.'
CLEAN=''
;;
--deploy)
echo 'Deploy option detected'
DEPLOY=true
;;
--modpom=*)
echo 'modpom with value option detected'
MODPOM=true
GWTVERSION=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
;;
--modpom)
echo 'modpom option detected'
MODPOM=true
;;
--cpextjars)
echo 'cpextjars option detected'
CPEXTJARS=true
;;
    *)
                # unknown option
;;
  esac
done

echo "ROOSCAN=${ROOSCAN}"
echo "DEPLOY=${DEPLOY}"
echo "MODPOM=${MODPOM}"
echo "GWTVERSION=${GWTVERSION}"
echo "CPEXTJARS=${CPEXTJARS}"

if ${ROOSCAN};
then
rooscan
fi

if ${MODPOM};
then
modpom
fi

if ! ${DEPLOY};
then
echo 'RUN GWT'
maven_run
else
echo 'DEPLOY TO TOMCAT'
maven_deploy
fi

if ${CPEXTJARS};
then
cpextjars
fi

sudo -k
echo 'Exiting.....'

Wednesday, November 9, 2011

Parsing Bash Script Command Line Arguments

http://www.digitalpeer.com/id/parsing

for i in $*
do
 case $i in
     --prefix=*)
  PREFIX=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
  ;;
     --searchpath=*)
  SEARCHPATH=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
  ;;
     --lib=*)
  DIR=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
  ;;
     --default)
  DEFAULT=YES
  ;;
     *)
                # unknown option
  ;;
   esac
done

Tuesday, November 8, 2011

Maven - mavenize project and recipes

Links and commands used by the authors:
http://i-proving.com/2007/03/29/Maven-Recipes/

http://i-proving.com/2007/04/27/How-to-Mavenize-an-Existing-Eclipse-Project/ :
Insure that your M2_REPO variable is properly defined
mvn -Declipse.workspace=<path-to-eclipse-workspace> eclipse:add-maven-repo
mvn eclipse:eclipse -DdownloadSources=true

http://i-proving.com/2009/11/03/creating-a-maven-project-and-adding-it-to-subversion/ :
mvn archetype:create -DgroupId=[packageName] -DartifactId=[projectName]
mvn eclipse:eclipse -DdownloadSources.
For integration with Hudson, some nodes should be added to the pom.xml
 1. parent 
 2. distributionManagement 
 3. scm
Project under an existing project:
Using the command line, enter the following in the root of the parent project
mvn archetype:create -DgroupId=[packageName] -DartifactId=[projectName]
svn add 'projectName'
svn commit [projectName] pom.xml
mvn eclipse:eclipse -DdownloadSources

http://i-proving.com/2007/05/10/How-to-Determine-the-Maven-dependency-to-use-for-a-jar/ :
$ md5sum commons-collections.jar
$ openssl dgst -md5 commons-collections.jar
$ openssl dgst -sha commons-collections.jar
mvn deploy:deploy-file -Dfile=<the file to deploy> \
   -Durl=<url to your repository> \
   -Dpackaging=jar \
   -DrepositoryId=<the repositoryID> \
   -DpomFile=<path to your pom.xml file>

http://i-proving.com/2007/03/29/Split-Your-Project-Into-Sub-Projects/ :
+-- workspace/
    +-- myproject/
    |    +-- pom.xml    --IMP: please refer link for contents. Note <packaging>pom</packaging>
    +-- subproject-1/
    |    +-- pom.xml
    +-- subproject-2/
        +-- pom.xml
The  myproject pom makes myproject your "one stop shopping" location for running mvn goals such as install or release or eclipse:eclipse
If subproject-1 pom has
<groupId>ca.intelliware</groupId>
  <artifactId>subproject-1</artifactId>
  <version>1.0-SNAPSHOT</version>
and if subproject-2 consumes subproject-1 as a dependency
then
<dependencies>
    <dependency>
        <groupId>ca.intelliware</groupId>
        <artifactId>subproject-1</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
  </dependencies>
eclipse:eclipse goal behaviour:
If dependency.SNAPSHOT: subproject-2 should reference the Eclipse project for subproject-1 as a project dependency in its Java build path
else if dependency.RELEASE: Eclipse project that gets generated by the eclipse:eclipse will simply refer to the released version of the JAR in your M2_REPO repository
1. mvn archetype:create -DartifactId=myNewProject -DgroupId=ca.intelliware
2. cd myNewProject 
3. mvn archetype:create -DartifactId=myNewSubProject-i -DgroupId=ca.intelliware
4. cd ..
5. mv myNewProject/myNewSubProject-i ./myNewSubProject-i
6. Edit myNewProject.POM
<modules>
        <module>../myNewSubProject-1</module>
        <module>../myNewSubProject-2</module>
</modules>
7. mvn -DdownloadSources=true eclipse:eclipse
SPLITTING PROJECT: foobar->{foo,bar}
1. Rename foobar as foo
2. mvn archetype:create -DartifactId=foobar -DgroupId=ca.intelliware

Edit foobar.POM.packaging to "pom"
3. cd foobar
4. mvn archetype:create -DartifactId=bar -DgroupId=ca.intelliware
5. cd ..
6. mv foobar/foo ./foo
7. Edit foo.POM.artifactId to foo
8. Copy bar.POM.parent to foo.POM.parent
9. Edit foobar.POM

<modules>
    <module>../foo</module>
    <module>../bar</module>
</modules>
10. Move code you want to split from foo to bar
11. mvn eclipse:eclipse
Thats it for now!!!

C:\>mvn install:install-file -Dfile=utils.jar -DgroupId=com.zparacha.example -DartifactId=utils -Dversion=1.0 -Dpackaging=jar