Why Is Swagger JSON Better Than Swagger Java Client?

The Swagger Java-Based Client Using Java Annotations on the Controller layer

Pros and Cons

  • It’s the old way of creating web-based REST API documents through the Swagger Java library.
  • It’s easy for Java developers to code.
  • All API description of endpoints will be added in the Java annotations parameters.
  • Swagger API dependency has to be added to the Maven configuration file POM.xml.
  • It creates overhead on the performance because of extra processing time for creating Swagger GUI files (CSS, HTML, JS etc). Also, parsing the annotation logic on the controller classes creates overhead on the performance, as well. It makes the build a little heavy to deploy on microservices, where build size should be smaller.
  • The code looks dirty because the extra code has to be added to the Spring MVC Controller classes through the Spring annotations. Sometimes, if the description of the API contract is too long, then it makes code unreadable and maintainable.
  • Any change in an API contract requires Java to build changes and re-deployment, even if it’s only simple text changes, like API definition text.
  • The biggest challenge is to share with the clients/QA/BA teams before the actual development and to make frequent amendments. The service consumers may change their requirements frequently. Then, it’s very difficult to make these changes in code and create the Swagger GUI HTML pages by redeploying and sharing the updated Swagger dashboard on the actual deployed dev/QA env.

2. Swagger JSON File Can be Written Separately and Provide Browser-Based GUI

Pros and Cons

  • In this latest approach, all of the above challenges with Java-based client solution have been solved.
  • The developer initially creates a JSON file, shares, and agrees with the service consumer and stakeholders. They will get signed off after many amendments —no code change and re-deployment are required.
  • The code will be cleaner, readable, and maintainable.
  • There is no extra overhead for file creation and processing, performance is better, and the code is more lightweight for microservices, etc.
  • There is no code dependency for any API contract changes.
  • Swagger JSON file resides in the project binaries (inside src/main/resources/swagger_api_doc.json). We can deploy Swagger on one server and can switch to an environment like this.


You can copy and paste swagger_api_doc.json JSON file content on https://editor.swagger.io/. It will help you modify content and create an HTML page like the following.  Swagger GUI will provide the web-based interface like Postman.


Blockchain in Insurance Claims

via Blockchain

Blockchain is a distributed ledger initially used by Bitcoin cryptocurrency and eventually by many banking organizations to record transactions between parties with high security. It is start of Blockchain arena and it is anticipated to have a long sustainability and acceptability in various industries.

One of the biggest use cases in Insurance Industry is adoption of blockchain in claim processing. Insurance contracts involve various parties as agents, brokers, repair shops and third party administrators involving manual work and duplication at various stages of value chain. Using blockchain, verification of transactions will be done without any human intervention and making it completely automated process at various stages.

Benefits for using blockchain in claim processing –

  1. The distributed ledger allows various parties to update the information securely like updating claim forms, evidence, police report etc helping in reduction of loss adjusted (LAE) expenses.
  2. Fraud Detection – As blockchain maintains a ledger of multiple parties, it has ability to eliminate any errors and frauds. Blockchain technology using the high computing power authenticates the customers, policies and transactions.
  3. Payments – Claim payments can be made without any need of intermediary authority for transaction validations which helps in reducing the overall operational cost of claims processing.
  4. As this is highly secured transactions, multi review process will be eliminated resulting into speedy claim processing.

Multithreading in real world

Most of you already know about threads and it’s benefits. This article will help you to understand how thread are being used in real world applications and what are the best practices. Threads are primarily used to achieve asynchronous  behavior and multitasking.

Below are some common real life use cases where threads have been used effectively.

  1. Animation and Games.
  2. Most of the GUI tools like Swing uses thread to keep track of events generated from widgets.
  3. Internally Junit uses threads for executing test cases parallel.
  4. Most of the web servers uses multithreading to entertain HTTP Requests parallel

Below are some common best practices for developing concurrent (multi threaded )applications.

Naming a Thread-

Thread should be named for easier debugging.  You can see in Eclipse that threads running in parallel with some random names like “Thread-124362563”. Giving a unique name to a thread will make it easier to identify the thread while debugging.

How many threads-

Before deciding number of threads to create , please keep in mind following facts.

  1. One processor executes a thread at a time and keeps switching between threads. Too much of switching can be an inefficient solution.
  2. Now a days most of the computers are multi core i.e comes with multiple processor so multiple threads can be executed simultaneously.

For long running threads one practice  can be to have no of processors as no of threads.

Use Immutable Classes 

Immutable classes, once created cannot be modified so one does not need to worry about sharing the state with multiple threads. This reduces  a great scope of synchronization.

Threads VS JMS –

I have developers discussing JMS VS Threads for developing asynchronous behavior.  I think JMS is more controllable way to use threads. JMS gives you additional features like tracking of request and retry to make a better enterprise choice.

Use Executors instead of Threads API

Object pool is a concept to avoid cost of object creation and destruction. JDK provides “Executors” as managed thread pool.

Use  java.util.concurrent

Java 5 added a java.util.concurrent  to the Java. This package contains a set of classes that makes it easier to develop concurrent scalable applications .Before this package was added , one need to use “synchronized” , “volatile” , “join” , “wait” and “notify” to write concurrent ( multi threaded applications) .

Popular items of “java.util.concurrent” are “BlockingQueue” , “semaphore” , “Lock Interface”  , “CountDown Latch” and “CyclicBarrier”.

Giving some details about Locks , CountDown Latch and Cyclic Barrier.


