Sheila's Blog

Software Development

Sheila's Blog header image 4

Spring versus Seam

April 19th, 2009 by Sheila
Respond

I used Spring a few years ago and was really impressed with it as a framework.  I found that for less experienced developers it enforced a lot of good programming practises.  Unfortunately in the last couple of years I haven’t worked in companies that were using it.  In my current comany, the decision was made to opt for Seam instead of Spring.  Primarily, I think, on the basis that it was newer, and therefore ‘better’.  The jury is still out for me on which is better, or whether you should use both.  I’m starting to get more comfortable with Seam now.  Especially with the concept of conversations and how to use them.  But it can be quite difficult to figure out which of the many different ways of using the framework is the most optimal once you veer away from code that copies the provided examples closely.  I still find myself constantly skilling up on Seam to try and stay on top of the architectural decisions that need to be made as we continue coding.  While it’s a good framework, you really need to understand what you’re doing to use it effectively.

On the other hand, Spring has progressed quite far since I last used it.  There seem to be far more companies using it than Seam.  It’s hard to know if this is just because it has had a head start on Seam or not.  Not having used the newer Spring features I find it hard to compare and contrast against Seam.  With a busy schedule in work, it’s difficult to find enough time to get to the point where my knowledge of both frameworks is equal.  In an attempt to rectify that, I’m sitting the SPR-001: Core Spring course from Springsource next week in Edinburgh.  I’m looking forward to getting back up to speed with Spring and seeing how the most recent version compares to Seam.

Tags:   No Comments.

Scrum – The Scrum Team

April 17th, 2009 by Sheila
Respond

Scrum requires a team of people rather than a group of individuals. A team has a common goal and set of standards. They will collaborate and support each other to achieve that goal. The team size is usually 4-9. Ideally the team members are full-time and co-located to help communication.

The team should be cross-functional, including whatever skills are needed to achieve the goal. Each person should ideally be a generalist rather than a specialist. Rather than creating bottlenecks where tasks can only be done by a limited number of resources, knowledge should be shared among other team members. The hierarchy is flat – each member must participate and commit to what will be delivered. The team as a whole succeeds or fails.

Tuckman phases:
Bruck Tuckman described a model of group development in 1965. The model has 4 phases, all of which are necessary for a team to grow and deliver reults.

Forming – a new team meets, gets to know each other and agrees on goals.
Storming – the team addresses issues including how the team will function and what standards will be applied. Some teams never progress past this stage.
Norming – the team adjusts to working together, motivation and productivity increases.
Performing – the team is functioning effectively as a group with little conflict or guidance.

Obviously the goal in scrum is to bring the team all the way through to the performing stage.  Unfortunately it only takes a small change like replacing a team member to potentially bring the team back to the forming stage again.

Tags:   No Comments.

Software Development – choosing a software methodology

April 14th, 2009 by Sheila
Respond

There are a lot of methods for developing software out there now.  Choosing the best one for your company or team can be difficult – and that’s before you start adapting it to suit your particular situation.  Here’s a brief history and overview of some of the more common ones you’ll come across.  Each of them have good elements that you can make use of or learn from.

In the beginning, there was Waterfall…
Not that long ago, almost all IT companies based their software development on what was known as the waterfall cycle.  To deliver a project you moved through phases in order.  Requirements Specification, Design, Construction, Integration, Testing, Installation and finally Maintenance.  This style of development works well where the requirements are very clear and not going to change, but that rarely happens in practice.  For dealing with a typical software project, the method is rigid and closed.  The software to be delivered has to be fully described in detail months or years in advance of delivery.  The cycles are long with low visibility of what’s being done.  It’s hard to find out if deadlines will be met until the dates have already gone past.  Despite the abundance of planning and documentation, the customer may be unhappy with the delivered product or it no longer matches what the customer actually needs.  This can be a costly and restrictive way of developing software which can lead to people to shifting blame onto others as the final deadline approaches if things are going poorly.

