2. Dependencies and REST APIs

3. Using @ControllerAdvice

Introduced in Spring 3.2. it’s a better way to handle different kind of exceptions using @ExceptionHandler annotation. ResponseEntity used for type safety and provides flexibility to include HTTP headers and response status.

5. Conclusion

In this post, we learned different ways of exception handling for Spring based RESTful APIs. We also observed that ResponseStatusException is the simple and powerful approach to use for exception handling.

]]>https://www.cloudtechpro.com/exception-handling-spring-rest-services/feed0Spring Boot 2 HTTP Basic Authenticationhttps://www.cloudtechpro.com/spring-boot-2-http-basic-authentication
https://www.cloudtechpro.com/spring-boot-2-http-basic-authentication#respondSun, 25 Nov 2018 11:56:10 +0000http://www.cloudtechpro.com/?p=487This is post 4 of 5 in the series “Spring Tutorials” 1. Introduction In this post, we will apply HTTP Basic authentication to Spring REST APIs. We will also see how to test secured controllers by mocking users to test

3. Develop REST APIs

We will apply the spring security to the REST APIs we developed for ItemControllerin this post.

4. Securing Spring Controllers

Spring provides multiple methods to secure the spring controllers and methods. We will focus on HTTP Basic in this tutorial.

4.1. Default Security Provided by Spring Boot

When we include security dependency under Spring Boot 2 and not provide any security configuration, a form-based login is required to access controllers. Spring provides a user with name user and loads a random password while loading the application.

We used @WithMockUser annotation with value user that is the actual username in security configuration. Spring tests automatically use the credentials for this user when sending requests to spring controllers.

Now try to run the spring tests and it would successfully test all REST APIs.

That’s all!

2. Conclusion

In this post, we learned how to configure HTTP Basic authentication into Spring Boot 2 based REST APIs. We also saw some useful information for mocking users for Spring Boot test cases.

]]>https://www.cloudtechpro.com/spring-boot-2-http-basic-authentication/feed0Testing REST APIs using SpringRunner MockitoJUnitRunnerhttps://www.cloudtechpro.com/testing-rest-apis-spring-boot
Tue, 20 Nov 2018 13:47:59 +0000http://www.cloudtechpro.com/?p=450This is post 3 of 5 in the series “Spring Tutorials” 1. Introduction In this post, we will be testing REST APIs using SpringBootTest environment. We will also test independent services without loading the Spring Application Context. We will also

1. Introduction

In this post, we will be testing REST APIs using SpringBootTest environment. We will also test independent services without loading the Spring Application Context. We will also see how to fix execution order in test methods.

We have created test methods to test all Rest controller mappings. Because we need some records to be stored before fetch or delete operation we need to apply execution order of test methods. To control the execution order of methods we are using FixMethodOrder with NAME_ASCENDING property.

4.1. Testing Post Mappings

Let’s create a RequestBuilder for sending Post requests to the Rest controller.

]]>Developing REST APIs using Spring Boothttps://www.cloudtechpro.com/developing-rest-apis-using-spring-boot
https://www.cloudtechpro.com/developing-rest-apis-using-spring-boot#respondMon, 19 Nov 2018 11:00:07 +0000http://www.cloudtechpro.com/?p=467This is post 2 of 5 in the series “Spring Tutorials” 1. Introduction In this post, we will develop REST APIs using Spring Boot Application. We will learn how to develop REST APIs for CRUD operations using RestController mappings. You

2. Preparing Data Management Service

2.1. Creating a Bean

2.2. Creating a Service

Let’s create a service that manages the application data. As you can see, we used @Service annotation to create the service. ItemManager service contains a simple implementation of performing CRUD operations over items(Map).

6. Conclusion

In this post, we learned how to develop REST APIs using Spring Boot Application. We covered CRUD examples using RestController mappings. You also saw how to use default logging environment available in Spring Boot.

]]>https://www.cloudtechpro.com/developing-rest-apis-using-spring-boot/feed0Change Embedded Server Port under Spring Boothttps://www.cloudtechpro.com/change-embedded-server-port-under-spring-boot
https://www.cloudtechpro.com/change-embedded-server-port-under-spring-boot#respondMon, 05 Nov 2018 16:10:34 +0000http://www.cloudtechpro.com/?p=406This is post 1 of 5 in the series “Spring Tutorials” 1. Introduction In this post, we will learn different ways of changing the embedded server port for a Spring Boot application. This post covers both Spring Boot 1 and 2

1. Introduction

In this post, we will learn different ways of changing the embedded server port for a Spring Boot application. This post covers both Spring Boot 1 and 2 versions as there are different interfaces for configuring port number.