Prior to java 5  “synchronized” and “volatile” were the means of achieving concurrency. “Synchronized” provides a clean way to code but comes with limitation like try lock i.e. acquire only if lock is available. For more scalable concurrent solution JDK added lock interface and various implementations. “Reentrant lock” is a popular implementation of Lock interface.

Synchronized acquired a intrinitc lock on object wihis realeased automaticaaly. Bot with Lock , one need to release a lock programiticaaly. Best practice is to relase the lock in try block.

Synchronized acquired a intrinitc lock on object wihis realeased automaticaaly. Bot with Lock , one need to release a lock programiticaaly. Best practice is to relase the lock in try block.

CyclicBarrier and CountDown Latch

Both CyclicBarrier and CountDown latch are used for thread synchronization i.e. thread waits for another thread to complete their job at some point. Difference between both is that Cyclic Barrier instance can be reused while CountDownLatch instance can not.







Logback is not writing specific log file Solution

Logback is not writing specific log file Solution
Logback Configuration:
<property name="DEV_HOME" value="/root/apps/logs" />
<appender name="FILE-AUDIT"     class="ch.qos.logback.core.rolling.RollingFileAppender">
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <!-- rollover daily -->
        <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
            <!-- or whenever the file size reaches the max -->

Issue is related to conflict between log4j and Logback, when we migrate from old log4j to Logback. You need to exclude lo4j dependencies from existing dependencies by running this command:

$ mvn dependency:tree

= >Add these jars only for logging using SLF4j and Logback




Posted detail issue on StackOverflow:


Crawl and Index….. Nutch / elasticSearch – Partners in the making


In the internet era, there is an old tech saying – “Content is King”  (inspired by old Jungle saying from Phantom.. 🙂 )

One of the common challenges in content management system is to extract the latest information.  In the WWW world, it is commonly known as crawling.  The king of the crawler world is Apache nutch.

elasticsearch (no more just the new kid in town) has already established itself as one of the top search platforms.  It is only natural that companies are looking at using the both platforms together to achieve a better content management system specifically acquire, analyze, publish, search  phase.

Here’s a quick and dirty guide to get them up and running quickly.

1. Download nutch
3. Clean build
ant clean
4. Verify new local deploy created under NUTCH_HOME/rutime
5. Under bin sudirectory of local, create a new directory called urls
6. In urls create a new file called nutch.txt. Edit the file to add URLs to crawl
7. Enable crawler in conf/nutch-site.xml by adding the below lines within configuration tags
<value>My Nutch Spider</value>
8. Note the value and enter the same in conf/nutch-default.xml as the
value for <name>http.agent.name</name>
9. Test by running the below command in local/bin

nutch crawl urls -dir /tmp -depth 2
Integrate Nutch and ES
1. Activate elasticsearch indexer plugin
Edit conf/nutch-site.xml

<description>Regular expression naming plugin directory names to
include. Any plugin not matching this expression is excluded.
In any case you need at least include the nutch-extensionpoints plugin. By
default Nutch includes crawling just HTML and plain text via HTTP,
and basic indexing and search plugins. In order to use HTTPS please enable
protocol-httpclient, but be aware of possible intermittent problems with the
underlying commons-httpclient library.

2. Verify and add ES specific properties to nutch-site.xlm

<!– Elasticsearch properties –>

<description>The hostname to send documents to using TransportClient. Either host
and port must be defined or cluster.</description>


<description>The cluster name to discover. Either host and potr must be defined
or cluster.</description>

<description>Default index to send documents to.</description>

<description>Maximum size of the bulk in number of documents.</description>

<description>Maximum size of the bulk in bytes.</description>

3. Create a new index in ES if it is not there already

curl -XPUT ‘http://localhost:9200/nutch/&#8217;

Java Code Quality


Most tech leads will readily admit that in large development projects, a major chunk of their effort goes towards ensuring good code quality.  With the increase in number of developers, there is greater need for standardization the code which is enforced in the form of adherence to certain code quality.  As a programming language, Java if fortunate enough to have several coding conventions defined by several companies including Oracle (Sun).  However every company or even individual projects within a company often supplement the general standard with it’s own set of custom guidelines, rules and conventions.

Just like everything else in life, it is a simpler matter to define standards / guidelines.  However it is an entirely different ball game to follow them.  For architects and tech leads it is a question of ensuring the adherence.  So, we are constantly on the lookout for efficient ways to accomplish this.  One of our favourite tools is the Sonar – Java static code analysis tool from Sonarqube.

Here are some quick steps on how to get up and running with Sonar on a Mac system.  Hope you find it useful.

Set up Sonar

Here’s a great link that i found

1. Download sonar into some directory
For eg /Users/madheshr/tools/sonar-3.7

2. Create the sonar schema on MySQL

3. Edit sonar.properties in the conf directory and make below changes

– Specify DB parameters
– Webhosting mechanism: default is

4. Create a startup script to start sonar
/Users/madheshr/tools/sonar-3.7/bin/macosx-universal-64/sonar.sh start &
Analyzing a project using sonar-runner

1. Download sonar-runner and extract it

2. Edit conf/sonar-runner.properties to mention webserver name and DB name

Note: The default script has mismatched sonar schema names.
3. In the project home create a file sonar-project.properties. Note it is case-sensitive
Also confirm the path from which java code starts. May not be the main src itself

# required metadata

# optional description
sonar.projectDescription=Admin utility for iRecon

# path to source directories (required)

# The value of the property must be the key of the language.

# Encoding of the source code

4. Run using command sonar-runner

As always, all the mistakes are mine and all the credits go to the open source community.