{"id":27377973,"url":"https://github.com/jusexton/complex-header-validation-example","last_synced_at":"2026-04-24T16:05:53.158Z","repository":{"id":135724730,"uuid":"370877620","full_name":"jusexton/complex-header-validation-example","owner":"jusexton","description":"Example demonstrating how to validate complex header scenarios with Spring filters.","archived":false,"fork":false,"pushed_at":"2021-05-26T02:01:24.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-13T13:09:01.447Z","etag":null,"topics":["exmaple","spring-boot"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jusexton.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-05-26T01:57:02.000Z","updated_at":"2021-05-26T02:01:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"5002b3c0-6f35-46d5-8bb0-2c0b431a53bf","html_url":"https://github.com/jusexton/complex-header-validation-example","commit_stats":null,"previous_names":["jusexton/complex-header-validation-example"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jusexton/complex-header-validation-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jusexton%2Fcomplex-header-validation-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jusexton%2Fcomplex-header-validation-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jusexton%2Fcomplex-header-validation-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jusexton%2Fcomplex-header-validation-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jusexton","download_url":"https://codeload.github.com/jusexton/complex-header-validation-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jusexton%2Fcomplex-header-validation-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32230431,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T13:21:15.438Z","status":"ssl_error","status_checked_at":"2026-04-24T13:21:15.005Z","response_time":64,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["exmaple","spring-boot"],"created_at":"2025-04-13T13:09:01.549Z","updated_at":"2026-04-24T16:05:53.125Z","avatar_url":"https://github.com/jusexton.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Complex Header Validation Example\n\nExample demonstrating how to validate complex header scenarios with Spring filters.\n\n## How it Works\n\nThere are 3 main components:\n\n1. `HeaderRequirementFilter`\n2. `HeaderRequirement`\n3. `HeaderRequirementSpec`\n\n### The Filter\n\nIf you're not familiar with filters, you should probably check\nout [this article](https://tutorialspoint.com/spring_boot/spring_boot_servlet_filter.htm) before reading any further.\n\nThe `HeaderRequirementFilter` is dependent on configured header requirements and makes use of these to determine if the\nheaders on the incoming request are valid or not. If the headers are valid the chain executes normally, otherwise\na `400 Bad Request` response is sent directly from the filter implementation.\n\n### The Requirement\n\n`HeaderRequirements` simply accept a `HttpServletRequest` and produce a `Set\u003cConstraintViolation\u003cT\u003e\u003e`. The `T` in this\ncase is the `spec` that will be used to validate the header values against using a `javax.Validator`. This solution also\ncomes with a `BaseHeaderRequirement` that comes with the common validation functionality out of the box. Making your\nown `HeaderRequirement` might look like the below:\n\n```java\nimport com.sexton.example.filter.BaseHeaderRequirement;\nimport org.springframework.stereotype.Component;\n\nimport javax.servlet.http.HttpServletRequest;\n\n@Component\npublic class ExampleHeaderRequirement extends BaseHeaderRequirement\u003cExampleHeaderRequirementSpec\u003e {\n    @Override\n    protected ExampleHeaderRequirementSpec buildValidationSpec(HttpServletRequest request) {\n        return ExampleHeaderRequirementSpec.builder()\n                .name(request.getHeader(\"X-Example-Header\"))\n                .build();\n    }\n}\n```\n\nMake sure the `HeaderRequirement` is decorated with `@Component` so that it is automatically configured with Spring and\ninjected into the filter.\n\n### The Spec\n\nThe `spec` is the POJO object that the headers will be mapped too and validated by hibernate. Below is a simple example:\n\n```java\nimport lombok.Builder;\nimport lombok.Data;\n\nimport javax.validation.constraints.NotEmpty;\n\n// Spec includes example headers that an API might require\n@Data\n@Builder\npublic class ExampleHeaderRequirementSpec {\n    @NotEmpty\n    private final String example;\n}\n```\n\n## Why This Solution?\n\nIn a single project this solution is probably a good example of over engineering unless you really just want to make use\nof hibernate when validating incoming headers.\n\nThis solutions really shines as a reusable pattern due to header requirements being decoupled from the filter, and the\nability to make use of the entire hibernate validation ecosystem.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjusexton%2Fcomplex-header-validation-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjusexton%2Fcomplex-header-validation-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjusexton%2Fcomplex-header-validation-example/lists"}