2. Using the Application Configuration File

2.1. application.properties

Spring provides server.port property that can be used to change the port.

]]>https://www.cloudtechpro.com/change-embedded-server-port-under-spring-boot/feed0Designing Custom Closable Alerts using Bootstrap 4https://www.cloudtechpro.com/designing-custom-closable-alerts-using-bootstrap-4
https://www.cloudtechpro.com/designing-custom-closable-alerts-using-bootstrap-4#respondThu, 12 Jul 2018 05:08:05 +0000http://www.cloudtechpro.com/?p=366This is post 2 of 2 in the series “Bootstrap 4 Tutorials” 1. Introduction In this article, we will learn how to create custom closable alerts by applying different colors, borders, shadows, and hover effects for Bootstrap 4 applications. We

1. Introduction

In this article, we will learn how to create custom closable alerts by applying different colors, borders, shadows, and hover effects for Bootstrap 4 applications. We will also learn how to apply different animations before disappearing alerts when a user closes the alert.

2. Overriding Color of an Alert

Overriding the color of the Bootstrap alerts is a very common requirement as per application themes. You just need to create a CSS class and must apply it to alert box. We have created a custom alert with a dark background and light text color.

3. Overriding Alert Border Radius

We can easily change the border radius of alerts by applying border-radius CSS property. Let’s see some examples by applying border-radius:unset

8px

36px

4. Shadow and Hover Effects

By default, Bootstrap alerts don’t have any shadow effects. In the above examples, we are using shadows and you can play hover shadow effects on the demo link. Let’s see the required CSS rules to create a shadow.

7. Conclusion

In this article, we focused on custom closable alerts. We have learned almost everything required including colors, borders, shadows, animations, close events. These steps will help you to get a start and design professional bootstrap alerts.

]]>https://www.cloudtechpro.com/designing-custom-closable-alerts-using-bootstrap-4/feed0Designing Responsive Login Form using Bootstrap 4https://www.cloudtechpro.com/designing-responsive-login-form-using-bootstrap-4
https://www.cloudtechpro.com/designing-responsive-login-form-using-bootstrap-4#respondTue, 10 Jul 2018 16:33:38 +0000http://www.cloudtechpro.com/?p=344This is post 1 of 2 in the series “Bootstrap 4 Tutorials” 1. Introduction In this article, we will learn how to design a responsive login form using Bootstrap 4. We will use the Bootstrap grid system to develop a responsive

1. Introduction

In this article, we will learn how to design a responsive login form using Bootstrap 4. We will use the Bootstrap grid system to develop a responsive login form and apply a super clean CSS to make it beautiful and professional.

All other styling classes are available in the attached CSS file with the developed login form and available on GitHub.

I hope this post will help you to understand the basics of designing a login form. Enjoy!

4. Conclusion

In this article, we have learned how to design a responsive login form using Bootstrap 4. We developed a login form using the Bootstrap grid system and made it beautiful and professional by applying CSS.

]]>https://www.cloudtechpro.com/designing-responsive-login-form-using-bootstrap-4/feed0Java 8 Stream API Explainedhttps://www.cloudtechpro.com/java-8-stream-api-explained
https://www.cloudtechpro.com/java-8-stream-api-explained#respondSun, 08 Jul 2018 12:27:46 +0000http://www.cloudtechpro.com/?p=2651. Introduction This article explains Java 8 Stream API with different examples. We will learn how to perform different operations using the stream() method. 2. Stream Initialization Java provides different ways to initialize a stream. Let’s see the most useful

]]>https://www.cloudtechpro.com/java-8-stream-api-explained/feed0Angular Application Loader Animation Stylinghttps://www.cloudtechpro.com/angular-application-loader-animation-styling
https://www.cloudtechpro.com/angular-application-loader-animation-styling#respondFri, 06 Jul 2018 13:13:24 +0000http://www.cloudtechpro.com/?p=3221. Introduction In this article, we will learn how to show loader animation while Angular application startup. We will use CSS styling that would only apply to our application loader page. 2. Requirement While loading Angular applications by default it

In this article, we will learn how to show loader animation while Angular application startup. We will use CSS styling that would only apply to our application loader page.

2. Requirement

While loading Angular applications by default it shows a blank page. The load time depends on the size of the application along with dependencies. It is better to show some loader animation to users if startup takes a long time on slow networks otherwise, some of the audience may close the session by thinking the application is broken or under process.

In our example, we will edit the default index.html file that serves a blank page and applies CSS styling to show animation until application startup completes. Let’s see how it looks:

