Feeds:
Posts
Comments

Recently I stumbled upon a particular Spring project  called Spring Loaded .The ReadMe section did catch my attention because it boosts developer productivity by reloading class files as and when they change.

There have been quite a few projects which provide such benefits and I believe the most popular commercial choice is JRebel. Those guys have done a great job in turning  one of the greatest JAVA Web developers pain into a line of business.  However there have been alternatives but none so simple as JRebel

Fortunately Spring Loaded was quite simple to use and configure. Its just a single jar. However, I am quite sure it is not a sophisticated as  other commercial options. But its getting there and is currently being used in Grails 2.

ReLoading in Action

The most reliable  way to show automatic reloading in action is by capturing a video. Unfortunately you guys will just have to trust me.

Start off by downloading the jar and including in your normal java project.

Create a POJO “Person”


public class Person {
	
	
	
	public  void printBody()
	{

		System.out.println("*********");
		this.hands();
//		this.gloves();
		System.out.println("Body");
		this.legs();
//		this.shoes();
		System.out.println("*********");
	}
	
	private  void hands()
	{
		System.out.println("Hands");
	}
	
	private  void gloves()
	{
		System.out.println("Gloves");
	}		
	
	private  void legs()
	{
		System.out.println("Legs");
	}	
	
	private  void shoes()
	{
		System.out.println("Shoes");
	}	

}

Now create a class to run the POJO

public class LiveEcho {

	
	public static void main(String[] args) throws Exception {
		
		while(true)
		{
			Thread.sleep(5000);
			new Person().printBody();

		}
		
	}
}

When you run the LiveEcho class you will see statements in the console like below.

*********
Hands
Body
Legs
*********
*********
Hands
Body
Legs
*********
*********
Hands
Body
Legs
*********

Nothing amazing. While the application is running, try uncommenting out “this.gloves()” or “this.shoes()”. Still nothing amazing.

In order to let Spring Loaded to be aware of the changes, we need to pass “-javaagent:springloaded-1.1.5.RELEASE.jar” as a java argument. I have done it here from my eclipse option

SprngLoadedConfig

SprngLoadedConfig

Run the LiveEcho class again. This time while the class is running, try uncommenting out “this.gloves()” or “this.shoes()”. You will see the output on the console changing

*********
Hands
Body
Legs
*********
*********
Hands
Body
Legs
*********
*********
Hands
Body
Legs
*********
*********
Hands
Gloves
Body
Legs
*********
*********
Hands
Gloves
Body
Legs
*********
*********
Hands
Gloves
Body
Legs
Shoes
*********
*********
Hands
Gloves
Body
Legs
Shoes
*********

As you can see, Spring Loaded has noticed the changes in the Person class files and reloaded the changes without re-starting the JVM.

Further reading

There are different ways of checking whether the classes have re-loaded or what are the changes that have taken place.

Q. How do I know when a reload has occurred so I can clear my state? A. You can write a plugin that is called when reloads occur and you can then take the appropriate action. Create an implementation of ReloadEventProcessorPlugin and then register it via SpringLoadedPreProcessor.registerGlobalPlugin(plugin). (There are other ways to register plugins, which will hopefully get some documentation!)

I have not tried it out on complex web project and their likes, but I am sure they are getting there.

Mobile Platform trends…

Mobile development has been evolving drastically in the past few years. It started with native development , where you needed to code for every platform such as iOS, Android, Windows, etc. With the increased number of devices and operating systems and the need for speed to market, technology vendors started to provide:

Mobile Application Development Platform (MADP) which can be used to build and package (used before production). These platforms reduce the maintenance overhead of developing natively for every operating system. It enables developer to write the code once and package it for different operating systems.

But soon mobile development required more features such as analytics to know the usage of the application, push notification, offline synchronization for cases when internet is not available on the device due to the person entering elevator for example.  Mobile devices have limited resources in term of  processing, storage, bandwidth, thus it requires lightweight mechanisms to connect to backend services.

Technology vendors, yet again, brought in a new concept to cope up with the continuous demands and features. Mobile Backend as a Service (Mbaas) which is used to connect to backend as well as mobile specific features such as offline sync, analytics, push notification. All reused services can be defined and published through MBaas (used after production)

