package ch.born.wte.ui.server.services;

import java.util.logging.Logger;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

@ControllerAdvice
@ResponseBody
public class RestExceptionHandler {

	@Autowired
	FileUploadResponseFactory fileUploadResponseFactory;
	
	private final Logger logger = Logger.getLogger(getClass().getName());
	
	@ExceptionHandler(MaxUploadSizeExceededException.class)
	public String handleMaxUploadSizeExceededException(final MaxUploadSizeExceededException e) {
		logger.warning("MaxUploadSizeExceededException: " + e.getLocalizedMessage());
		return fileUploadResponseFactory.createJsonErrorResponse(MessageKey.UPLOADED_FILE_TOO_LARGE);
	}
	
	@Order(Ordered.LOWEST_PRECEDENCE)
	@ExceptionHandler(RuntimeException.class)
	public String handleRuntimeException(final RuntimeException e) {
		logger.warning("RuntimeException: " + e.getLocalizedMessage());
		return fileUploadResponseFactory.createJsonErrorResponse(MessageKey.INTERNAL_SERVER_ERROR);
	}
}

@@ -45,34 +45,57 @@
 ort 
-java.util.logging.Logger;%0A
+org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0Aimp
@@ -436,16 +436,140 @@
 seBody;%0A
+import org.springframework.web.context.request.NativeWebRequest;%0Aimport org.springframework.web.context.request.WebRequest;%0A
 import o
@@ -716,16 +716,24 @@
 owired%0A%09
+private 
 FileUplo
@@ -777,17 +777,16 @@
 actory;%0A
-%09
 %0A%09privat
@@ -815,16 +815,23 @@
 = Logger
+Factory
 .getLogg
@@ -847,22 +847,11 @@
 ss()
-.getName()
 );%0A
-%09
 %0A%09@E
@@ -998,89 +998,106 @@
 on e
-) %7B%0A%09%09logger.warning(%22MaxUploadSizeExceededException: %22 + e.getLocalizedMessage()
+, WebRequest request) %7B%0A%09%09logger.warn(%22Uploaded file to big from %7B%7D: %22, request.getRemoteUser(), e
 );%0A%09
@@ -1194,17 +1194,16 @@
 GE);%0A%09%7D%0A
-%09
 %0A%09@Order
@@ -1339,75 +1339,119 @@
 on e
-) %7B%0A%09%09logger.warning(%22RuntimeException: %22 + e.getLocalizedMessage()
+, NativeWebRequest request) %7B%0A%09%09logger.error(%22error on processing request from %7B%7D %22, request.getRemoteUser(), e
 );%0A%09

change logger from jdk to slf4j