Angular startup loader animation screen

3. Setup

Let’s use Angular CLI to generate a new project. To build our sample application, we used Angular CLI 6 to create the Angular project.

4. Prepare Loader Screen Styling

Let’s create the required CSS classes we need to show the loader animation.

There are different ways we can add loader CSS to the Angular application. We can create a new stylesheet file or another approach is to create a new inline CSS under index.html. In our sample project, we are appending loader styling to index.html.

Next, we need to include loader animation CSS classes under <app-root> tag. Let’s append the required tags and label.

Now, we are ready to launch the Angular application with a nice application startup loader screen. Let’s start the application and you will see a loader animation at the center of the web page.

In case your application loads fast and you are not able to see the loading screen use F12 and try to configure your browser to perform slowly by changing Network type. In my case, I tested using Google Chrome.

5. Conclusion

In the above article, we learned how to efficiently apply loader animation while Angular application startup. We applied CSS that only applied to loader page.

As always the full source of the sample project can be found over on GitHub.

]]>https://www.cloudtechpro.com/angular-application-loader-animation-styling/feed0How to Find a Class with Eclipsehttps://www.cloudtechpro.com/how-to-find-a-class-with-eclipse
https://www.cloudtechpro.com/how-to-find-a-class-with-eclipse#respondSun, 24 Jun 2018 12:59:03 +0000http://www.cloudtechpro.com/?p=2541. Introduction In this post, we’ll look at different ways to find a class under Eclipse. 2. Supported Eclipse Versions All the examples provided in this article are executed under Eclipse Luna Service Release 2 (4.4.2). The key bindings used

2. Supported Eclipse Versions

The key bindings used in examples are same for all eclipse versions. We are assuming that you are using default key bindings provided by Eclipse.

Shortcuts used in examples can be OS dependent. For example, in case of MacOS Cmd will be used instead of the Ctrl key.

3. Using Open Type Dialog

Eclipse provides an Open Type dialog to search for types. You can open this dialog from Navigate menu or by using shortcut Shift+Ctrl+T. Typically, a type can be a Class, Interface, Enum or Annotation.

Open Type dialog shows results when you type a name prefix or provide a wildcard or a camel case pattern. Let’s see some examples.

3.1. Name Prefix Search

Let’s enter the name prefix of the class CloudTech as input. As a result, we’ll get a list of classes whose names start with CloudTech:

Eclipse open type search

3.2. Wildcard Search

Sometimes, we only remember a part of a class name. In that case, we can use a ‘*’ wildcard to represent the unknown name section. We can use Cloud*Pro to find all types starting with Cloud and having Pro after it:

Eclipse open type search wildcard

3.3. Camel Case Search

We can also use Camel case search. Let’s enter CTPA to find all types containing upper-case letters:

Eclipse open type search camel case

Note that you can even mix wildcards and camel case search, to get the most out of this functionality.

4. Using Open Type in Hierarchy Dialog

You can open this dialog from the Navigate menu, or by using the shortcut Shift+Ctrl+H.

It works in the same way as Open Type dialog, but it also provides a Type Hierarchy view.

Eclipse open type hierarchy search

5. Using Java Search

Eclipse provides a Search dialog that can be used to search for declarations. You can open this dialog from the Search menu, or by using a shortcut Ctrl+H. Now, let’s open the Java Search tab since we want to search for Java elements.

We can filter different kinds of Java elements using Search For filter. We will continue with default Type as it is suitable for searching class.

Under Limit To the default is All occurrences. In our case, we don’t need References and Implementors, so we’ll select the Declarations filter to show only Java declarations.

We can use the Scope and Search In options to define the search scope. For now, let’s leave the default values.

Let’s enter CTPA to search for camel case types. After submitting the search, we’ll get a list of types including CloudTechProApp.

Eclipse java search

6. Using Open Declaration

Sometimes, we need to open a declaration while editing a Java file. We can open a declaration by clicking on Open Declaration item under Navigate menu, or by using the key binding F3. Another option is to hold down the Ctrl key and to click on the class you want to open.

To make it work, we need to highlight the Java element in the editor, by placing the cursor over it:

Eclipse open declaration search

This command also works with methods and fields.

7. Using Open Type Hierarchy

Similar to the previous example, hitting F4 or selecting Open Type Hierarchy item under Navigate menu while the cursor is on the type in the editor, will show that class in the Type Hierarchy view:

Eclipse Open Type Hierarchy Search

8. Conclusion

In this article, we’ve seen several ways how to find a class using Eclipse, how to see the class in the hierarchy view, and how to trigger those options using menu and keyboard shortcuts.