Skip to content

ercansormaz/chain-of-responsibility-pattern

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Boot Chain of Responsibility Pattern Example: Hash Resolving Service

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.


How It Works

  • The API accepts a plain text and a hashed value.
  • A chain of handlers (each responsible for a different algorithm) is executed.
  • When a match is found, the chain returns the algorithm name.

API Endpoint

Example Request

curl --location 'http://localhost:8080/hash/resolve' \
--header 'Content-Type: application/json' \
--data '{
  "text": "hello world",
  "hash": "5eb63bbbe01eeed093cb22bb8f5acdc3"
}'

Example Response

{
  "algorithm": "MD5"
}

Chain of Responsibility Implementation

Each hashing algorithm is represented by a Chain Step:

  • MD5HashResolveChainStep
  • SHA1HashResolveChainStep
  • SHA224HashResolveChainStep
  • SHA256HashResolveChainStep
  • SHA384HashResolveChainStep
  • SHA512HashResolveChainStep

The chain is managed by the HashResolveChainHandler, which executes each step in order until a match is found.


Running the Project

1. Clone this repository:

git clone https://github.com/ercansormaz/chain-of-responsibility-pattern.git

2. Navigate to the project folder and build:

mvn clean install

3. Run the application:

mvn spring-boot:run

4. Test the endpoint (example above)


📚 Further Reading

You can read a detailed explanation of this project and the Chain of Responsibility Pattern in the blog post here:
👉 Read the Blog Post


🤝 Contributing

Contributions are welcome! Feel free to fork the repo, submit pull requests or open issues.


📜 License

This project is licensed under the MIT License.

About

Spring Boot project demonstrating the Chain of Responsibility Pattern

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages