SDWest 2009

Monday. Disappointed to discover the coding dojo cancelled. Guessing that not enough people knew what it was and were not prepared to sign-up beforehand. Sat in instead on Scott Meyers’ ‘Better Software – No Matter What’: familiar material by a good presenter. Sofware quality depends on programmers, and how they exercise their discretion in implementing requirements: providing guidelines makes a significant difference. Insist on useful requirements. Create interfaces that are easy to use correctly and difficult to use incorrectly. Use design by contract to specify requirements using pre-conditions, post-conditions and invariants. Embrace static analysis. Favor constructor parameters over singletons.

Lunchtime presentation by Robert Martin, giving some inside history on Agile and Scrum, and how that has led to today’s movement for software craftsmanship.

Afternoon session on easyb and Groovy with Rod Coffin and Andy Glover: slow start before plunging into use of the requirements domain specific language with IntelliJ and Eclipse. Tested and documented version of a LIFO stack implemented with remarkable speed.

Evening discussion panel on SOA: a marketing buzz phrase past its prime. SOAP/HTTP web services remain the most robust solution even though simpler RESTful solutions have gained popularity on more ‘primitive’ platforms.

Finally an informal presentation by an engineering director and architect from LinkedIn describing their infrastructure and development practices. Tomcat, a custom MVC framework and JSP compiler, SpringRPC (~100 services), Jetty and Oracle on SPARC. Four million visitors a day peaking at 200,000 concurrent users. Originally pair programming but now simply at least two developers per project. No contractors, all 100 engineering staff in the same building. High end Mac workstations and laptops with Eclipse/IntelliJ. 1,500 JUnit/HttpUnit test cases for ~1,000 KLOC automated using Hudson. Database partitioned both vertically (by functional area) and horizontally (by member id range). Back to the hotel past 9pm.

Tuesday. Morning session Dean Warner on programming in Scala, a scary-powerful collision of Java and Lisp/Erlang used by Twitter for higly parallel message handling. Afternoon session with Chris Richardson, author of ‘POJOs in Action’ giving a technical introduction to Spring Framework dependency injection (replacing singletons with constructor arguments) enabling Spring AOP for service methods. Also Spring JDBC and Hibernate, all using either XML or annotations.

Wednesday. After two days of half-day tutorials the conference format switching to four 90 minute workshops per day plus lunchtime presentations. Website navigation using menus and search, especially for e-commerce. Overlay menus at Amazon. Everyone familiar with the layout of Outlook. BabyNameWizard.com making novel use of AJAX. Neal Ford with an introduction to Ruby and JRuby, an interpreted language well suited to metaprogramming such as building test frameworks including Mocha. Robert Martin walking through some of his code from FitNesse: functions should be well named, short, and do one thing only. Two presentations from Scott Ambler on Agile development: delivering code early and often, using TDD, involving stakeholders, building self-organizing teams and delivering what the customer wants. Geographically dispersed teams with a 15% higher rate of project failure: fly people around or pay more in hidden costs. Evening awards ceremony: Dr. Dobbs Excellence In Programming award going to Scott Meyers and over a dozen Jolt awards made in surprising haste, including easyb. Reading the first chapters of ‘Groovy In Action’.

Thursday. Morning sessions on how to select a web framework and testing web applications. Grails immature and questions still over the Groovy classloader. GWT-Ext and Tapestry 5 or Wicket a recommended configuration. Rod demonstrating unit and component testing tools, including infinitest, WicketTester, HtmlUnit and Watij. Lunchtime presentation from Juval Lowy on the coming boom in power management software for homes, electric vehicles and buildings. Afternoon sessions on Guice, a lightweight dependency injection framework, and using the new javax.script package in Java 6.