In more recent years there has been a move away from the traditional style of developing software to address some of the issues mentioned above and allow for projects where the requirements aren’t fully known at the start.  Many of these are incremental and/or iterative.  Incremental development is when the work is divded into parts (or increments) which are integrated when they’re completed.  At the end of each phase there is a fully completed unit of work or increment.  Iterative development uses multiple iterations to progress to a final solution.  The important distinction is that each iteration can include refactoring or expanding on a piece of work – rather than fully completing a unit of work at a time.  The first iteration may provide a basic piece of functionality and later iterations will develop it further until it grows into the final product.

The Unified Process…
The Unified Process (and also the Rational Unified Process) is an iterative framework.  Each time-boxed iteration provides an increment of work which is the input for the next iteration.  It’s still quite similar to waterfall.  The architect/designer is a vital role as each iteration is driven by UML use cases.  Roles and responsibilities are very clearly defined with each level in the organisation delivering particular artifacts to the next.  The Unified Process gives better observability than the waterfall method, but using tools like Rational Rose add overhead and the process creates big divisions between design and development.  At each point where an artifact is handed over, responsibility is also effectively handed over which is not necessarily a good thing.

Enter Agile…
Agile is a group of software development methodologies with the agile principles at the core of each.  The Agile Manifesto is a statement of these principles.  The four main principles are:
Individuals and interactions over processes and tools
Working software over comprehensive documentation
Customer collaboration over contract negotiation
Responding to change over following a plan
You can view the full Agile Manifesto and history here.  Three of the Agile methodologies are XP, Scrum and Lean Software Development which we will take a quick look at.

XP / Extreme Programming…

XP replaces use cases with user stories.  These are less formal and usually less detailed than use cases as there’s more interaction between the developers and the person giving the requirements.  Instead of handing the requirements over at the start of the project, regular feedback is an important ingredient.  XP aims to have fast iterations with frequent planning and estimating.  Rather than using layering, software is built in slices so that feedback can be given early on.  Teams provide regular increments of software that could be delivered to the client using test-first approaches, continuous integration and regular customer feedback.  This allows for changing requirements as the project progresses.

Eliminating Waste with Lean…
Another Agile method is Lean Software Development which takes its inspiration from methods used in the manufacturing industry.  Waste is reduced or eliminated by removing anything that doesn’t contribute to the overall goal.  Decisions are deferred until as late as possible or until there’s no advantage to holding off.  This means decisions don’t have to be made at the very start of the project, but can be made when more information is available.  Teams try to eliminate time spent waiting (for another developer or a 3rd party to deliver something, or for more detailed requirements) and to deliver only what’s required as fast as possible.  More communication is encouraged and documentation is produced on-demand.  Teams are encouraged to see the bigger picture rather than focusing only on the slice of work they are doing.

Scrum…
Scrum progresses on from XP, but takes a wider viewpoint including focusing on how an agile team can function well within a large organisation.  Scrum was developed independently, but at a similar time as Lean and they have similar goals.   Many teams using the scrum practices also use XP and Lean practices.  Each team includes a Product Owner and Scrum Master.  Teams are small with 5-7 members and cross-functional.  The team as a whole commits to delivering functionality.  The Product Owner decides what functionality they want, and what order they would like it in and the team will decide what it can commit to in each iteration (called a sprint).  The scrum master is there to ensure the process is followed and assist the team in meeting their goals. Communication is a key factor here with daily meetings to keep all the team members in synch and share knowledge.

SOA – the latest buzzword…
Moving on from the Agile methods, one of the things you will commonly hear about now is Service Oriented Architecture.  SOA started in the larger companies – ones that may have merged with other companies on a regular basis, inheriting legacy systems and duplicating functionality as they went along.  As the complexity of working with completely different software systems increases, so does the cost.  SOA is a stategy for managing this complexity.  It can be used to reduce dependencies on 3rd party vendors and help ‘clean up’ the systems.  By reducing coupling between systems you gain the ability to swap out a component and replace it with an improved one.

It’s common to associate SOA with adding a web services layer over different systems but SOA should be seen more as a long-term strategy.  To reduce language coupling you can use XML, to reduce protocol coupling you can use web services.  Network coupling can be reduced using ESB and component coupling is reduced by making components replaceable.  The primary goal is to bring back simplicity.  Not everything should be a service and reuse of components isn’t always a good thing.  If communication is costly then the overhead of communicating that a service is available may be higher than if the component wasn’t reused.

