Revision 60496
Added by Konstantina Galouni about 3 years ago
modules/uoa-admin-tools/trunk/src/main/java/eu/dnetlib/uoaadmintools/responses/ExceptionResponse.java | ||
---|---|---|
1 |
package eu.dnetlib.uoaadmintools.responses; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
public class ExceptionResponse { |
|
6 |
|
|
7 |
private String errorCode; |
|
8 |
private String errorMessage; |
|
9 |
private String errors; |
|
10 |
|
|
11 |
public ExceptionResponse() { |
|
12 |
} |
|
13 |
|
|
14 |
public String getErrorCode() { |
|
15 |
return errorCode; |
|
16 |
} |
|
17 |
|
|
18 |
public void setErrorCode(String errorCode) { |
|
19 |
this.errorCode = errorCode; |
|
20 |
} |
|
21 |
|
|
22 |
public String getErrorMessage() { |
|
23 |
return errorMessage; |
|
24 |
} |
|
25 |
|
|
26 |
public void setErrorMessage(String errorMessage) { |
|
27 |
this.errorMessage = errorMessage; |
|
28 |
} |
|
29 |
|
|
30 |
public String getErrors() { |
|
31 |
return errors; |
|
32 |
} |
|
33 |
|
|
34 |
public void setErrors(String errors) { |
|
35 |
this.errors = errors; |
|
36 |
} |
|
37 |
} |
modules/uoa-admin-tools/trunk/src/main/java/eu/dnetlib/uoaadmintools/responses/SingleValueWrapperResponse.java | ||
---|---|---|
1 |
package eu.dnetlib.uoaadmintools.responses; |
|
2 |
|
|
3 |
public class SingleValueWrapperResponse<T> { |
|
4 |
private T value = null; |
|
5 |
|
|
6 |
public SingleValueWrapperResponse() { } |
|
7 |
public SingleValueWrapperResponse(T value) { |
|
8 |
this.value = value; |
|
9 |
} |
|
10 |
|
|
11 |
public T getValue() { |
|
12 |
return value; |
|
13 |
} |
|
14 |
|
|
15 |
public void setValue(T value) { |
|
16 |
this.value = value; |
|
17 |
} |
|
18 |
} |
modules/uoa-admin-tools/trunk/src/main/java/eu/dnetlib/uoaadmintools/controllers/SimpleErrorController.java | ||
---|---|---|
1 |
package eu.dnetlib.uoaadmintools.controllers; |
|
2 |
import org.springframework.beans.factory.annotation.Autowired; |
|
3 |
import org.springframework.boot.autoconfigure.web.ErrorAttributes; |
|
4 |
import org.springframework.boot.autoconfigure.web.ErrorController; |
|
5 |
import org.springframework.util.Assert; |
|
6 |
import org.springframework.web.bind.annotation.CrossOrigin; |
|
7 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
8 |
import org.springframework.web.bind.annotation.RestController; |
|
9 |
import org.springframework.web.context.request.RequestAttributes; |
|
10 |
import org.springframework.web.context.request.ServletRequestAttributes; |
|
11 |
|
|
12 |
import javax.servlet.http.HttpServletRequest; |
|
13 |
import java.util.Map; |
|
14 |
|
|
15 |
/** |
|
16 |
* Created by argirok on 8/3/2018. |
|
17 |
*/ |
|
18 |
|
|
19 |
@RestController |
|
20 |
@CrossOrigin(origins = "*") |
|
21 |
@RequestMapping("/error") |
|
22 |
public class SimpleErrorController implements ErrorController { |
|
23 |
|
|
24 |
private final ErrorAttributes errorAttributes; |
|
25 |
|
|
26 |
@Autowired |
|
27 |
public SimpleErrorController(ErrorAttributes errorAttributes) { |
|
28 |
Assert.notNull(errorAttributes, "ErrorAttributes must not be null"); |
|
29 |
this.errorAttributes = errorAttributes; |
|
30 |
} |
|
31 |
|
|
32 |
@Override |
|
33 |
public String getErrorPath() { |
|
34 |
return "/error"; |
|
35 |
} |
|
36 |
|
|
37 |
@RequestMapping |
|
38 |
public Map<String, Object> error(HttpServletRequest aRequest){ |
|
39 |
Map<String, Object> body = getErrorAttributes(aRequest,getTraceParameter(aRequest)); |
|
40 |
String trace = (String) body.get("trace"); |
|
41 |
if(trace != null){ |
|
42 |
String[] lines = trace.split("\n\t"); |
|
43 |
body.put("trace", lines); |
|
44 |
} |
|
45 |
return body; |
|
46 |
} |
|
47 |
|
|
48 |
private boolean getTraceParameter(HttpServletRequest request) { |
|
49 |
String parameter = request.getParameter("trace"); |
|
50 |
if (parameter == null) { |
|
51 |
return false; |
|
52 |
} |
|
53 |
return !"false".equals(parameter.toLowerCase()); |
|
54 |
} |
|
55 |
|
|
56 |
private Map<String, Object> getErrorAttributes(HttpServletRequest aRequest, boolean includeStackTrace) { |
|
57 |
RequestAttributes requestAttributes = new ServletRequestAttributes(aRequest); |
|
58 |
return errorAttributes.getErrorAttributes(requestAttributes, includeStackTrace); |
|
59 |
} |
|
60 |
} |
Also available in: Unified diff
[Trunk | Admin Tools]:
1. Deleted folder "responses" with all its files (moved to uoa-admin-tools-library in r60105 ).
2. Deleted file "SimpleErrorController.java" (moved to uoa-admin-tools-library in r60105 ).