Saturday, 7 April 2012

Dojo: mocking dependencies with DOH

This post demonstrates a way to use the Dojo 1.7 AMD loader to provide mock/stub/fake/dummy artefacts in place of the defined dependencies.

Wednesday, 4 April 2012

Dojo: version 1.7 and the AMD loader

Along with a few other JavaScript libraries, Dojo is making the transition to the Asynchronous Module Definition (AMD) API. This post presents a few minimal files written to make use of it.

Monday, 2 January 2012

JSF: managed beans without JSF dependencies

A previous post discussed how to inject the FacesContext into managed beans using a broker. This post demonstrates how to build on that approach with greater levels of abstraction.

It is generally possible to remove direct JSF dependencies from managed bean code. You might want to do this to reduce coupling, improve cohesion or in the interests of writing testable code.

The code was written against Java 6, JSF 2 and JUnit 4 but the approach could be adapted to earlier versions of all of these.

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.

Friday, 24 December 2010

JavaScript: validating UTF-8 string lengths in the browser

Let's take a JavaScript string: "€100". This is going to be sent from a browser input box and stored in a web server's database. The database is using the UTF-8 encoding and the constraint on the column is CHAR(4). Spot the problem?

Sunday, 19 December 2010

JSP: what all the encoding declarations mean

When you see a JSP document, you might wonder why it specifies the UTF-8 encoding three or four times. This is a post about what those declarations mean.

Sunday, 21 November 2010

Comments policy

Comments are moderated and will not appear until I approve them.

  • I don't live on the blog, so it may take me some time to see and respond to your comment.
  • I won't publish comments with e-mail addresses in them.
  • If you post a question and I don't respond, I just may not know the answer off the top of my head and may not feel like putting in the research to answer it. You'll have more luck on a dedicated Q&A site like stackoverflow.com.
  • Comments that say little more than "Thanks!" are appreciated, but don't add much value for other readers. Don't expect them to show up.
  • Spam gets deleted.

Corrections and constructive criticism are welcome.

Sunday, 19 September 2010

Java: System.console(), IDEs and testing

The method System.console() can return null if there is no console device present. This comes as a surprise to people when they run their code in an IDE. This post is about overcoming such problems.

Thursday, 16 September 2010

Java: "Content is not allowed in prolog" - causes of this XML processing error

Content is not allowed in prolog is an error generally emitted by the Java XML parsers when data is encountered before the <?xml... declaration. You may inspect the document in a text editor and think nothing is wrong, but you need to go down to the byte level to understand the problem. You probably have a character encoding bug.

Sunday, 1 August 2010

Java: a fluent I/O API (4/4)

This is the fourth post about my experiments with a fluent I/O API. This post covers conclusions and limitations of the implementation. You can find downloads and source repository details further down the page.

Java: a fluent I/O API (3/4)

This is the third post about my experiments with a fluent I/O API. This post covers how the API enhances exception handling.

Java: a fluent I/O API (2/4)

This is the second post about my experiments with a fluent I/O API. This post covers how to extend the API.

Java: a fluent I/O API (1/4)

I've been experimenting with fluent API design. You can find the sources in part 4.

I've often been frustrated with the verbosity of Java I/O. Handling close with decorators got better with the introduction of the Closeable interface, but there's still a bit of boilerplate. This post describes a new fluent API to wrapper around the existing I/O API.

Saturday, 17 April 2010

I18N: comparing character encoding in C, C#, Java, Python and Ruby

Don't assume that the character handling conventions you've learnt in one language/platform will automatically apply in others. I've selected a cross-section of popular languages to contrast the different ways character encoding is handled.

Tuesday, 12 January 2010

Scala: implementing a "did you mean..?" spelling corrector

I was looking at Scala again and decided to implement Peter Norvig's algorithm for suggesting spelling correction suggestions. I suggest you go read How to Write a Spelling Corrector for the clever stuff.

This implementation is limited to the English alphabet. You'll need the big.txt file or a similar set of training data.

Thursday, 17 December 2009

Java: safe character handling and URL building

This post discusses HTTP URLs in Java and how to avoid data loss due to encoding/escaping issues. Special mention is made of the query part, since it is frequently used to store data.