Monday, August 29, 2016

HTTP Communication between Client and Server

Step 1: On the client machine, user who wants a web-resource(eg: html document) from a web server types the URL of the resource in a Browser window and then clicks GO.

Step 2: Browser - a s/w program(Eg C or C++) running on the client machine - takes URL as the input and converts it into HTTP message(also called HTTP request) since Http Clients(Eg Browser) and Http Servers(Eg Apache Web server) use HTTP protocol to communicate. All modern browsers are pre-built with the functionalities of encoding and decoding Http(Application layer protocols or OSI layers 5,6,7) message to/from servers. Servers too have the similar capablities.


   To be more specific, Browser implements** Client Side of the HTTP protocol and Web Server implements Server side of the HTTP protocol.

   The converted HTTP message is then handed over to machine's Operating System's Protocol infrastructure(OSI layers 1,2,3,4) -  Transfer Control Protocol(TCP part of Transport Layer), Internet Protocol(IP part of Internet layer) and Network Protocol( Part of Link Layer). HTTP Message when passed through these three layers will be ultimately become electric/electronic signals which can be transmitted through wired or wireless Internet to the destination.


Step 3: The HTTP message(in the form of electric/electronic/electro magnatic/ light signal) then arrives at the destination machine(Http server in this case). Exact reverse process follows here and converted back to HTTP message. This HTTP message is then be read by Http server(a Software program running on the server machine having the capabilities to read and understand HTTP messages) translates it for later processing by any Java/.NET middle-ware program (which also is running on the server machine). Once the processing is done, a Http Response is created and sent back to client in the exact same fashion(Step 1 through Step 3...shown below)





**What is meant by HTTP implementation by Browser or Web Server?
The explanation could be as simple and plain as a Student asking his or her Teacher a question.

Analogy:

Student who wants to ask his/her English teacher a question says..

What is the tallest structure in the world? ----> [A Message in ENGLISH]


The sentence is constructed based on the Grammar guidelines specified by English language.


Similarly, a browser which wants a html document from a Webserver on a remote machine requests in the following way...


GET /hello.htm HTTP/1.1

User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Host: www.google.com
Accept-Language: en-us

The above is [A Message in HTTP]


The message is constructed based on the guidelines specified by W3Consortium on HTTP protocol.


A protocol can be identical to a langugage.

Monday, July 4, 2016

J2EE APIs Placement based on Usage point of view


J2EE Specification has various APIs each having its own functionality to cater for. While developing an Application using these, each API may or may not need others. Following is a usage/interaction level diagram that shows how they can be positioned wrt each other.


Looking from Web Application development based on J2EE compliant server, the EJB container and Web Container APIs are mandatory. Rest of the APIs such as - JMS, JPA, JTA etc are all going to be used based on the services that they offer.

Hence the Container APIs are placed at the center and rest of the APIs are surrounding them.

Note on Terminology:
Container APIs are generally called as Component APIs
Rest of the Service providing APIs - JMS, JAX-WS, JPA, Security - are termed as Resource APIs or Service APIs.

Overview of how Server Runs:
J2EE App Server runs using J2SE Platform APIs and both run in Java Runtime Environment(JRE) on Java Virtual Machine(JVM)

Sunday, July 3, 2016

API level Matching between J2EE compliant Server and Spring Eco System

Having experienced in developing  Java based Web Applications using J2EE compliant app servers and Spring Framework, below is my understanding of how various APIs fit-in if compared at API level in terms of similarity or analogy.

Note: Comparison is not based on performance or any other metrics.




J2EE compliant Application Server: Any implementation of the J2EE specifications. Oracle's WebLogic, IBM's WebSphere are most popular examples. But they are many more that can be found if you search for J2EE compliant Servers.


Tuesday, February 9, 2016

Accessing JSP data inside JavaScript or jQuery

Issue: I came across this situation while trying to add row of select boxes to a table in a JSP page upon clicking an AddRow button. The 'select' boxes should be populated with some model data(jsp data) received from Spring's controller. I am able to add the row of select boxes to the table using jQuery but unable to use the JSP data to the select boxes.

Solution: After searching various solutions on internet, I finalized on 2 methods:

Method 1: Set the JSP data to a html element and read the data inside jQuery and use it.
Method 2: Go for ajax calls in jQuery to fetch data from controller every time you need to populate the select boxes.

Monday, January 25, 2016

Appropirate Usage of JacksonDatatypeHibernate

Jackson, Spring and Hibernate are the three popular frameworks in their respective technologies but there are some issues occuring while using all these 3 together due to serialization of lazy loaded hibernate objects.

I faced a similar issue while converting Hibernate object to JSON using Jackson API in a Spring based web application and following is a sample error description:

No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer  to avoid exception, disable 
SerializationConfig.SerializationFeature.FAIL_ON_EMPTY_BEANS)



Approach to solve the above issue:
Having gone through various forums and many different solutions, I have decided to zero in on using JacksonDatatypeHibernate add-on to fix the lazy loading concerns.

Step 1:
Write an ObjectMapper extension-class in one of your packages to inject Hibernate4Module object into ObjectMapper:




Step 2:
Register ObjectMapper extension-class(HibernateAwareObjectMapper) in the Spring-Config.xml with the following configuration:

Important note:
Never configure message converters outside of the annotation-driver tag when mvc:annotation-driven is enabled.  The registered message converter has to be inside the message-converters tag.

This is it.

Monday, October 19, 2015

Solution for Tomcat Server Start issue - A child container failed to start...

Environment: Tomcat 8 + Spring + Eclipse+J2EE
Issue: Starting the Tomcat server gives the following issue:


A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/Spring3Hibernate]]
    at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:252)
    at java.util.concurrent.FutureTask.get(FutureTask.java:111)
    at org.apache.catalina.core.ContainerBase.startInternal(Contai...


Solution: Add commons-logging jars to the lib folder and restart the server. This will solve the issue.




Tuesday, September 1, 2015

Selenium-Webdriver-Java-IssuesList

1. Incompatibility of webdriver-java bindings with browser version. Encountered issues with Firefox. IE and Chrome used to work fine.
Sol: Upgrade or Downgrade the Browser version to be compatible with webdriver. Refer the changelog or release notes on the java binding.

2. GUI Automation Issues with TeamCity running as a service. Webdriver unable to locate elements when running TeamCity as a service but it is able to do so if TCAgent is run via OSConsole.

3. Issue with TestNG parallelism not working with already designed framework due to Grouping.

4. cacert import issue:
“PKIX path building failed” and “unable to find valid certification path to requested target”
SSLHandshake issue while using httpclient to connect to a website and getting response.
Sol: Generally import RootCertificate not the intermediate ones and add them to cacert file.


I will keep updating this post if and when I encountered any issues.

How J2EE components work together in any Container - Spring or Application Server

In a Spring+Jersey+Hibernate RESTful webapplication, we can spot various J2EE components - JTA, JPA, Java Bean Validation, JSON-B API for B...