Posts

Showing posts from July, 2012

Java Web Service Client - Proxy Configuration

Image
Over the past few days I’ve been integrating an application with the Experian bank account validation service. I’ve been using an Axis2 web service client to generate requests and call the service. My web service client worked fine in our office but when I deployed it on our customers sever (Tomcat running on Windows Server 2008) the client was unable to connect to the target URL.
The Axis client was throwing an UnknownHostException which meant that it wasn't able to resolve the service URL. Strangely though, on the same machine I was able to paste the same URL into a browser and view the service WSDL. After a little heading scratching I realised that all HTTP requests to public URLs had to be routed through our customers ‘bluecoat’ proxy server. I looked around and found a few different ways of doing this - I’ll document each approach and hopefully it’ll help out someone else.
Solution 1 - Set Proxy Details On Axis2 Web Service Stub Axis provides a convenient way for you to set prox…

Singleton Pattern

Image
The Singleton pattern allows you to take control of object creation by ensuring that only one instance of a class is instantiated. This can be useful when you want to restrict resource use, or you have a sensitive object whose data shouldn’t be accessed by multiple instances (a registery object for example). Imagine you have an object containing a large amount of reference data that you want to share across your application - you may want to ensure that you have only one instance of that object. Multiple instances of such a large object would unnecessarily increase the memory footprint of your application.
Typically objects are instantiated using the new operator - the following 3 lines of code will create 3 new ReferenceData objects. ReferenceData refData1 = new ReferenceData(); ReferenceData refData2 = new ReferenceData(); ReferenceData refData3 = new ReferenceData(); The Singleton pattern restricts the use of the new operator and ensures that only one instance of a cl…

Observer Pattern

Image
The observer pattern allows objects to communicate and exchange information using notifications. An observer object registers with and receives notification from a subject object. Any number of observers can register with a subject and when an event occurs a notification is sent to each of the registered observers. The observer pattern allows loose coupling between the object triggering the event and the objects that respond to the event. The diagrams below should help explain this a little better.





Creating the Subject interface We’ll start off by creating the Subject interface which should be implemented by any object that wants to send event notifications to other objects. The Subject interface is defined as follows. public interface Subject { public void registerObserver(Observer observer); public void unregisterObserver(Observer observer); public void notifyObservers(String event); } The 3 method signatures above are pretty intuitive - they provide a means of adding a …