Friday. Morning sessions on Spring 3.0 and Continuous Testing. Spring Framework clearly mature and featureful. Rod demoing intellitest IDE plugin allowing all dependent unit tests in a project to be run automatically whenever class bytecode changed. Afternoon sessions on xUnit testing and generating documentation during the build cycle. Dependency injection does not require a framework for in-house applications. Creating and maintaining mock objects for database services may be impractical, consider the Dependent Object Framework and possibly H2 instead. Demos of Hudson and Doxygen rounding out the conference.

What did I get from the conference? Most inspriring was seeing Rod demonstrating TDD in action with a hands on pair programming session and discussions of the supporting tools. Scott Meyers, Robert Martin and Scott Ambler reinforcing the importance of TDD in the bigger picture, Justin Gordon describing use of TDD on a significant IBM project. Automated testing driving the adoption of dependency injection frameworks such as Spring and Guice. A second significant theme was scripting languages – including their use for testing – with sessions on Groovy/easyb, JRuby/Mocha and Scala. Finally there were the demos and pointers to projects like GWT-Ext, Hudson and Doxygen worthy of further investigation.

facelets-tutorial javax/el/ELResolverClass

ICEfaces have published a facelets-tutorial

Deployment instructions were limited so I downloaded and unzipped the source file into the samples folder provided with ICEfaces-1.7.2-SP1.

ant help
ant clean
ant tomcat6.0

I then copied dist/facelets-tutorial.war to tomcat-6.0/webapps… localhost…log showed:

Feb 21, 2009 11:11:07 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class com.sun.faces.config.ConfigureListener
java.lang.LinkageError: loader constraints violated when linking javax/el/ELResolver class
 at com.sun.faces.config.ConfigureListener.registerELResolverAndListenerWithJsp(ConfigureListener.java:581)

Incompatibility between the EL included with ICEfaces and the EL provided with Tomcat 6? Stopping Tomcat, removing webapps/facelets-tutorial/web/WEB-INF/lib/el-api.jar and restarting provides a quick fix. Closer inspection of the facelets-tutorial build.xml reveals it has entries obsoleted by the newer version of samples/etc/build-common.xml and so is still including jars not needed or desired with Tomcat 6.

Trac on Solaris using Apache mod_python and https

If Trac is being used by a distributed team over the internet we want to remove all privileges from unauthenticated users:

for perm in BROWSER_VIEW CHANGESET_VIEW FILE_VIEW LOG_VIEW MILESTONE_VIEW 
REPORT_SQL_VIEW REPORT_VIEW ROADMAP_VIEW SEARCH_VIEW TICKET_CREATE TICKET_MODIFY TICKET_VIEW 
TIMELINE_VIEW WIKI_CREATE WIKI_MODIFY WIKI_VIEW
do
  trac-admin $tracenv permission remove anonymous $perm
  trac-admin $tracenv permission add authenticated $perm
done

We also want to encrypt traffic to the site. To do this I tried stunnel…

/opt/csw/bin/pkg-get -i stunnel

…and placed the following in /opt/csw/etc/stunnel/stunnel.conf

 [https]
accept  = 443
connect = 8000

I also commented out the chroot setup. Once configured all that is required is to run

cd /opt/csw/etc/stunnel 
/opt/csw/bin/stunnel

…and change /var/opt/csw/trac/conf/trac.ini

 [trac]
authz_file =
authz_module_name =
base_url = https://trac.mydomain.com

The bad news is that Trac 0.10.4 does not consistently use base_url, so creating a ticket, for example, redirects the user to an http page.

PATH=/opt/csw/bin:$PATH
tracenv=/var/opt/csw/trac
HTTPS=1; export HTTPS
nohup tracd --port 8000 $tracenv &

To resolve this issue I decided to move from tracd/stunnel to Apache2/mod_python. The default Solaris 10 distribution includes apache2 but not mod_python. Instead I installed mod_python from Blastwave, which in turn automatically installs the Blastwave cswapache2 package below /opt/csw/apache2.

pkg-get install ap2_modpython

We will want to run trac under apache2 using a dedicated account:

