Search results for: Java

class ReactiveJavaTutorial { public static void main(String[] args) { Flux<String> firstFlux = Flux.fromArray(new String[]{“a”, “b”, “c”}); Flux<String> secondFlux = Flux.fromArray(new String[]{“d”, “e”, “f”}); // combine two Flux Publishers Flux<String> combinedFlux = Flux.concat(firstFlux, secondFlux); // subscribe and print the elements of a combined Flux combinedFlux.subscribe(element -> System.out.print(element + ” “)); } } Output: a b c…

Read More Combine Flux and Mono Publishers

class ReactiveJavaTutorial { public static void main(String[] args) { Flux.fromArray(new String[]{“Tom”, “Melissa”, “Steve”, “Megan”}) .map(String::toUpperCase) .subscribe(System.out::println); } } Output: TOM MELISSA STEVE MEGAN class ReactiveJavaTutorial { public static void main(String[] args) { Flux.fromArray(new String[]{“Tom”, “Melissa”, “Steven”, “Megan”}) .filter(name -> name.length() > 5) .map(String::toUpperCase) .subscribe(System.out::println); } } Output: MELISSA STEVEN   Note: Reactive Streams are immutable.…

Read More Transform Flux and Mono Using Operators

Flux<String> cities = Flux.fromIterable( new ArrayList<>(Arrays.asList(“New York”, “London”, “Paris”, “Toronto”, “Rome”))); cities.subscribe(); class ReactiveJavaTutorial { public static void main(String[] args) { Flux<String> cities = Flux.fromIterable( new ArrayList<>(Arrays.asList(“New York”, “London”, “Paris”, “Toronto”, “Rome”))); cities.log().subscribe(); } } Output: INFO 6832 — [ main] reactor.Flux.Iterable.1 : | onSubscribe([Synchronous Fuseable] FluxIterable.IterableSubscription) INFO 6832 — [ main] reactor.Flux.Iterable.1 : |…

Read More How Mono and Flux Work Internally?

class ReactiveJavaTutorial { public static void main(String[] args) { Mono<String> mono = Mono.just(“data”); Flux<String> fluxFromMono = Flux.from(mono); fluxFromMono.subscribe(System.out::println); } } Output: data class ReactiveJavaTutorial { public static void main(String[] args) { // one value Flux<String> flux1 = Flux.just(“data1”); Mono<String> monoFromFlux1 = flux1.next(); // get data from mono monoFromFlux1.subscribe(data -> System.out.println(“monoFromFlux1 data: ” + data)); //…

Read More Convert Mono to Flux and vice versa

class ReactiveJavaTutorial { public static void main(String[] args) throws InterruptedException { Flux<String> flux = Flux.fromArray(new String[]{“data1”, “data2”, “data3”}); flux.subscribe(System.out::println); } } Output: data1 data2 data3   Another way would be using the Reactive Streams operators like onNext, flatMap, etc. class ReactiveJavaTutorial { public static void main(String[] args) throws InterruptedException { Flux<String> flux = Flux.fromArray(new String[]{“data1”,…

Read More Extract data from Flux

Testing Java with JUnit & Mockito This video course is for beginners and you do not need to have any prior Unit testing knowledge to enrol into this course. The course covers JUnit 5 basics as well as advanced topics. You will also learn to use another very popular testing framework for Java called Mockito.…

Read More My Video Courses

This tutorial will demonstrate how to implement the One-to-Many Mapping in your Spring Boot application that uses Hibernate/Spring Data JPA. As a database, I will use a MySQL server. If you are learning about Hibernate, you might also be interested in the following tutorials: One-to-One Mapping Hibernate/JPA Using Spring Boot and MySQL Many-to-Many Relationship in…

Read More One to Many Mapping Hibernate/JPA Using Spring Boot and MySQL

This tutorial will demonstrate how One-to-One Mapping in Hibernate/Spring Boot Data JPA works. As a database, I will use a MySQL database server. We will create two JPA entities: the Book and the Story. The Book and the Story entities have one to one relationship, which means that the Book entity has a Story entity,…

Read More One to One Mapping Hibernate/JPA Using Spring Boot and MySQL

import org.apache.http.HttpResponse; import org.apache.http.HttpHeaders; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.client.methods.RequestBuilder; import org.apache.http.impl.client.BasicResponseHandler; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import java.io.IOException; public class Test { public static void main(String[] args) throws IOException { try (CloseableHttpClient httpclient = HttpClients.createDefault()) { HttpUriRequest request = RequestBuilder.get() .setUri(“https://jsonplaceholder.typicode.com/todos/1”) // adding headers .setHeader(HttpHeaders.CONTENT_TYPE, “application/json”) .setHeader(“Authorization”, “Bearer 123token”) .build(); System.out.println(“Executing GET request…”); HttpResponse response = httpclient.execute(request);…

Read More Add a Custom HTTP Header with the HttpClient

In this post, we will cover the concepts of using AWS Lambda variables and discuss why there is a need to have environment variables in lambda functions. Use case of Environment Variables in AWS Lambda Function You can use environment variables to customize function behavior in your test environment and production environment. For example, you…

Read More AWS Lambda Environment Variables – Encryption & Decryption

In this tutorial, I’ll guide you on how to use the new OAuth2 Authorization Server(v0.0.3) built by the Spring Team. Below are the new features that have been introduced in the newer version: Enforce one-time use for authorization code Introduce OAuth2 Tokens Add Refresh Token grant Implement Token Revocation Endpoint OAuth2 is an authorization method…

Read More The New OAuth2 Authorization Server

An important property of modern web apps is resilience. In simple terms, resilience refers to the ability of a system or feature to fail gracefully without impacting the entire system. In the context of web apps, we want to ensure that the entire system will not go down if a remote service, such as a…

Read More Enforcing Resilience in Spring Boot with Resilience4J

In this tutorial, you will learn how to call stored procedures in a Spring Boot RESTful API project that uses Spring Data JPA. Using a stored procedure to execute parts of the application logic in the database is a widely used approach in huge, data-heavy applications. A stored procedure is a group of predefined SQL…

Read More Calling a Stored Procedure in Spring Boot REST with JPA

This tutorial is the fifth in a series on Reactive Programming in Java and Spring Framework. In this tutorial, we will develop a simple REST API using Spring Web flux. To completely understand this tutorial, it is better to read a previous tutorial first. It would also help to know how to develop a REST Controller using…

Read More Developing a REST API using Spring WebFlux

In this tutorial, you will learn how to create a custom password encoder in a Spring Boot application that uses Spring Security. Table of contents Create a Spring Boot project and add database connection properties, Add a User model, Create a User repository, Implement a custom PasswordEncoder, Create a service class that implements UserDetailService, Add…

Read More Custom Password Encoder in Spring Security