Some vendor providers have combined both MADP and Mbaas into their offerings while others provide these two separately.

 

Mbaas is to a great extend overlapping with another technology which is the Enterprise Service Bus (ESB). ESB is used to integrate with multiple backend services.

 

So how can we decide on what to use?

What does our organization need? MADP, Mbaas, or ESB?

 

Recommended approach

 

Mobile Platforms

Mobile Platforms

I would recommend the below approach starting from bottom up:

  • Backend service: Existing services provided internally or externally which could be published through web services, databases, etc.
  • Integration Layer: This layer will connect backend services together thus it needs to support multiple adaptors to connect to these services. Moreover, it may transform some of the protocols and payload if required for the service integration. It will also orchestrate between these service to provide simpler services i.e. using information accessible by different services rather than requesting the information from the end user. This layer can be used if you already have an ESB or a need for the ESB within your organization.
  • Mobile Integration Layer: This layer is a highly optimized layer for the mobile or any future device. It publishes the service provided through the Integration Layer in a very lightweight manner as mobile devices have limited capabilities in term of processing power, bandwidth, etc.. Moreover, it provides mobile specific features such as offline sync, analytics, push notification. This layer needs to integrate with different development approach i.e. native, hybrid, etc.
  • Development Layer: This layer is used to develop and package mobile development. It can be provided as an add value for any organization who would like to start or shift their mobile development. It can integrate with the Mobile Integration Layer and use any of its facilities.

The advantages of using such an approach are:

  • Segregation of responsibilities between integration platform, mobile backend and development platform which enables you to use the power of every platform
  • Decoupling of the layers which will enable you to be less vendor lock and ease the replacement technology of any of these layers
  • Be able to support multiple development platforms and languages such as JavaScript, .Net, native, etc. This will resolve any the technical skill constraint.
  • MBaas technology can integrate with any other technology i.e. development and integration

Conclusion:

Don’t fall for vendor jargon and technology hype. Carefully measure and evaluate which piece of technology fits into your bigger picture puzzle.

 

This is the first time I am attending the Microsoft TECH.ED and I was really excited to know what was in stall for us. Like any company organized event (e.g.: IBM Smart SOA), it was more of a sales pitch of Microsoft’s Cloud platform – AZURE (its pronounced somewhat like ASSURE)

The Keynote was given by Mr. S. Somasegar and there were some interesting points that I could pick up, like ODATA. It is a new open data specification proposed and actively supported by Microsoft. It is completely based on REST. I also had the privilege to see a live demo on easily integrating a Windows 7 app with eBAY website (which exposed their data in the form of ODATA).A very good initiative but will have to wait and see how many vendors would easy support ODATA

An interesting announcement was that Kinect SDK will be available soon in Spring. That would be a very interesting thing to watch out for. As soon as the SDK is made available a proliferation of possibilities are going to hit the shores. The possibilities are endless and it would be the right time to think of how to leverage this technology in the business space and very likely in the medical and educational space. Kudos to Microsoft guys to bring out the Kinect SDK.

Also there were talks about Visual Studio 2010 SP1 on what all enhancements and feature packs have been in place. Mr. S Somasegar claimed that the VS 2010 SP1 will be available to download on March 8th, if you are a MSDN subscriber. If not hard luck NON-MSDN guys, you can only download it on March 10th. Oh my goodness that is really going to pain…..Seriously.

VS 2010 Load Testing feature pack has increased it virtual user limit from 250 to infinity. Good, but can you really spawn 250 virtual users from your developer machines? (Just a thought)

If that was not enough, enter VS 2010 Light Switch (Its still beta, hope it stays the same). The feature pack facilitates a developer to build applications in a jiffy and gives him the power to deploy the application on the desktop or browser, with the data-screen motto in mind.

This is what Jason Gander has to say about Light Switch: “At their core, most end user business applications combine two things:  data + screens.  LightSwitch is optimized around making these two things very simple.”

