shinchik17 / weather-app

http://147.45.240.22/weather-app/
0 stars 0 forks source link

Weather App

Java CI with Gradle Docker image build and push

Home page view

Overview

A web application for viewing current weather. The user can register and add one or multiple locations (cities, villages, or other places) to their collection. Afterward, the main page of the application will display a list of user places with their current weather.

The technical requirements for this project can be found here.

Index

Technologies and frameworks

Logic layer:

Data access layer:

Frontend:

Testing:

Deploy:

Monitoring:

Miscellaneous:

Application features

1. User-related:

2. Location-related:

3. Developer-related

Interface overview

The app contains five pages:

They relate with each other as shown below.

Pages relations

Default and home page are placed on the same URL - application context path (by default is '/weather-app/').
Log in and registration pages are inaccessible until user have active session.

Implementation details

1. Filters

There are four HttpFilters used in project. Their relations are shown below.

Filters scheme

1.1 BaseFilter

BaseFilter handles all requests to the application. It passes request to the next filter if it has a valid servlet path, which are:

BaseFilter redirect to the default page all requests which are not in list above. Except requests to static resources. They are just going through filter.

1.2 AuthFilter

This filter prevent authorized users with active session from navigating to registration or log in pages. It redirects such requests to home page.

1.3 ProtectedUrlFilter

ProtectedUrlFilter filter prohibit unauthorized users to go to search locations or log out. It redirects such requests to default page.

1.4 HomeFilter

HomeFilter implement quite a similar function but only for empty servlet path (default and home page URL).

The need for such separate filter is due to its servlet path. Empty servlet path cannot be used as UrlPattern for filter (as we can do for "/search-results" and "/logout"), because it is causes matching all requests (as well as BaseFilter does).

That's why HomeFilter was implemented without using UrlPattern property, and it matches only the HomeServlet. HomeServlet handles both the default and home pages so logics of ProtectedUrlFilter and HomeFilter differs a little bit too.

2. Servlets

2.1 BaseServlet

Abstract parent class for all servlets. Encapsulate work with Thymeleaf engine and some other common stuff.

2.2 HomeServlet

Method doGet() serves for representing home page with location cards containing weather for authorized users and default page for unauthorized users.
Method doDelete() serves for removing location from user's tracking list.

2.3 Auth servlets

Auth servlets is a group of servlets responsible for authentication. They are:

2.4 SearchLocationServlet

Method doGet() serves for representing page with location cards which were found by user entered search string. Method doPost() serves for adding selected location to tracking list for locations which are shown on the home page.

Deploy guide

Prerequisites:

Installation:

  1. Clone or download project

    git clone https://github.com/shinchik17/weather-app.git
  2. Navigate to the project directory

    cd weather-app
  3. Create file ".env" containing:

    BCRYPT_SALT=
    WEATHER_API_KEY=
    DS_PASSWORD=
    DS_URL='jdbc:postgresql://db:5432/postgres'
    GRAFANA_PASS=

Where:

*It is better to add quotes at the edges of variables values, because some of them (BCRYPT_SALT to be precise) could contain signs that may be interpreted wrong by shell.

  1. Change prometheus password in web.yaml. It must be a bcrypt hash (it also may be generated here).
  2. Ensure that ports 80, 3000, 9090 and 9001 are free on your local machine.
  3. Run multi-container application by following command:
docker compose --env-file .env up -d

After that services will be accessible at:

  1. Configure Grafana dashboard.
    JMX exporter by default configured so that be compatible with this Apache Tomcat dashboard. So the easiest way is to import it by link or ID 19532. Nevertheless, it is also possible to create your own custom dashboards and panels using JMX metrics info at http://localhost:9001/metrics

  2. Enjoy :D

*You may also change all used in docker containers ports. But it needs a little bit more efforts. You need to:

Acknowledgements

I would like to express my gratitude to Sergey Zhukov, the author of technical requirements, and Aleksei Osadchii, who tested the application and reviewed the code.