Integrate Swagger with Spring boot application for RESTful API documentation-Lab 4

Hi Readers,

I am happy to post another blog post on how to integrate swagger with Spring boot application for RESTful API documentation.

You have created a RESTful project(say) and like to integrate swagger for representing your RESTful API then this post is for you.

In pom.xml add the below dependency

 io.springfox
 springfox-swagger2
 2.2.2
 io.springfox
 springfox-swagger-ui
 2.2.2

Create a swagger config class similar to this.

Inside the predicate method, add your request mapping path.

Take a maven build and run as spring boot app.

Open a browser and type the below url.

http://localhost:8080/swagger-ui.html

swaggerprojectsjosepraveen1.PNG

From the above diagram the highlighted ones points to my @RequestMapping value of my controller.

Let me know your thoughts and experiences on how to integrate swagger with Spring boot application for RESTful API documentation.

Happy Learning !!

Integrate H2 database in your Spring Boot Application – Lab 3

Hi Readers,

I am happy to post another blog post on how to integrate H2 database in your Spring Boot Application.

In this tutorial we will be using the H2 database in embedded mode.

You have created a  spring boot application and like to integrate with h2 database.

In pom.xml add the below dependency.

 <!-- H2 Database -->
 <dependency>
 <groupId>com.h2database</groupId>
 <artifactId>h2</artifactId>
 </dependency>

In applciation.properties file add the below line to enable the h2 database.

# H2
spring.h2.console.enabled=true
spring.h2.console.path=/h2

# Datasource
spring.datasource.url=jdbc:h2:file:~/test
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver

 

Take a maven build and run the application as spring boot app.

Open a browser and type

http://localhost:8080/h2  to get the below image.

h2databasejosepraveen

The above yellow highlighted lines should match your application.properties file.

h2databasejosepraveen1

If you get stuck, kindly comment below.

Ask me your questions/ doubt in quora.

Thanks for reading this post. Subscribe my blog for  some awesome posts.

Monitor your built-in endpoints- Spring Boot Lab 2

Hi Readers,

I am happy to post another blog post on how to monitor your built-in endpoints of your Spring Boot application.

While i was checking my STS console my look peeped into area which is shown below.

springbootjosepraveen3.PNG

If you like to activate your built-in endpoints in your spring boot applciation. Just add the below dependencies in your pom.xml file

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

After adding the above dependencies in pom.xml take a maven build with goals as clean install and run the spring boot application.

You will notice the above image in the console which gets rolled out.

Open a browser and hit the below ones.

http://localhost:8080/health,

http://localhost:8080/env ,

http://localhost:8080/beans,

http://localhost:8080/beans,

http://localhost:8080/trace,

http://localhost:8080/info,

http://localhost:8080/trace

If you get stuck, kindly comment below.

Ask me your questions/ doubt in quora.

Thanks for reading this post. Subscribe my blog for  some awesome posts.

Using map reduce to find max and min temperature for a data set – lab 1

Hi Readers,

I am happy to post another blog post on how to use map reduce to find Max and Min temperature of a data set.

I have a dataset (say temperaturedata.txt) file. I like to analyze the above data set using map reduce.

I have a written a map reduce program to find the max and min temp of the year.

 

I have a data set in my linux file system and I need to move that to hadoop file system.

hdfs dfs -copyFromLocal /home/cloudera/Downloads/temperaturedata.txt /jpraveen/temperaturedata.txt

Now the file is in hdfs directory i.e (hdfs dfs -ls /jpraveen/)

Now you need to convert your map reduce program into a jar file and run the jar file using the below command.

hadoop jar MaxMinTemp.jar  /jpraveen/temperaturedata.txt  ~/output1

Note:

Below code snippet in the main method of your program

 FileInputFormat.setInputPaths(job, new Path(args[0])) represents this value /jpraveen/temperaturedata.txt.
 FileOutputFormat.setOutputPath(job, new Path(args[1])) represents this value ~/output1.

JobClient.runJob(job) this will trigger the map reduce job to start.

Moreover you can also track the job status which you will get at the time of running the map reduce.

http://quickstart.cloudera:19888/jobhistory/job/job_1479137854338_0004/

The output of the above job can seen using the below command or through file browser

hdfs dfs -cat /root/output1/part-00000 .

(or)

