Example usage for org.springframework.web.client HttpStatusCodeException getCause

List of usage examples for org.springframework.web.client HttpStatusCodeException getCause

Introduction

In this page you can find the example usage for org.springframework.web.client HttpStatusCodeException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:am.ik.categolj2.app.authentication.AuthenticationController.java

@RequestMapping(value = "login", method = RequestMethod.POST)
String login(@RequestParam("username") String username, @RequestParam("password") String password,
        UriComponentsBuilder builder, RedirectAttributes attributes, HttpServletRequest request,
        HttpServletResponse response) throws IOException {
    logger.info("attempt to login (username={})", username);
    String tokenEndpoint = builder.path("oauth/token").build().toUriString();
    HttpEntity<MultiValueMap<String, Object>> ropRequest = authenticationHelper.createRopRequest(username,
            password);//from   w w  w  .j  ava2 s  . c om
    try {
        ResponseEntity<OAuth2AccessToken> result = restTemplate.postForEntity(tokenEndpoint, ropRequest,
                OAuth2AccessToken.class);
        OAuth2AccessToken accessToken = result.getBody();
        authenticationHelper.saveAccessTokenInCookie(accessToken, response);
        authenticationHelper.writeLoginHistory(accessToken, request, response);
    } catch (HttpStatusCodeException e) {
        authenticationHelper.handleHttpStatusCodeException(e, attributes);
        return "redirect:/login";
    } catch (ResourceAccessException e) {
        // I/O error on POST request for "https://xxxx:8080/oauth/token":Unrecognized SSL message, plaintext connection?
        if (e.getCause() instanceof SSLException) {
            // fallback to another port
            UriComponentsBuilder b = builder.replacePath("").port(httpsPort);
            return login(username, password, b, attributes, request, response);
        } else {
            throw e;
        }
    }
    return "redirect:/admin";
}