General Strategies…
Agile methods tend to promote a low tech approach that avoids putting distance between the team and the state of the project.  In an ideal situation, an agile team is located together and communication is easier.  The client or product owner is heavily involved in refining requirements and providing feedback.  MS Project and Gantt charts aren’t used and updates are made directly by the people doing the work. Documentation goes out of date fast, so instead of documenting everything extensively, teams are kept aware of each others activities.  Documentation can be as simple as a photo of a whiteboard instead of using software tools.  Teams avoid making vague long-term predictions by assessing the risk of something happening, and then making it observable so changes can be made when they’re actually needed, rather than catering for something that never actually happens.

All of the methods above can work really well, or fail spectacularly.  Regardless of what method a company uses for developing software, the one thing that applies across the board is that there’s always room for improvement. And even a good development process can’t manage teams of individuals well for you.  For that you have to rely on having at least one good team lead – whatever process they follow or job title they hold.

Tags:   · · · · 2 Comments

Accessing remote Alfresco web services

April 8th, 2009 by Sheila
Respond

You can check that the alfresco webservices are accessible on a remote machine by accessing the url http://hostname:8080/alfresco/api.  You should get the following message. Axis HTTP Servlet Hi, you have reached the AXIS HTTP Servlet. Normally you would be hitting this URL with a SOAP client rather than a browser. In case you are interested, my AXIS transport name appears to be 'http'

To access a remote web service instead of a local one in your code you need to add a file called webserviceclient.properties to the classpath

webserviceclient.properties

If you're accessing the web service from your own web application then you need to place webserviceclient.properties in WEB-INF/classes/alfresco/webserviceclient.properties for it to be picked up properly.

Tags:   · No Comments.

Using Chainsaw to tail your JBoss server log

April 7th, 2009 by Sheila
Respond

Log4j is a logging library from Apache.  It consists of loggers (log events) and appenders (a destination for a log message).  There’s always a rootLogger defined, plus however many other loggers you require.  A logger can have several appenders attached to it which can format and write the message to the console or a file etc.  The logging levels are TRACE, DEBUG, INFO, WARN, ERROR and FATAL.

A default JBoss installation uses log4j for logging.  The log4j settings are configured in JBOSS_HOME\server\default\conf\jboss-log4j.xml which sends output to both the console and JBOSS_HOME\server\default\log\server.log

Chainsaw is a GUI tool for parsing and analysing log files generated by log4j.  It allows you to read and filter events.  It can be used to tail the server.log file allowing you to filter the messages you see rather than searching through the log file in an editor.

You can download Chainsaw from here.

Download the chainsawWebStart.jnlp file and open it up to start the Chainsaw Log viewer.

Tailing a Log file
Create a file somewhere on your system to hold configuration information for chainsaw.

chainsaw-config.xml <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true"> <plugin name="jboss" class="org.apache.log4j.varia.LogFilePatternReceiver"> <param name="fileURL" value="file:///c:/Applications/jboss-4.2.2.GA/server/default/log/server.log" /> <param name="timestampFormat" value="yyyy-MM-dd HH:mm:ss,SSS"/> <param name="logFormat" value="TIMESTAMP LEVEL [LOGGER] MESSAGE"/> <param name="name" value="alpha-jboss" /> <param name="tailing" value="true" /> </plugin> <root> <level value="debug"/> <root> </log4j:configuration>

Edit the filename to match where the jboss server.log is on your system.

Select the ‘view-show application wide preferences’ menu.

In the automatic configuration url field, enter the URL to your config file.
Select OK and restart Chainsaw.

You'll see the file load up ina new tab 'file/c:Applications/jboss-4.2.2.GA/server/default/log/server.log.

There's a dropdown menu that lets you filter the log entries from the most verbose TRACE up to FATAL errors only.

Chainsaw basics:
The toolbar icons at the top let you pause the logging, configure what gets displayed and clear the screen of events among other things.  The first thing to get accustomed to is drilling through the log events to see the information you're interested in.  In the left pane you can move through the logging tree to select a particular logger.  Any messages from a Logger matching the one selected are highlighted in black.  You can then right click on the selected logger in the tree and choose either 'Focus on' to filter to just those events or 'Ignore' to exclude them.  Selecting a specific event gives you more detailed information in the lower pane.

