This project demonstrates the Chain of Responsibility Pattern in a Spring Boot application.
The goal is to resolve which hashing algorithm (e.g., MD5, SHA1, SHA256, etc.) was used to generate a given hash, based on the provided plain text.
The API accepts a plain text input and a hash value. Each handler in the chain (representing a hash algorithm) checks whether the given text, when hashed using its algorithm, matches the provided hash value.
If a match is found, the API returns the matching algorithm type — otherwise, the next handler takes over.
The Chain of Responsibility pattern is used to decouple senders and receivers of requests.
Each handler in the chain decides either to handle the request or to pass it to the next handler.
In this project:
- Each handler represents a hash algorithm (e.g., MD5, SHA-1, SHA-256, etc.)
- The chain continues until a match is found or no algorithms match.
- The chain is orchestrated by the
HashResolveChainOrchestrator, which dynamically builds the handler chain based on each algorithm’s hash length during the application’s startup (@PostConstruct). This means the service layer does not interact with individual handlers directly — all hash checks are performed through the orchestrator.
The following algorithms are currently implemented in the chain:
| Algorithm | Class |
|---|---|
| MD5 | MD5HashResolveChainHandler |
| SHA-1 | SHA1HashResolveChainHandler |
| SHA-224 | SHA224HashResolveChainHandler |
| SHA-256 | SHA256HashResolveChainHandler |
| SHA-384 | SHA384HashResolveChainHandler |
| SHA-512 | SHA512HashResolveChainHandler |
💡 You can extend the project by implementing the missing SHA3-224, SHA3-256, SHA3-384 and SHA3-512 handlers. Try creating your own handler classes!
curl --location 'http://localhost:8080/hash/resolve' \
--header 'Content-Type: application/json' \
--data '{
"text": "hello world",
"hash": "5eb63bbbe01eeed093cb22bb8f5acdc3"
}'{
"algorithm": "MD5"
}git clone https://github.com/ercansormaz/chain-of-responsibility-pattern.git
cd chain-of-responsibility-patternmvn clean installmvn spring-boot:runYou can read a detailed explanation of this project and the Chain of Responsibility Pattern in the blog post here:
👉 Read the Blog Post
Contributions are welcome! Feel free to fork the repo, submit pull requests or open issues.
This project is licensed under the MIT License.