Spring Boot MVC download image or binary file

Sometime we want our user to download some file from our web application that is developed in Spring MVC or Spring Boot. To achieve this the main trick is to send the Content-Disposition http header before sending the data. Here is an example of a Controller class with just one method that take the name of a jpg image file from url, read that file from a predefined location, set the appropriate http header and send the data to the client.

Java Selenium web automation example

Selenium Webdriver became a defacto standard for automating the web based test. Here we will see a very basic example of web automation using Selenuium framework. Source code folder structure: java-selenium-web-automation-gradle-example ├──build.gradle ├──settings.gradle └──src └──main └──java └──com └──firstfewlines └──SeleniumSample.java 1. build.gradle group 'com.firstfewlines' version '1.0-SNAPSHOT' apply plugin: 'java' apply plugin: 'application' sourceCompatibility = 1.8 mainClassName = 'com.firstfewlines.SeleniumSample' repositories { mavenCentral() } dependencies { compile('org.seleniumhq.selenium:selenium-java:3.4.0') { exclude group: 'org.

Spring Boot MVC Controller send image or binary data

In web server application, sending image data to client browser is quite common job. This can be easily achieved in Spring or Spring boot MVC Controller. Key things here is to specify proper Content-Type such as image/png or whatever and then return the raw binary data of the image. Here is a sample code to demonstrate the same. @Controller public class ImageController { @RequestMapping("/images/{id}") public ResponseEntity<byte[]> getImage(@PathVariable("id") String id) throws IOException { String filename = "D:/images/" + id + ".

Spring Boot + Spring JPA with PostgreSQL or MySQL or Oracle or SQL Server database and Thymeleaf using Gradle

Here we will see how to build a sample full stack web application using Spring Boot, Spring JPA with database like PostgreSQL, MySQL or Oracle Thymeleaf and Gradle. This example is very similar with my other example regarding Spring boot with H2 database: Spring Boot H2 data source with Thymeleaf using Gradle The only exception here, we will use some production database like postgres as database. So there are changes around Spring JPA configuration and Gradle build file.

Spark Java with Hibernate and MySql database example

In practical scenario it is very common to integrate a database with the web service application. Here we will see an example to use Hibernate to store and retrieve data in Spark Java application. We will use MySql database behind the Hibernate. The application provides HTML based UI for entering and viewing data. Gradle is our build tool here. In case Maven is your favourite build tool, just let me know.