Month: May 2020

  • The different ways to sort Collections in Java

    Let’s say you have an Employee class with attributes like name , age , rating etc. You want to create a number of employees and sort them all by name. How to do this in Java? You make the Employee class implement Comparable interface which has a method compareTo(). The Employee class needs to implement…

  • How to dockerize a Java application?

    Docker revolutionized the way applications are deployed. To deploy an application to a server , you no more need to set up required softwares/dependencies on the server machine. Create your application in development environment , build a docker image and then run the image on the server . Below is a simple example of how…

  • How to implement Concurrency in Java – A very minimalist example

    Let’s say you are implementing a batch service and you want to execute a lot of methods. Let’s assume they are independent functionalities and the output of one is not used by any other methods. Executing them one by one will consume a lot of time. The best strategy is to execute them in parallel.…

  • How to enable virtualization in Windows ?

    I have Windows 10 Home Single Language edition of Windows Operation System installed in my laptop. I tried to install Docker for Desktop in my system and it didn’t support. Instead Docker suggested installing Docker Toolbox . But for installing one of the prerequisites is that Virtualization should be enabled in Windows. I checked mine…

  • How to dockerize Spring Boot app the version 2.3.0 way?

    Spring Boot released its latest version 2.3.0 two days back (15 May 2020). One major feature provided by this release is creating docker images of a spring boot app in a much more efficient way. Prior to this , if you were to dockerize your spring boot app you need to take the jar generated…

  • How to secure a REST service in Spring Boot using Basic Authentication?

    Rest Services can be secured in a variety of ways: Basic Authentication , Bearer Authentication , API Keys , Open Id etc. Basic Authentication is the simplest , it uses a user name and password to secure a REST service. In this post let’s see how to protect a REST service using basic authentication in…

  • How to send multiple headers using Open Feign ?

    If you are consuming a REST service in Spring using Open Feign , you may come across scenarios where multiple headers need to be set. In the previous post: How to invoke a basic authenticated REST service using Open Feign? I explained how to set Authorization header while consuming a basic authenticated REST service. You…

  • How to invoke a REST service protected by BasicAuth using Spring Open Feign?

    Invoking REST services from Spring is much easier if you use Spring Open Feign. It allows you to invoke REST services declaratively and saves a lot of code. Here is the post explaining the basic concept of Open Feign: How to call a REST service declaratively using Open Feign? It is a very simple example…

  • Elegance vs Utility – How to address this problem as a software developer?

    I came across an issue in one of my code today. A rest client I wrote was throwing error when consuming a third party rest service. It was working well and suddenly started throwing exceptions. I debugged and found out that the issue was due to a security fix I recently added. Fixing security vulnerabilities…

  • How to call a REST service from Spring declaratively using OpenFeign?

    If you are using Spring, you are probably using Rest Template provided by Spring to invoke third party REST services. That involves some code , preparing the REST template , populating the parameters required for one of the methods exposed by the REST template and finally invoking one of its specific methods. What if you…