groupadd -g 202 trac
useradd -g trac -u 202 -d /var/opt/csw/trac trac
chown -R trac:trac /var/opt/csw/trac

Modified /opt/csw/apache2/etc/httpd.conf

User trac
Group trac
…
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
…

   SetHandler mod_python
   PythonInterpreter main_interpreter
   PythonHandler trac.web.modpython_frontend
   PythonOption TracEnv /var/opt/csw/trac

Created a self-signed certificate for the site:

cd /opt/csw/apache2/etc
PATH=$PATH:/usr/sfw/bin
/usr/sfw/bin/openssl genrsa -out server.key 2048
/usr/sfw/bin/openssl req -new -x509 -key server.key -out server.crt -days 365 -subj "/C=US/ST=Florida/O=My Company/CN=trac.mydomain.com"

Modified /opt/csw/apache2/etc/extra/httpd-ssl.conf

ServerName trac.mydomain.com
…

   SetHandler mod_python
   PythonInterpreter main_interpreter
   PythonHandler trac.web.modpython_frontend
   PythonOption TracEnv /var/opt/csw/trac

To start Blastwave Apache2 using SMF on Solaris:

svccfg -s cswapache2 setprop httpd/ssl=true
svccfg -s cswapache2 listprop

svcadm enable cswapache2

To check status

svcs cswapache2
svcs –xv

Trac on Solaris

Trac is a web-based software project management and bug/issue tracking system. Example publicly accessible sites that use Trac include

Getting Trac installed on Solaris 10 is easy, see http://trac.edgewall.org/wiki/TracOnSolaris Question is, what next?

Blastwave packages are installed below /opt/csw (csw = Community SoftWare). /opt/csw/share/doc/trac/INSTALL provides the next steps. I used:

PATH=/opt/csw/bin:$PATH
MANPATH=/opt/csw/share/man:$MANPATH
tracenv=/var/opt/csw/trac
trac-admin $tracenv initenv
tracd --port 8000 $tracenv & # no authentication
firefox http://localhost:8000/trac

For a small number of users the tracd standalone server is good enough. Authentication can be managed with htdigest on Solaris 10 thusly:

/usr/apache2/bin/htdigest -c $tracenv/conf/users.htdigest
mydomain.com fred

Tracd can then be started like this:

PATH=/opt/csw/bin:$PATH
tracenv=/var/opt/csw/trac
nohup tracd --port 8000 --auth *,$tracenv/conf/users.htdigest,mydomain.com $tracenv &

To change the logo upload the new logo to /opt/csw/share/trac/htdocs and modify trac.ini

[header_logo]
…
link = https://trac.mydomain.com/
src = common/mylogo.png
…
[project]
descr = My Trac
footer = Visit the Trac open source project at 
http://trac.edgewall.org/
icon = common/trac.ico
name = My Project
url = https://myproject.mydomain.com/

Trac is much easier to administer with the WebAdmin plugin, which for Trac 0.10.4 requires downloading and installing from source:

easy_install http://svn.edgewall.com/repos/trac/sandbox/webadmin/

To get started a Trac administrator has to be empowered:

trac-admin /var/opt/csw/trac permission add fred TRAC_ADMIN

To simplify account administration we’ll also try an account manger plugin

/opt/csw/bin/easy_install http://trac-hacks.org/svn/accountmanagerplugin/0.10

…and change /var/opt/csw/trac/conf/trac.ini

[components]
webadmin.* = enabled
trac.web.auth.LoginModule = disabled
acct_mgr.api = enabled
acct_mgr.htfile.HtDigestStore = enabled
acct_mgr.web_ui.AccountModule = enabled
acct_mgr.web_ui.LoginModule = enabled
acct_mgr.web_ui.RegistrationModule = disabled
acct_mgr.admin.AccountManagerAdminPage = enabled
[account-manager]
password_format = htdigest
password_store = HtDigestStore
password_file = /var/opt/csw/trac/conf/users.htdigest
htdigest_realm = mydomain.com

