Commit 9182ba39356804806230f637ccceaa31158ae0f5
1 parent
d167a387
Ça affiche le numéro de version dans les réponses !
Bon ok, c'est useless. Oui oui, les bases de données elles arrivent !
Showing
2 changed files
with
67 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,49 @@ |
1 | +package etunicorn; | |
2 | + | |
3 | +import org.springframework.web.servlet.ModelAndView; | |
4 | +import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; | |
5 | + | |
6 | +import javax.servlet.http.HttpServletResponse; | |
7 | +import java.io.*; | |
8 | + | |
9 | +/** | |
10 | + * Created by geoffrey on 29/01/17. | |
11 | + */ | |
12 | +public class GitHeaderInterceptor extends HandlerInterceptorAdapter { | |
13 | + | |
14 | + private String version = "inconnue"; | |
15 | + | |
16 | + public GitHeaderInterceptor() { | |
17 | + super(); | |
18 | + try { | |
19 | + String[] commande = {"git", "describe", "--tags", "--dirty"}; | |
20 | + Process p = Runtime.getRuntime().exec(commande); | |
21 | + BufferedReader output = new BufferedReader(new InputStreamReader(p.getInputStream())); | |
22 | + p.waitFor(); | |
23 | + this.version = output.readLine(); | |
24 | + } catch(IOException e) { | |
25 | + } catch (InterruptedException e) { | |
26 | + } | |
27 | + } | |
28 | + | |
29 | + @Override | |
30 | + public boolean preHandle(javax.servlet.http.HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | |
31 | + response.addHeader("X-Version", this.version); | |
32 | + return super.preHandle(request, response, handler); | |
33 | + } | |
34 | + | |
35 | + @Override | |
36 | + public void postHandle(javax.servlet.http.HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { | |
37 | + super.postHandle(request, response, handler, modelAndView); | |
38 | + } | |
39 | + | |
40 | + @Override | |
41 | + public void afterCompletion(javax.servlet.http.HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { | |
42 | + super.afterCompletion(request, response, handler, ex); | |
43 | + } | |
44 | + | |
45 | + @Override | |
46 | + public void afterConcurrentHandlingStarted(javax.servlet.http.HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | |
47 | + super.afterConcurrentHandlingStarted(request, response, handler); | |
48 | + } | |
49 | +} | ... | ... |
... | ... | @@ -0,0 +1,18 @@ |
1 | +package etunicorn; | |
2 | + | |
3 | +import org.springframework.context.annotation.Configuration; | |
4 | +import org.springframework.web.servlet.config.annotation.*; | |
5 | + | |
6 | +/** | |
7 | + * Created by geoffrey on 29/01/17. | |
8 | + */ | |
9 | + | |
10 | +@Configuration | |
11 | +public class WebMvcConfig extends WebMvcConfigurerAdapter { | |
12 | + | |
13 | + @Override | |
14 | + public void addInterceptors(InterceptorRegistry registry) { | |
15 | + registry.addInterceptor(new GitHeaderInterceptor()); | |
16 | + } | |
17 | +} | |
18 | + | ... | ... |