Project

General

Profile

« Previous | Next » 

Revision 58363

[Uoa-admin-tool|Trunk]

Properties: use classpath instead of path of specific tomcats
Recaptcha: add logs and catch exceptions

View differences:

VerifyRecaptcha.java
3 3
import eu.dnetlib.uoaadmintools.configuration.properties.GoogleConfig;
4 4
import eu.dnetlib.uoaadmintools.entities.GoogleResponse;
5 5
import eu.dnetlib.uoaadmintools.handlers.InvalidReCaptchaException;
6
import org.apache.log4j.Logger;
7
import org.apache.log4j.spi.ErrorCode;
6 8
import org.springframework.beans.factory.annotation.Autowired;
7 9
import org.springframework.beans.factory.annotation.Configurable;
8 10
import org.springframework.boot.web.client.RestTemplateBuilder;
......
17 19
@Service
18 20
@Configurable
19 21
public class VerifyRecaptcha {
20

  
22
    private final Logger log = Logger.getLogger(this.getClass());
21 23
    @Autowired
22 24
    private RestOperations restTemplate;
23 25

  
......
33 35

  
34 36
    public void processResponse(String response) throws InvalidReCaptchaException{
35 37
        if(!responseSanityCheck(response)) {
36
            throw new InvalidReCaptchaException("Response contains invalid characters");
38
            InvalidReCaptchaException e = new InvalidReCaptchaException("Response contains invalid characters");
39
            log.error("Response contains invalid characters", e);
40
            throw e;
37 41
        }
38 42

  
39 43
        URI verifyUri = URI.create(String.format(
......
43 47
        GoogleResponse googleResponse = restTemplate.getForObject(verifyUri, GoogleResponse.class);
44 48

  
45 49
        if(!googleResponse.isSuccess()) {
46
            throw new InvalidReCaptchaException("reCaptcha was not successfully validated");
50
            log.error("Has client error:"+googleResponse.hasClientError());
51
            InvalidReCaptchaException e = new InvalidReCaptchaException("reCaptcha was not successfully validated");
52
            log.error("reCaptcha was not successfully validated", e);
53
            throw e;
47 54
        }
48 55
    }
49 56

  

Also available in: Unified diff