GitHeaderInterceptor.java
1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package etunicorn;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
/**
* Created by geoffrey on 29/01/17.
*/
public class GitHeaderInterceptor extends HandlerInterceptorAdapter {
private String version = "inconnue";
public GitHeaderInterceptor() {
super();
try {
String[] commande = {"git", "describe", "--tags", "--dirty"};
Process p = Runtime.getRuntime().exec(commande);
BufferedReader output = new BufferedReader(new InputStreamReader(p.getInputStream()));
p.waitFor();
this.version = output.readLine();
} catch(IOException e) {
} catch (InterruptedException e) {
}
}
@Override
public boolean preHandle(javax.servlet.http.HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
response.addHeader("X-Version", this.version);
return super.preHandle(request, response, handler);
}
@Override
public void postHandle(javax.servlet.http.HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
super.postHandle(request, response, handler, modelAndView);
}
@Override
public void afterCompletion(javax.servlet.http.HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
super.afterCompletion(request, response, handler, ex);
}
@Override
public void afterConcurrentHandlingStarted(javax.servlet.http.HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
super.afterConcurrentHandlingStarted(request, response, handler);
}
}