A RESTful webservice that creates screenshots of web pages and stores them in the application folder.
- Java 11
- Maven 3
- Spring 5
- Spring Boot 2
- Google Cloud Platform
- JPA, Hibernate
- MySQL 8
- Selenium
- JUnit 5
- Spring WebTestClient
The application runs on port 8080.
To change the port, go to .src/main/resources/application.properties and change the value of the server.port
property.
-
MySQL Server (locally): https://dev.mysql.com/doc/refman/8.0/en/installing.html
-
MySQL Workbench (or another MySQL client application) https://dev.mysql.com/doc/workbench/en/
Run both applications.
The database is called "screenshotter" and runs on port 3306. To change these settings, go to .src/main/resources/application.properties.
Open a MySQL client and establish the connection to the database.
Open a terminal (command prompt in Microsoft Windows) and open the MySQL client as a user who can create new users. For example, on a Linux system, use the following command:
sudo mysql --password
To create a new database, run the following commands at the mysql prompt:
- to create the new database:
mysql> create database screenshotter;
- to create the user:
mysql> create user 'user'@'%' identified by '123';
- to give all privileges to the new user on the newly created database
mysql> grant all on screenshotter.* to 'user'@'%';
Hibernate automatic schema creation is disabled:
spring.jpa.hibernate.ddl-auto=none
Initial schema and data is populated via src/main/resources/data.sql script
spring.sql.init.mode=always
To change these settings, go to .src/main/resources/application.properties.
Build the project and run all unit tests:
mvn clean install
Build without unit tests:
mvn clean install -Dmaven.test.skip=true
The project can be run as a Spring Boot app by using the main class - ScreenshotterApp.java.
To run the project from the command line, use the Maven command:
mvn spring-boot:run
To access the application open http://localhost:8080/screenshotter/screenshots/. A JSON representation of several screenshots will be shown. For the first run after installation, the list will be empty.
To create a screenshot of the Apple.com webpage, use an application that can send HTTP requests, for example, Postman. Send a POST request containing "http://apple.com" as plain text in the body.
To see a screenshot with id 1, call the http://localhost:8080/screenshotter/screenshots/1 URL.
Get all screenshots (Run the curl command in a new tab)
curl --request GET \
--url http://localhost:8080/screenshotter/screenshots/ \
--header 'content-type: application/json'
Create a screenshot of the Apple.com webpage (Run the curl command in a new tab)
curl --request POST \
--url http://localhost:8080/screenshotter/screenshots/ \
--header 'content-type: text/plain' \
--data "http://apple.com"
docker build --tag screenshotter .
docker run -d -p 8080:8080 screenshotter
Go in to the container’s file system
docker run -ti --entrypoint /bin/sh screenshotter
See the logs of the running container
docker logs -f [container_name]