generated from lernejo/maven-starter-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6ee9ed
commit 9863504
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/main/java/fr/lernejo/todo/ApplicationIdentifierFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package fr.lernejo.todo; | ||
|
||
import jakarta.servlet.*; | ||
import jakarta.servlet.Filter; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.springframework.stereotype.Component; | ||
import java.io.IOException; | ||
import java.util.UUID; | ||
|
||
@Component | ||
public class ApplicationIdentifierFilter implements Filter { | ||
private final String instanceId; | ||
|
||
public ApplicationIdentifierFilter() { | ||
this.instanceId = UUID.randomUUID().toString(); | ||
//System.out.println("Your UUID is: " + instanceId); | ||
} | ||
|
||
@Override | ||
public void init(FilterConfig filterConfig) throws ServletException { | ||
Filter.super.init(filterConfig); | ||
} | ||
|
||
@Override | ||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { | ||
//HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse; | ||
if (servletResponse instanceof HttpServletResponse httpServletResponse) { | ||
httpServletResponse.setHeader( | ||
"Instance-Id", instanceId); | ||
} | ||
filterChain.doFilter(servletRequest, servletResponse); | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
Filter.super.destroy(); | ||
} | ||
} |