-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentSSBAccessValve.java
More file actions
44 lines (36 loc) · 1.52 KB
/
StudentSSBAccessValve.java
File metadata and controls
44 lines (36 loc) · 1.52 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
package com.test.tomcat;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.ServletException;
import org.apache.catalina.valves.ValveBase;
import org.apache.catalina.connector.Request;
import org.apache.catalina.connector.Response;
public class StudentSSBAccessValve extends ValveBase {
private static final String LOG_FILE = "/opt/tomcat/logs/student_ssb_access.log";
private static final SimpleDateFormat formatter = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss Z");
public StudentSSBAccessValve() {
super(true);
}
@Override
public void invoke(Request request, Response response) throws IOException, ServletException {
getNext().invoke(request, response); // Process the request
String uri = request.getRequestURI();
if (uri.startsWith("/StudentSelfService/ssb/*")) {
String logEntry = String.format("%{X-Forwarded-For}i %l %u %t "%r" %s",
request.getRemoteAddr(),
formatter.format(new Date()),
request.getMethod(),
uri,
request.getProtocol(),
response.getStatus(),
response.getContentLength());
try (FileWriter fw = new FileWriter(LOG_FILE, true)) {
fw.write(logEntry);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}