Spring REST Optional Path Variable Example

Optional Path Variable In this tutorial I will show you how to work with Spring framework’s optional path variable (PathVariable) in REST services. Here I will use Java 8’s java.util.Optional or using attribute required=false and at least Spring Boot 2.1.4 to support optional PathVariable. The optional variable can be found in the URI resource path of the URL.

Convert Image To PDF File Using Java

Introduction This tutorial will show you how to convert image to pdf file using Java programming language. For this I am using here itext API. The example Java image to pdf file will show you step by step procedures for image to pdf conversion. I will build the application using both gradle and maven tools. In this example I will…

MySQL Function to Capitalize the First Letter of Words in a String

The below MySQL function will show how to capitalize first letter of each word in a string.

Validate input data in REST service

Introduction In this tutorial I will show you how you can validate your input data while working with REST service. Generally you need to validate the input data coming from end users because users may give anything as an input but your service side code should not accept anything as an input for the defined field. Prerequisites Please go through…

How to delete files having too long path in Windows

Introduction In this post we will see how to delete files having too long path in Windows Operating System. Sometimes we face problem while try to delete directories or files having too long path in Windows Operating System. So in this tutorial I will tell you few simple steps by which you can delete directories or files having too long…

Java 8 : Iterate Map And Add To List

Here I will show you how to iterate Map in Java 8 and add element to List. I came across a situation where I required to fetch data from a HashMap and add it to an ArrayList. So I will show you here how to iterate a Map and form an object and finally add it to the List using…

Java 8: iterate over Map of List of Objects

In this example I am going to show you how to iterate over map of list of objects. Let’s say you have keys as strings and values as list of objects in a HashMap. Now you want to iterate list of objects and want make one attribute of the object as keys and other attribute(s) as values and want to…

Documenting Spring REST API with Swagger 2

When creating a REST API, good documentation is instrumental. But developers do not have any option using JSR-339 to generate any documentation on all these APIs so other developers could quickly understand how to use them. For sure, it would be just awesome to generate verbose and easy to follow documentation from source code, and but the help is coming in…

MySQL error – Access denied for user ‘root’@’localhost’

If you get an error message like this: Access denied for user: ‘username@localhost’ (Using password: YES) then the problem is that user can not access the database. This can have several causes: First of all, you use the correct name and password of your MySQL user for connecting to your database. Secondly, make sure the your database user has the…

Spring Boot Security Pre-authentication Example

Spring Security Pre Authentication Here you will see an example on Spring Security Pre-authentication. There are situations where you want to use Spring Security for authorization, but the user has already been reliably authenticated by some external system prior to accessing the application. In such situations where Spring Security Pre-authentication comes into picture I refer to these situations as “pre-authenticated”…