Tracd can then be started like this:

PATH=/opt/csw/bin:$PATH
tracenv=/var/opt/csw/trac
nohup tracd --port 8000 $tracenv &

To manage custom fields we’ll add another plugin

easy_install http://trac-hacks.org/svn/customfieldadminplugin/0.10

…and change /var/opt/csw/trac/conf/trac.ini

[components]
customfieldadmin.* = enabled

Installing JBoss with Oracle XE on Windows

Both Tomcat and Oracle XML DB use port 8080 by default. Before installing JBoss I first changed the default port for XML DB as suggested here.

call dbms_xdb.cfg_update(updateXML(
            dbms_xdb.cfg_get()
          , '/xdbconfig/sysconfig/protocolconfig/httpconfig/http-port/text()'
          , 8081))
      /

I restarted the Oracle database and verified port 8081 was in use and not 8080.

CruiseControl and Subversion

Getting started with CruiseControl is relatively straightforward, see http://confluence.public.thoughtworks.org/display/CC/Getting+Started+With+CruiseControl

To place an application on CruiseControl it should have an Ant script to build it. The application Ant script does not need to interact with Subversion. The source for the application including the Ant script should be checked into Subversion.

I started to install CruiseControl by downloading and compiling the source, but my version of ant was too old. Instead I downloaded the binary (which ironically includes a newer ant also):

su -
wget http://downloads.sourceforge.net/cruisecontrol/cruisecontrol-bin-2.7.2.zip
unzip -d /opt cruisecontrol-bin-2.7.2.zip

useradd --system --home /srv/cruisecontrol --create-home --gecos "System account to run CruiseControl" cruise
usermod -s /bin/ksh cruise
su – cruise
mkdir checkout logs artifacts
PATH=$PATH:/opt/subversion-1.3.2/bin/:/opt/cruisecontrol-bin-2.7.2
cruisecontrol.sh

Now we need to configure CruiseControl to monitor the Subversion repository. Create config.xml:

  1. <cruisecontrol>  
  2.   <property name="svn.url" value="svn://svn/srv/svn">  
  3.   <property name="svn.username" value="cruise">  
  4.   <property name="svn.password" value="*****">  
  5.   <property name="ant.script" value="/opt/cruisecontrol-bin-2.7.2/apache-ant-1.7.0/bin/ant">  
  6.    
  7.   <project name="myproj">  
  8.     <listeners>  
  9.       <currentbuildstatuslistener file="logs/${project.name}/status.txt">  
  10.     </currentbuildstatuslistener></listeners>  
  11.    
  12.     <bootstrappers>  
  13.     </bootstrappers>  
  14.    
  15.     <!-- Defines where cruise looks for changes, to decide whether to run the build -->  
  16.     <modificationset quietperiod="10">  
  17.       <svn repositorylocation="${svn.url}" username="${svn.username}" password="${svn.password}">  
  18.     </svn></modificationset>  
  19.    
  20.     <!-- Configures the actual build loop, how often and which build file/target -->  
  21.     <schedule interval="60">  
  22.       <ant antscript="${ant.script}" buildfile="build-${project.name}.xml" target="clean-build" uselogger="true" usedebug="false">  
  23.     </ant></schedule>  
  24.    
  25.     <!-- directory to write build logs to -->  
  26.     <log dir="logs/${project.name}">  
  27.    
  28.     <!-- Publishers are run *after* a build completes -->  
  29.     <publishers>  
  30.     </publishers>  
  31.   </log></project>  
  32. </property></property></property></property></cruisecontrol>  

Build-myproj.xml contains Ant steps to checkout a clean copy of the application and build it:

To setup the dashboard, running at :8080

su - cruise cp /opt/cruisecontrol-bin-2.7.2/dashboard-config.xml . kill `cat cc.pid` cruisecontrol.sh

Installing Subversion on Ubuntu

