loging partially, fox for sql way id
This commit is contained in:
1 parent
51ad0bd7a0
commit
4eb3768e12
6 files changed
+103
-13
No files matched your search
@@ -1,6 +1,5 @@
|
||||
package hello;
|
||||
|
||||
import hello.agh.edu.bazy.interceptor.RequestInterceptor;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
|
||||
@@ -18,10 +18,10 @@ public class GisDbApi {
|
||||
|
||||
private static final String GET_LAMPS = "SELECT gis_points_id,tags,st_transform(way,4326) FROM gis_points WHERE highway='street_lamp';";
|
||||
private static String PUT_LAMP = "INSERT INTO public.gis_points(gis_points_id, way, highway) VALUES (@, st_geomfromtext('POINT(@ @)',4326), 'street_lamp');";
|
||||
private static final String GET_LAMP = "SELECT gis_points_id,st_transform(way,900913) FROM gis_points WHERE gis_points_id = ?;";
|
||||
private static final String GET_LAMP = "SELECT gis_points_id,st_transform(way,4326) FROM gis_points WHERE gis_points_id = ?;";
|
||||
private static final String DELETE_LAMP = "DELETE FROM public.gis_points WHERE gis_points_id = ?";
|
||||
private static final String GET_POLYGONS = "SELECT st_transform(way,900913) as polygon FROM gis_polygons;";
|
||||
private static final String GET_POLYGON = "SELECT st_transform(way,900913) as polygon FROM gis_polygons WHERE gis_polygons_id = ?";
|
||||
private static final String GET_POLYGONS = "SELECT st_transform(way,4326) as polygon FROM gis_polygons;";
|
||||
private static final String GET_POLYGON = "SELECT st_transform(way,4326) as polygon FROM gis_polygons WHERE gis_polygons_id = ?";
|
||||
|
||||
JdbcTemplate gisJdbcTemplate;
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package hello.agh.edu.bazy.interceptor;
|
||||
|
||||
import hello.agh.edu.bazy.path.ModuleServicePaths;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Marcin on 2015-01-27.
|
||||
*/
|
||||
public class LoggingInterceptor extends HandlerInterceptorAdapter {
|
||||
public static final List<String> availableLoglevels = Arrays.asList("info", "debug", "warn", "error");
|
||||
protected RestTemplate restTemplate;
|
||||
protected String permission;
|
||||
|
||||
public LoggingInterceptor() {
|
||||
}
|
||||
|
||||
public LoggingInterceptor(String permission) {
|
||||
this.restTemplate = new RestTemplate();
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
protected boolean logEvent(String message, String logLevel, String type) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
|
||||
map.add("type", type);
|
||||
map.add("msg", message);
|
||||
|
||||
HttpEntity entity = new HttpEntity(headers);
|
||||
HttpEntity<Object> response = restTemplate.exchange(
|
||||
ModuleServicePaths.PUT_LOG
|
||||
.concat("/").concat(logLevel),
|
||||
HttpMethod.POST, entity,
|
||||
Object.class,
|
||||
map);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,11 @@
|
||||
package hello.agh.edu.bazy.interceptor;
|
||||
|
||||
|
||||
import hello.agh.edu.bazy.path.ModuleServicePaths;
|
||||
import hello.agh.edu.bazy.controllers.LoginController;
|
||||
import hello.agh.edu.bazy.path.ModuleServicePaths;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -16,16 +14,13 @@ import javax.servlet.http.HttpServletResponse;
|
||||
* Created by lukasgol on 22.01.15.
|
||||
*/
|
||||
@Component
|
||||
public class RequestInterceptor extends HandlerInterceptorAdapter {
|
||||
RestTemplate restTemplate;
|
||||
String permission;
|
||||
public class RequestInterceptor extends LoggingInterceptor {
|
||||
|
||||
public RequestInterceptor() {
|
||||
}
|
||||
|
||||
public RequestInterceptor(String permission) {
|
||||
this.restTemplate = new RestTemplate();
|
||||
this.permission = permission;
|
||||
super(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,14 +40,26 @@ public class RequestInterceptor extends HandlerInterceptorAdapter {
|
||||
if (!correctHeaders(request)) {
|
||||
System.out.println("No token in header.");
|
||||
response.sendError(HttpStatus.BAD_REQUEST.value(), "No token parameter in request header");
|
||||
logEvent("No token parameter in request header." +
|
||||
request.getRequestURI(),
|
||||
"error",
|
||||
"rest");
|
||||
return super.preHandle(request, response, handler);
|
||||
}
|
||||
|
||||
if (validToken(request.getHeader(LoginController.TOKEN))) {
|
||||
logEvent("Correct request." +
|
||||
request.getRequestURI(),
|
||||
"info",
|
||||
"rest");
|
||||
return super.preHandle(request, response, handler);
|
||||
} else {
|
||||
System.out.println("Token or permission not valid.");
|
||||
response.sendError(HttpStatus.UNAUTHORIZED.value(), "Token or permission not valid.");
|
||||
logEvent("Token or permission not valid." +
|
||||
request.getRequestURI(),
|
||||
"error",
|
||||
"rest");
|
||||
return super.preHandle(request, response, handler);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package hello.agh.edu.bazy.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
/**
|
||||
* Created by Marcin on 2015-01-27.
|
||||
*/
|
||||
public class Log {
|
||||
private String type;
|
||||
|
||||
@JsonProperty("msg")
|
||||
private String message;
|
||||
|
||||
public Log(String type, String message) {
|
||||
this.type = type;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ public final class ModuleServicePaths {
|
||||
|
||||
//LOGS
|
||||
public static final String LOGS_MODULE = ROOT + "/restlogger/logger";
|
||||
public static final String PUT_LOG = ROOT + "/restlogger/logger";
|
||||
public static final String GET_LOGS = LOGS_MODULE + "/getlog";
|
||||
|
||||
// http://10.156.207.136:8080/restlogger/logger/getlog?moduleType=gis&logLevels=debug,error
|
||||
}
|
||||
Reference in new issue
Block a user