Revision 39076
Added by Antonis Lempesis over 8 years ago
EmailUtilsLogger.java | ||
---|---|---|
17 | 17 |
@Component |
18 | 18 |
@Aspect |
19 | 19 |
public class EmailUtilsLogger { |
20 |
@Autowired
|
|
21 |
private MailLibrary mailLibrary;
|
|
20 |
@Autowired
|
|
21 |
private MailLibrary mailLibrary;
|
|
22 | 22 |
|
23 |
private @Value("#{cascadingPropertyLoader.properties['goldoa.debugemails']}") boolean sendEmails = false; |
|
23 |
private |
|
24 |
@Value("#{cascadingPropertyLoader.properties['goldoa.debugemails']}") |
|
25 |
boolean sendEmails = false; |
|
24 | 26 |
|
25 |
@Around("execution(public void eu.dnetlib.goldoa.service.utils.EmailUtils.send* (..))")
|
|
26 |
public Object logErrors(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
27 |
if (sendEmails) {
|
|
28 |
try {
|
|
29 |
mailLibrary.sendEmail("antleb@di.uoa.gr", "sending email: " + joinPoint.getSignature().getName(), "");
|
|
27 |
@Around("execution(public void eu.dnetlib.goldoa.service.utils.EmailUtils.send* (..))")
|
|
28 |
public Object logErrors(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
29 |
if (sendEmails) {
|
|
30 |
try {
|
|
31 |
mailLibrary.sendEmail("antleb@di.uoa.gr", "sending email: " + joinPoint.getSignature().getName(), "");
|
|
30 | 32 |
|
31 |
return joinPoint.proceed();
|
|
32 |
} catch (Throwable throwable) {
|
|
33 |
StringWriter sw = new StringWriter();
|
|
34 |
PrintWriter pw = new PrintWriter(sw);
|
|
33 |
return joinPoint.proceed();
|
|
34 |
} catch (Throwable throwable) {
|
|
35 |
StringWriter sw = new StringWriter();
|
|
36 |
PrintWriter pw = new PrintWriter(sw);
|
|
35 | 37 |
|
36 |
throwable.printStackTrace(pw);
|
|
37 |
pw.close();
|
|
38 |
throwable.printStackTrace(pw);
|
|
39 |
pw.close();
|
|
38 | 40 |
|
39 |
try {
|
|
40 |
mailLibrary.sendEmail("antleb@di.uoa.gr", "Exception in mails", sw.toString());
|
|
41 |
} catch (MessagingException e) {
|
|
42 |
e.printStackTrace();
|
|
43 |
}
|
|
41 |
try {
|
|
42 |
mailLibrary.sendEmail("antleb@di.uoa.gr", "Exception in mails", sw.toString());
|
|
43 |
} catch (MessagingException e) {
|
|
44 |
e.printStackTrace();
|
|
45 |
}
|
|
44 | 46 |
|
45 |
throw throwable;
|
|
46 |
}
|
|
47 |
} else {
|
|
48 |
return joinPoint.proceed();
|
|
49 |
}
|
|
50 |
}
|
|
47 |
throw throwable;
|
|
48 |
}
|
|
49 |
} else {
|
|
50 |
return joinPoint.proceed();
|
|
51 |
}
|
|
52 |
}
|
|
51 | 53 |
} |
Also available in: Unified diff
reformatted code