Skip to content

Commit

Permalink
create Instance-Id
Browse files Browse the repository at this point in the history
  • Loading branch information
SquidRings1 committed Dec 4, 2024
1 parent a6ee9ed commit 9863504
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/main/java/fr/lernejo/todo/ApplicationIdentifierFilter.java
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();
}
}

0 comments on commit 9863504

Please sign in to comment.