http://quickstart.cloudera:50070/explorer.html#/root/output5.

Integrate inmemory authentication for a Spring Boot application – Lab 1

Hi Readers,

I am happy to post another blog post on how to Integrate inmemory authentication for a Spring Boot application.

I have created a simple spring boot project in STS IDE using Spring Starter kit. While navigating through the starter kit for creating your spring boot application you need to select web so that the spring boot web dependencies get added to the pom.xml file.

springbootjosepraveen

Now I like to have a in-memory authentication  for my sample project.

Open pom.xml add the below dependency

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>

Create a simple class like this.

Take a maven build with goals as clean, install.

Run this spring boot application. You need to give the right credentials as in authentication class

springbootjosepraveen1.PNG

springbootjosepraveen2.PNG

Points to Ponder:

AuthenticationManagerBuilder ==>> SecurityBuilder used to create an AuthenticationManager. Allows for easily building in memory authentication, LDAP authentication, JDBC based authentication, adding UserDetailsService, and adding AuthenticationProvider’s.

Easy to read/ search contents in a file using grep output

In post we are going to find out how we can display the grep contents(colorful) in application log file(say). You are searching a particular content in a application log file. The log file is too big and you need to open it in a notepad++ or editplus. Rather than use the below tip.

Go to the path in which log file is

type grep –color=always PSP route.dat

grepjoseblog

Hope this helps you. Please subscribe and comment if you have any doubts.

Different Java versions – codename and features

Below are the changes introduced with each version.

Java 1.0 ( 1996 )

Codenamed Oak and released on January 23, 1996
Java 1.1 ( 1997 )

  • JDBC (Java Database Connectivity)
  • Inner Classes
  • Java Beans
  • RMI (Remote Method Invocation)
  • Reflection (introspection only)

Java 1.2 ( 1998 )

  • Collections framework.
  • Java String memory map for constants.
  • Just In Time (JIT) compiler.
  • Jar Signer for signing Java ARchive (JAR) files.
  • Policy Tool for granting access to system resources.
  • Java Foundation Classes (JFC) which consists of Swing 1.0, Drag and Drop, and Java 2D class libraries.
  • Java Plug-in
  • Scrollable result sets, BLOB, CLOB, batch update, user-defined types in JDBC.
  • Audio support in Applets.

Java 1.3 ( 2000)

Code named Kestrel

  • Java Sound
  • Jar Indexing
  • A huge list of enhancements in almost all the java area.

Java 1.4 ( 2002 )

Code named Merlin

  • XML Processing
  • Java Print Service
  • Logging API
  • Java Web Start
  • JDBC 3.0 API
  • Assertions
  • Preferences API
  • Chained Exception
  • IPv6 Support
  • Regular Expressions
  • Image I/O API

Java 1.5 ( 2004 )

Code named Tiger

  • Generics
  • Enhanced for Loop
  • Autoboxing/Unboxing
  • Typesafe Enums
  • Varargs
  • Static Import
  • Metadata (Annotations)
  • Instrumentation

Java 1.6 ( 2006 )

Code named Mustang

  • Scripting Language Support
  • JDBC 4.0 API
  • Java Compiler API
  • Pluggable Annotations
  • Native PKI, Java GSS, Kerberos and LDAP support.
  • Integrated Web Services.
  • Lot more enhancements.

Java 1.7 ( 2011 )

Code named Dolphin

  • Strings in switch Statement
  • Type Inference for Generic Instance Creation
  • Multiple Exception Handling
  • Support for Dynamic Languages
  • Try with Resources
  • Java nio Package
  • Binary Literals, underscore in literals
  • Diamond Syntax
  • Automatic null Handling

Java 1.8 ( 2014 )

  • Lambda Expressions
  • Pipelines and Streams
  • Date and Time API
  • Default Methods
  • Type Annotations
  • Nashhorn JavaScript Engine
  • Concurrent Accumulators
  • Parallel operations
  • PermGen Error Removed
  • TLS SNI

Java 9 is expected to be release between March 2017.

Major releases
Java 1.1 ( RMI )
Java 1.2 ( Collections Classes )
Java 1.5 ( Enums, Generics )
Java 1.8 (Lambda expressions, Method Reference , Streams)

Reference:

http://javapapers.com/core-java/java-features-and-history/

Hope this helps. Please subscribe the blog and comment if any doubts.