Come on MS guys, we are professional developers building serious enterprise applications. You really thing business applications are just screens and data. The real value of LightSwitch can be for hobbyist and kids to play around with technology and build prototypes, POCs etc, but building business applications, you got to be kidding me. If you don’t believe me, check out the comments by some users here (http://blogs.msdn.com/b/jasonz/archive/2010/08/03/introducing-microsoft-visual-studio-lightswitch.aspx)

 

Following the keynote were, 1 hour sessions by different speakers. You had to choose the session based on your preference of technology (which I figured out only on the second day)

Fascinated by the name of the session, “Enterprise Strategy & Architecture Overview”, I had to leave Mr. Parimal Deshpande in 10 minutes although the room occupancy rate was pretty high. Not sure why, probably the strange taste of Star Bucks coffee in my mouth.

Next, I entered “Stepping Outside the Browser with Microsoft Silverlight 4”. The presentation was given by Mr. Daron Yondem. It was interesting with some of the new features supported by Silverlight when it runs outside the browser. Also elaborated with a demo as to how you could get the snapshot of a website and show it inside a Web Browser component. Quite a few quirky samples were also demonstrated which kept the audience attentive. Overall, was moderately worth listening too.

Next session was really jaw dropping and mostly mouth watering. I had been eagerly looking forward to it: “Lunch Break”. The food was good and thankfully less on variety. Sure helped me choose easily. I totally forgot about the dessert till I stepped out.

Evening session started with “Citrix & Microsoft Virtualized and Optimized Desktops” given by Mr. Yannick Kunegel. The talk was really interesting and the occupancy was really high probably packing the room. Desktop virtualization seems to be a good option on tremendously cutting down on you Operation Costs. However, the Capex can be significantly higher as rightly questioned by a member of the audience. Fortunately, I did sit through the whole session.

Next session was “Using Cloud to Engage across a Diversity of Devices” by Mr. Marc Mercuri. Came to know about a couple of websites/frameworks such as TOWNHALL probably deployed on Windows Azure. Plan to check out the code base as it seems to be open source. By the way Mr. Marc , I seriously believe you need to bring down your pace a bit.

Finally “A Dive into Internet Explorer 9 for Designer & Developers” by Ms. Asli Bilgin. The speaker kept claiming about the new tags that had been supported by IE 9. However these were mostly HTML 5 tags which have been long over due. Thanks a lot MS guys for supporting them quite quickly. A very interesting project MOSAIC 23/25 http://www.jumpman23mosaic.com was also shown. I would advice all to go check it out and it sure uses the power of Azure to do queries.

Disclaimer: I have been mostly working on JAVA technologies for quite sometime. However am not new to Microsoft technologies.

 
Recently I was in need to tune some of the java services which I had implemented for for an iPhone project. When integrating services with mobile and hand held devices, it is very important that the services respond in a matter of seconds. In order to tune the services and get the best UI experience, the obvious step is to find the slowest service. However the intriguing question was ….HOW?

Following are some of the alternates most developers do

  • Have a System.out / Log.debug after you enter and before you exit the service, which prints the time
  • Write and aspect using AOP and log the time before and after invocation of the method

 

Serious developers choose the second approach, since monitoring is a cross cutting concern.

Before you fire up you IDE and start writing an Aspect and all those AOP jargon, I would like to introduce you to a class from the Spring Framework core portfolio called “JamonPerformanceMonitorInterceptor”. As the name suggests, it is an AOP interceptor that hooks into the framework called JAMon. JAMon is a java monitoring framework and it sure is sweet.

To know more about JAMon check it out HERE. Make sure you download the jamon-2.7.jar file and put it on your classpath

That’s right, no writing of interceptors and joint points and what not AOP jargon out there.

All you need to to do is instantiate a JamonPerformanceMonitorInterceptor bean and tell it which all Spring beans to intercept

Add this to instantiate the bean

<bean id="jamonPerformanceMonitorInterceptor" class="org.springframework.aop.interceptor.JamonPerformanceMonitorInterceptor" >
   <property name="trackAllInvocations" value="true"></property>
   <property name="useDynamicLogger" value="true"></property>
</bean>

Next create a “BeanNameAutoProxyCreator” and hook in the interceptor.

<bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
	<property name="interceptorNames">
		<list>
			<idref bean="jamonPerformanceMonitorInterceptor"/>
		</list>
	</property>
	<property name="beanNames">
		<list>
			<value>aRegularSpringBean</value>
			<value>statisticsDao</value>
			<value>statisticsService</value>
			<value>paymentDao</value>	
			<value>paymentService</value>				
		</list>
	</property>
</bean>

All you need to do now is, tell the BeanNameAutoProxyCreator which all Spring beans to intercept.”paymentDao”,”paymentService” etc are all classic Spring beans. Voila, your services and dao are all being monitored.

Oh…And one last thing.

Make sure you set the log4 logging level to TRACE or else it will NOT work!!

In the follow article , I shall show you have to generate reports from the JAMON framework using a simple servlet.

Serial Killers

Many of you are aware that laughter is one of the best medicines that can boost the state of mind. But how many of us know that worries and miseries can harm our total health. The more you become depressed and worried, the worst your health is affected and so does the interaction with your near and dear ones. 

Scientific studies have proven beyond doubt that laughter and happiness have a positive effect where as sadness, worries and despair have adverse effects on the life span of any living being. Neither joy nor sorrow come from within, but is the result of external turbulence. However, some of the agonies are unprecedented like accidents and natural calamities. At the same time, there are voluntarily chosen ones like the emotional turmoil generating TV serials/series. As the saying goes, too much of anything is harmful and so are these. In another few minutes, I will try to prove, with the help of facts and figures, how these emotionally disturbing tear generators can become “serial killers”. 

            Consider the case of an average family that views the idiot box. The bread winner is mostly busy with his day’s work and hardly put in any effort to watch it after a day’s work at office. The kids, back from school have hefty homework and are usually denied cartoons that bring in color and imagination to the mind of a growing child. The remaining members are the housewives and the old aged. Now you know why majority of the TV serials are shot with crying characters and pouring out tears. It appears that there are, at least, three channels airing such serials at a time. If the family is of a multilingual nature, then the number of serials gets multiplied by the number of languages the family can understand.

The calculation I have taken into consideration is trimmed down to the lowest. The peak viewing hours are often from 6pm to 9pm on weekdays and it becomes more on weekends. Taking a rough estimate, we can approximate 3 hours viewing per day (I am sure its even more than that). 

Out of this, 1½ hours are eye rubbing (filled with tears) TV serials and 1½ hours are good entertainers which hardly any housewife cares about as they are addicted to the “family enthrallers”. 

            From the 1½ hours, we set aside ½ an hour for advertisement. Have you ever wondered why these different ads are shown in between these serials!!!! ‘Cause various companies have sponsored the programs?????  Well, you guessed wrong. The sole intention of these properly spaced ads is to prevent the old aged from going into a stroke or coma while viewing these depressing serials. At the end, we have a total of 1hr viewing. Now for some scientific facts:

  • If you are positive and happy then you get your life span extended by 1 day (if you do not watch such serials)
  • If you cry, get depressed or turns into a bad- mood, it shortens your life span by at least 1 hour. 

So a total of 1 year’s viewing gives you 365 hours of non stop worries, and mind it, they do make sure to watch the next episode even if the day’s food is not cooked (no exaggerations whatsoever).

One day’s viewing gives a reduction in life span = 60 minutes 

                                        Therefore 1 year’s viewing   = 365 units (1 hr/day)

               Therefore 1 year’s reduction in life span = (365*60) minutes

                                                                                                 = 365 hrs

                                                                                                 = (365/24) days

                                                                                                 = 15.2 days

 

The average life expectancy of a human being is 70 years.

                         After 67 years, the loss of years    = (67*15.2)/365

                                                                                                Approx 3 years

If loosing 3 years of your life is a luxury you can afford then you just have wasted your time.

Now I leave it for you to decide.

Those who long to live, live longer…

How many times have you sent out an email and then said !@$%#!@. I  forgot the attachment again!!

Dont worry. Gmail can now save you from such embarassing moments.

If you try to send an email using gmail where in which your content has something like “Kindly find attached with this mail ….” and you forget to attach your document Gmail “automagically” alerts you. Check out the screenshot if you dont believe me.

Gmail Attachment Alert

Gmail Attachment Alert

And this is called “Thinking out of the Box”. Imagine, there have been thick clients such as Outlook and their likes for so so long, but such a small ingenious thought and thats what is called creative thinking. Hats off  “Google Guys”!!

Enjoy,

Franklin

Some time back, I was in need to invoke a simple WebService and that’s when one of my colleagues brought to my notice the simplicity of WSIF. Initially it looked to me as though it’s very simple. However I had to struggle a bit to invoke a simple WebService. I believe the reason for that was their poor documentation.

Needless to say WSIF was the brain child of IBM folks (do correct me if I am wrong) and has been prominently used in this space.

This article is just to show how to invoke a simple WebService which takes a FLAT XML request object and returns a FLAT XML response.

Below is the WSDL of the WebService in question. All it does is spit back a concatenated string of what you spit at it.

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:ns="http://ws.apache.org/axis2" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://ws.apache.org/axis2">
    <wsdl:types>
        <xs:schema attributeFormDefault="qualified" elementFormDefault="unqualified" targetNamespace="http://ws.apache.org/axis2">
            <xs:element name="showEcho">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="value" nillable="true" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="showEchoResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:schema>
    </wsdl:types>
    <wsdl:message name="showEchoRequest">
        <wsdl:part name="parameters" element="ns:showEcho"/>
    </wsdl:message>
    <wsdl:message name="showEchoResponse">
        <wsdl:part name="parameters" element="ns:showEchoResponse"/>
    </wsdl:message>
    <wsdl:portType name="TestPortType">
        <wsdl:operation name="showEcho">
            <wsdl:input message="ns:showEchoRequest" wsaw:Action="urn:showEcho"/>
            <wsdl:output message="ns:showEchoResponse" wsaw:Action="urn:showEchoResponse"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="TestSoap11Binding" type="ns:TestPortType">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <wsdl:operation name="showEcho">
            <soap:operation soapAction="urn:showEcho" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:binding name="TestSoap12Binding" type="ns:TestPortType">
        <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <wsdl:operation name="showEcho">
            <soap12:operation soapAction="urn:showEcho" style="document"/>
            <wsdl:input>
                <soap12:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap12:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:binding name="TestHttpBinding" type="ns:TestPortType">
        <http:binding verb="POST"/>
        <wsdl:operation name="showEcho">
            <http:operation location="Test/showEcho"/>
            <wsdl:input>
                <mime:content type="text/xml" part="showEcho"/>
            </wsdl:input>
            <wsdl:output>
                <mime:content type="text/xml" part="showEcho"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="Test">
        <wsdl:port name="TestHttpSoap11Endpoint" binding="ns:TestSoap11Binding">
            <soap:address location="http://10.142.20.66:8080/axis2/services/Test.TestHttpSoap11Endpoint/"/>
        </wsdl:port>
        <wsdl:port name="TestHttpSoap12Endpoint" binding="ns:TestSoap12Binding">
            <soap12:address location="http://10.142.20.66:8080/axis2/services/Test.TestHttpSoap12Endpoint/"/>
        </wsdl:port>
        <wsdl:port name="TestHttpEndpoint" binding="ns:TestHttpBinding">
            <http:address location="http://10.142.20.66:8080/axis2/services/Test.TestHttpEndpoint/"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

NOTE: This WebService was developed with the help of AXIS 2 runtime. I just created a normal java class and put the complied class file (after renaming its extension from .class to .aar) into the repository folder of the AXIS 2 server.

Now the Class used to invoke the WebService


package com.datel.transliterator.app;

import org.apache.log4j.Logger;
import org.apache.wsif.WSIFException;
import org.apache.wsif.WSIFMessage;
import org.apache.wsif.WSIFOperation;
import org.apache.wsif.WSIFPort;
import org.apache.wsif.WSIFService;
import org.apache.wsif.WSIFServiceFactory;
import org.apache.wsif.providers.soap.apacheaxis.WSIFDynamicProvider_ApacheAxis;
import org.apache.wsif.util.WSIFPluggableProviders;

public class WSInvoke {
	
	Logger log = Logger.getLogger(RunNow.class);
	
	public static void main(String[] args) throws Exception 
	{
		new WSInvoke().invoke();		
	}
		
    public void invoke() throws Exception
    {
		String result = null;
		
        WSIFPluggableProviders.overrideDefaultProvider("http://schemas.xmlsoap.org/wsdl/soap/",
        		new WSIFDynamicProvider_ApacheAxis()
    
        );
       
        // create a service factory
        WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
        WSIFService service = factory.getService(
	                "http://localhost:8080/axis2/services/Test?wsdl", //Location of the WSDL
	                null,
	                null,
	                "http://ws.apache.org/axis2", //TargetNamespace as per the WSDL
	                "TestPortType"); //PortType as per the WSDL

	        WSIFPort port = service.getPort();
	 

	        // create the operation
	        WSIFOperation operation = port.createOperation("showEcho");
	        
      

	        // create the input, output and fault messages associated with this operation
	        WSIFMessage input = operation.createInputMessage();
	        WSIFMessage output = operation.createOutputMessage();
	        WSIFMessage fault = operation.createFaultMessage();
	        
      
	        /*VALUE : BECAUSE OF THE attribute VALUE
	          <xs:element name="showEcho">
				<xs:complexType>
					<xs:sequence>
						<xs:element minOccurs="0" name="value" nillable="true" type="xs:string"/>
					</xs:sequence>
				</xs:complexType>
			   </xs:element>

        	  <xs:element name="showEchoResponse">
				<xs:complexType>
					<xs:sequence>
						<xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
					</xs:sequence>
				</xs:complexType>
				</xs:element>
        	  */	        
	        input.setObjectPart("value", " Hi there");
       
	        if (operation.executeRequestResponseOperation(input, output, fault)) 
	        {

	        	result = (String) output.getObjectPart("return");
	            System.out.println(result);
	             
	        } 
	        else 
	        {
	        	System.out.println("Invocation failed");
	            // extract fault message info
	        }
             
    }

}


We have created an “input” request object and set it with a key value pair, where the key is “name”. This is because the XML request object takes an attribute “name”

We have created an “output” response object and get it with a key value pair, where the key is “return”. This is because the XML response object takes an attribute “return”

Important:
This example is assuming the structure of the XML request and response object. I have only been able to using this type of invocation for FLAT XML objects. For complex XML request object please wait for PART 2 to see how its invoked.

Oracle JDeveloper SUCKS!!!

I really couldn’t help but write this after I found out how to create a folder with JDeveloper.

Do you agree or disagree?

 

Vendor : You can use this “CANNON” to fire moving objects and its extremely powerful

Customer : I only need a “STRAW” to drink juice !!

Vendor : Well you can disable the features in a “CANNON” and use it as “STRAW”

Customer : In that case I might as well use a “MISSLE” or a “ROCKET” !!

I was trying to access a secure web site using Apache HttpClient API. However, it was failing giving me the following exception

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

In apache HttpClient website, it states that “HttpClient provides full support for HTTP over Secure Sockets Layer (SSL) or IETF Transport Layer Security (TLS) protocols by leveraging the Java Secure Socket Extension (JSSE).

I tried their example of accessing a secure website and it worked. However the website I was trying to access is still failing.

After debugging the problem I came across a good article. In the article, the author mentioned that the above exception comes in the following case “when trying to open an SSL connection to a host using JSSE. What this usually means is that the server is using a test certificate (possibly generated using keytool) rather than a certificate from a well known commercial Certification Authority such as Verisign or GoDaddy. Web browsers display warning dialogs in this case, but since JSSE cannot assume an interactive user is present it just throws an exception by default.

That was not exactly my case. I was not getting a warning from the web browser. The web site I was trying to access was using a commercial certificate but it was not a very well known. It was from a regional authority and not an international authority. Any key store comes with a default set of certificates from well known authorities.

So, I ran the program mentioned in the article. A file called jssecacerts was generated which includes the certificate. I have placed the file in the JAVA_HOME\jre\lib\security directory. Finally I was able to access the secure web site successfully.