There are many ways to do it, but this incantation worked for me on an Ubuntu host. This is an ‘entry level’ setup with one repository and simple authentication. Read the Subversion book and Ubuntu documentation to understand.

su -
apt-get install subversion
adduser --system --home /srv/svn --gecos "System account to run svnserve" svn
svnadmin create /srv/svn
chown -R svn:nogroup /srv/svn

apt-get install xinetd
cat >> /etc/xinetd.d/svn << "EOF"
service svn
{
        port                    = 3690
        socket_type             = stream
        protocol                = tcp
        wait                    = no
        user                    = svn
        server                  = /usr/bin/svnserve
        server_args             = -i -r /srv/svn
}
EOF
/etc/init.d/xinetd restart

# uncomment line to use default password file (~svn/conf/passwd)
vi ~svn/conf/svnserve.conf

cat >> ~svn/conf/passwd << "EOF"
[users]
fred = *****
...
EOF
chmod 600 ~svn/conf/passwd

Struts Guidelines

Struts (or more correctly, the Struts Action Framework) is probably the most successful Java web-application framework to date. It enables organization of Java web-applications using a model-view-controller (MVC) approach that makes it easier to write and maintain non-trivial applications.

The framework comprises

  • A front controller servlet (ActionServlet) that accepts, processes, and routes all incoming HTTP requests in accordance with a configuration file (struts-config.xml)

  • RequestProcessor and Action classes that can be extended and customized with application logic.

  • A set of JSP tag libraries (html, bean, logic, tiles) to simplify building forms and displaying output.

  • Support for populating HTML form input into regular or dynamic beans (DynaBeans).

  • Support for validating input and displaying error messages (ActionErrors, ApplicationResources.properties)

The version of Struts shipped with JDeveloper 10.1.2 was 1.1. A number of books have been written about this version, see the Apache Struts 1.1 Project Home Page. Using 1.2 should not be a significant problem, but it does not include compelling enhancements. Note Struts 1.1 includes Commons BeanUtils 1.6.

JSPs

  • Organize applications into pages, eg. CustomerSearch.jsp, CustomerView.jsp, CustomerEdit.jsp.

  • Follow the Oracle Browser Look And Feel (BLAF) guidelines for all corporate applications, see the Oracle Browser Look and Feel (BLAF) Guidelines. Use the blaf.css provided with JDeveloper, do not modify it.  Use the icons from the BLAF icon repository.

  • Place all JSPs into the WEB-INF directory, where they cannot be invoked directly. Provide a start.jsp in the public web root directory that forwards to a Struts action to start the application. Set start.jsp as the welcome file in web.xml.

  • Refrain from adding scriplets to JSPs as far as possible: place code in the corresponding Java class and use Struts :bean tags to display results in the JSP.

Action Classes

  • For each JSP create a corresponding Java class that extends DispatchAction and which handles requests from the JSP.

  • Use DynaActionForms to capture form input. These are configured in struts-config.xml, eliminating the need to write Java bean classes for each input form.

  • Validate all input on the server side. Although JavaScript can be used on the client for added responsiveness, client side validation can always be bypassed or disabled.

  • Do not place database access code into JSPs or Action classes: factor out this code into separate data access objects (DAOs). Configure data sources using the servlet container, not the (deprecated) struts-config.xml option. Name data sources after the username or schema used for the connection, not the target database instance.

Error Handling

  • Write error diagnostic and tracing information to the servlet context log, do not simply print a stack trace.  This may be done by extending struts.action.RequestProcessor.

  • Declare error pages in web.xml to handle unexpected server errors (500) and missing resources (404).  It may be convenient to comment these out in development environments.

  • Review Ambysoft’s Coding Standards for Java

  • At a minimum use an initial capital for classes and an initial lower case for variables. Use all caps only for constants, ie. where ‘static final’ is used.

  • Do not declare global variables: at a minimum use singleton beans. Global constants are OK.

References

Posts navigation

1 2 3 4 5 6
Scroll to top