Tuesday, 27 December 2011

JSF: mocking FacesContext for unit tests

Referencing the FacesContext directly in Java classes makes managed beans more difficult to unit test. This post discusses how to mock the context for testing outside the application container.

These examples use Mockito with JUnit. Familiarity with JSF and unit testing Java is assumed.

I've used the javax.faces.bean annotations but the techniques apply for other bean management mechanisms (e.g. using faces-config.xml or Spring).

Sunday, 27 November 2011

JSP: arbitrary attributes on JSF controls

One criticism developers have of JavaServer Faces is that it is not possible to add arbitrary attributes to the resultant markup. Problems arise when they wish to add custom attributes specific to JavaScript frameworks (e.g. dojoType for the Dojo toolkit) or HTML 5 attributes (such as data- or placeholder.)

However, this is not a technical limitation of the JSF framework; only a limitation of the standard control library.

Thursday, 27 October 2011

WebSphere AS: RAD vs WSDL2Java for JAX-RPC client SOAP bindings

I've been doing a bit of work recently with JAX-RPC on WebSphere Application Server 6.1. This is hardly cutting edge software (WAS 8 is out; JAX-RPC has been superceded by JAX-WS) but platforms can have a long shelf-life in the enterprise.

This post describes how to migrate from client bindings developed using RAD to automated generation via Ant. JAX-RPC isn't restricted to consuming SOAP in WARs, but this post confines itself to that topic.

For convencience, the sample code reuses the MaintainAddress.wsdl from a previous post.

Saturday, 23 April 2011

Java: JAX-WS web services and clients

JAX-WS is built into Java 6. This makes it a low-dependency choice for writing SOAP-based web service code. This post covers the basics of JAX-WS development with a sample web service.

An understanding of the following is beneficial: Servlets; XML Schema Definition (XSD); Web Services Description Langauge (WSDL); XPath; JAXB.

Server code was tested on Glassfish 3; client code was tested on Java 6.

The code here describes a contract-first web service; it is possible to do this the other way round, starting with Java code and generating descriptors from it.

Saturday, 22 January 2011

TAM WebSEAL: authentication and the iPad

After upgrading the iPads to a new version, we started seeing a logon issue with servers protected by TAM WebSEAL. After successfully authenticating, users were redirected to the resource apple-touch-icon.png which resulted in a 404 "Not Found" error.