Tags:   · · · No Comments.

Alfresco – Create User

April 6th, 2009 by Sheila
Respond

Creating a new alfresco user using a web service call requires the following jar files in your classpath: alfresco-web-service-client.jar axis-1.4.jar commons-discovery-0.4.jar commons-logging-1.1.jar jaxrpc.jar opensaml-1.1.jar wsdl4j-1.6.2.jar wss4j.jar xmlsec-1.4.1.jar

Create a java class called AlfrescoCreateUser with a main method public static void main(String[] args) throws Exception { AlfrescoCreateUser alfTest = new AlfrescoCreateUser(); alfTest.createUser(); }

Copy the createPersonProperties method from the AdministrationServiceSystemTest in the web service client code /** * Taken from AdministrationServiceSystemTest in the web service client. */ private NamedValue[] createPersonProperties(String homeFolder, String firstName, String middleName, String lastName, String email, String orgId) { // Create the new user objects return new NamedValue[] { new NamedValue(Constants.PROP_USER_HOMEFOLDER, false, homeFolder, null), new NamedValue(Constants.PROP_USER_FIRSTNAME, false, firstName, null), new NamedValue(Constants.PROP_USER_MIDDLENAME, false, middleName, null), new NamedValue(Constants.PROP_USER_LASTNAME, false, lastName, null), new NamedValue(Constants.PROP_USER_EMAIL, false, email, null), new NamedValue(Constants.PROP_USER_ORGID, false, orgId, null)}; }

You need to set the user properties and get an authentication token using the admin access details. The code below creates a user called test with a home space also called test under Company Home -> User Homes /** * Creates the user test with a home space in Company Home. */ public void createUser() { String login = "test"; String password = "password"; String homeFolder = "://app:company_home/cm:" + login; String userName = "test"; String userMiddlename = ""; String userSurname = "Test"; String userEmail = "test"; String userOrg = ""; try { AuthenticationUtils.startSession("admin", "admin"); AdministrationServiceSoapBindingStub administrationService = WebServiceFactory.getAdministrationService(); NewUserDetails newUser = new NewUserDetails(login, password, createPersonProperties(homeFolder, userName, userMiddlename, userSurname, userEmail, userOrg)); administrationService.createUsers(new NewUserDetails[] { newUser }); } catch (AuthenticationFault f) { System.out.println("Administration Fault"); f.printStackTrace(); } catch (RemoteException e) { System.out.println("RemoteException"); e.printStackTrace(); } finally { AuthenticationUtils.endSession();> } System.out.println("User created successfully"); }

Run the class and check that the user has been created successfully.

Tags:   · No Comments.

Debugging Seam applications

April 3rd, 2009 by Sheila
Respond

Seam provides two different pages that can be useful for debugging applications.  The Facelets Debug page which shows page-rendering errors, and the Seam Debug page which shows any uncaught application exceptions.

Enable the Facelets Debug Page:
In web.xml you set Facelets to development mode.
WEB-INF/web.xml <context-param> <param-name>facelets.DEVELOPMENT</param-name> <param-value>true</param-value> </context-param>

The Facelets debug page gives you the line number in the .xhtml page where the error occured and access to the JSF component tree.

You can access the facelets debug page at any point by setting a hot key for that page.  To launch a debug popup on a page using CTRL-SHIFT-D, add <ui:debug hotkey=”d”/> in the page.

Enable the Seam Debug Page:
You need to add Facelets and Seam UI Support, then enable debugging in components.xml

WEB-INF/components.xml <core:init jndi-pattern="example/#{ejbName}/local" debug=true/>where example is the name of the application.

You can always access the seam debug page by going to the /debug.seam page in your browser.

Tags:   · No Comments.

Adding Facelets and Seam UI to your application

April 2nd, 2009 by Sheila
Respond

It’s generally recommended in seam applications that Facelets be used instead of JSP.  JSP pages are processed by the JSP container at the same time as they’re processed by the JSF engine which can cause conflicts.  Performance is also improved when the JSP engine isn’t used.  Facelets is a templating framework that also gives access to XHTML tags and extra debugging support.

It’s also recommended that you add seam’s UI tags which allow the use of Hibernate’s validator annotations and provide conversation and business process management along with other extra tags.

To enable these you need to edit your configuration files and add some jar files.

Add required jar files:
WEB-INF/lib: jsf-facelets.jar jboss-seam-ui.jar jboss-seam-debug.jar

Add el-api.jar and el-ri.jar to the ear file so they can be used by both your war and jar files.  Make an entry in the application.xml file to make the jars available on the ear classpath.

META-INF/application.xml <module> <java>el-api.jar</java> </module> <module> <java>el-ri.jar</java> </module>

Add a View Handler:
The view handler renders html pages from facelets pages and templates.

WEB-INF/faces-config.xml <application> <view-handler>org.jboss.seam.ui.facelets.SeamFaceletViewHandler</view-handler> </application>

Update the web.xml so that the facelets suffix .xhtml will be used for web pages.

WEB-INF/web.xml <context-param> <param-name>javax.faces.DEFAULT_SUFFIX</param-name> <param-value>.xhtml</param-value> </context-param>

Add the Filter and Resource Servlet:
The SeamFilter supports JSF redirects, error pages and file uploads.  The resource servlet gives access to images and css files in jboss-seam-ui.jar and gives direct access to seam components from javascript.  You add these to your web.xml.

WEB-INF/web.xml <servlet> <servlet-name>Seam Resource Servlet</servlet-name> <servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>Seam Resource Servlet</servlet-name> <url-pattern>/seam/resource/*</url-pattern> </servlet-mapping> <filter> <filter-name>Seam Filter</filter-name> <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class> </filter> <filter-mapping> <filter-name>Seam Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>

You can now use .xhtml pages in your application and make use of the seam ui tags.

Tags:   · No Comments.

Alfresco errors

April 1st, 2009 by Sheila
Respond

Index Errors or The store ‘avm://sitestore’ has a duplicate root node entry:

Whoops, you’ve inadvertently done something Very Bad to your Alfresco install and the application throws a fit about the indexes when you try to start it up.  There’s a problem with the database data and the lucene indexes being out of synch.

To solve this error you need to rebuild the lucene indexes.  To do this:
1.  Stop Alfresco.
2.  Delete everything under /alf_data/lucene-indexes
3.  Edit C:/Alfresco/tomcat/shared/classes/alfresco/extension/custom-repository.properties or
alfresco.war/WEB-INF/classes/alfresco/extension/customer-repository.properties to set the property index mode to AUTO instead of validate
4. Start Alfresco again.

customer-repository.properties:
Now instead of validating the indexes and failing, the indexes will be rebuilt if a problem is found.

java.lang.UnsatisfiedLinkError: no Win32NetBIOS in java.library.path:

You need to add the folder containing the Win32NetBIOS.dll and Win32Utils.dll to the java.library.path of your application server.  For JBoss make an entry in run.bat

The server should now be able to find the files.

Tags:   1 Comment

Loading a properties file in a java web app

March 31st, 2009 by Sheila
Respond

You’ll often want to configure parameters in a properties file and read this into a class.

config.properties: value.a=orange value.b=apple

If you’re simply loading a file in a java program you can use: Properties props = new Properties(); props.load(new FileInputStream("config.properties")); String value = props.getProperty("value.a");

But when loading a property file in a web application you should package the file in your deployed archive and load the file from the classpath.  This avoids problems with loading files from different locations on a file system.

build.xml: gen-jar-files target <copy todir="${jar.dir}"> <fileset dir="${resources.dir}"> <include name="*.properties" /> </fileset> </copy>

This takes any properties files in the resources.dir and copies them into the jar file.  Now you can access the file within your application from the classpath: ClassLoader cl = this.getClass().getClassLoader(); InputStream is = cl.getResourceAsStream("config.properties"); Properties configProperties  = new Properties(); try { configProperties.load(is); String valueA = configProperties.getProperty("value.a"); } catch (IOException e) { e.printStackTrace(); }

Tags:   · No Comments.