List of usage examples for org.springframework.http HttpStatus valueOf
public static HttpStatus valueOf(int statusCode)
From source file:com.surevine.alfresco.audit.listeners.AbstractAuditEventListener.java
/** * Default implementation, uses the response code to make an assertion on whether success is achieved. * /* w w w. j a v a 2 s . c o m*/ * @throws JSONException * @throws IOException * * @see com.surevine.alfresco.audit.listeners.AuditEventListener#decideSuccess(com.surevine.alfresco.audit.BufferedHttpServletResponse, * com.surevine.alfresco.audit.Auditable) */ public void decideSuccess(final BufferedHttpServletResponse response, final Auditable audit) throws JSONException, IOException { HttpStatus responseStatus = HttpStatus.valueOf(response.getStatus()); // Use the enumeration of the type to decide whether or not a failure response should be signalled. switch (responseStatus.series()) { case CLIENT_ERROR: case SERVER_ERROR: audit.setSuccess(false); audit.setDetails(responseStatus.value() + ": " + responseStatus.name()); break; default: audit.setSuccess(true); break; } }
From source file:org.ng200.openolympus.controller.OlympusErrorController.java
private HttpStatus getStatus(final Integer value) { try {//w w w . j a v a 2 s . c o m return HttpStatus.valueOf(value); } catch (final Exception ex) { return HttpStatus.INTERNAL_SERVER_ERROR; } }
From source file:io.github.howiefh.jeews.modules.oauth2.controller.AccessTokenController.java
private HttpEntity<String> buildInvalidClientIdResponse() throws OAuthSystemException { OAuthResponse response = OAuthASResponse.errorResponse(HttpServletResponse.SC_BAD_REQUEST) .setError(OAuthError.TokenResponse.INVALID_CLIENT) .setErrorDescription(Constants.INVALID_CLIENT_DESCRIPTION).buildJSONMessage(); return new ResponseEntity<String>(response.getBody(), HttpStatus.valueOf(response.getResponseStatus())); }
From source file:com.envision.envservice.service.SAPService.java
private SAPResponse buildSAPResponse(HttpResponse response) throws Exception { int statusCode = response.getStatusLine().getStatusCode(); String content = IOUtils.toString(response.getEntity().getContent()); return new SAPResponse(HttpStatus.valueOf(statusCode), content); }
From source file:org.trustedanalytics.servicecatalog.service.RestErrorHandler.java
@ExceptionHandler(CloudFoundryException.class) public void handleCloudFoundryException(CloudFoundryException e, HttpServletResponse response) throws IOException { ErrorLogger.logAndSendErrorResponse(LOGGER, response, HttpStatus.valueOf(e.getHttpCode()), e.getMessage(), e);/*w w w . j a v a 2 s. c o m*/ }
From source file:org.awesomeagile.webapp.security.BasicSecurityConfigTest.java
/** * Returns a ResultMatcher that asserts that the result status is either 200 (Ok) or 404 (Not Found). * * @return a ResultMatcher//ww w . j ava 2 s . co m */ private ResultMatcher isOkOrNotFound() { return new ResultMatcher() { @Override public void match(MvcResult result) throws Exception { HttpStatus status = HttpStatus.valueOf(result.getResponse().getStatus()); assertTrue("Response status", status == HttpStatus.OK || status == HttpStatus.NOT_FOUND); } }; }
From source file:io.github.howiefh.jeews.modules.oauth2.controller.AccessTokenController.java
private HttpEntity<String> buildInvalidClientSecretResponse() throws OAuthSystemException { OAuthResponse response = OAuthASResponse.errorResponse(HttpServletResponse.SC_UNAUTHORIZED) .setError(OAuthError.TokenResponse.UNAUTHORIZED_CLIENT) .setErrorDescription(Constants.INVALID_CLIENT_DESCRIPTION).buildJSONMessage(); return new ResponseEntity<String>(response.getBody(), HttpStatus.valueOf(response.getResponseStatus())); }
From source file:org.osiam.addons.selfadministration.controller.LostPasswordController.java
/** * This endpoint generates an one time password and send an confirmation email including the one time password to * users primary email//from w w w . j av a 2s .c o m * * @param authorization * authZ header with valid access token * @param userId * the user id for whom you want to change the password * @return the HTTP status code * @throws IOException * @throws MessagingException */ @RequestMapping(value = "/lost/{userId}", method = RequestMethod.POST, produces = "application/json") public ResponseEntity<String> lost(@RequestHeader("Authorization") final String authorization, @PathVariable final String userId) throws IOException, MessagingException { // generate one time password String newOneTimePassword = UUID.randomUUID().toString(); UpdateUser updateUser = getPreparedUserForLostPassword(newOneTimePassword); User updatedUser; try { String token = RegistrationHelper.extractAccessToken(authorization); AccessToken accessToken = new AccessToken.Builder(token).build(); updatedUser = connectorBuilder.createConnector().updateUser(userId, updateUser, accessToken); } catch (OsiamRequestException e) { LOGGER.log(Level.WARNING, e.getMessage()); return getErrorResponseEntity(e.getMessage(), HttpStatus.valueOf(e.getHttpStatusCode())); } catch (OsiamClientException e) { return getErrorResponseEntity(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } Optional<Email> email = SCIMHelper.getPrimaryOrFirstEmail(updatedUser); if (!email.isPresent()) { String errorMessage = "Could not change password. No email of user " + updatedUser.getUserName() + " found!"; LOGGER.log(Level.WARNING, errorMessage); return getErrorResponseEntity(errorMessage, HttpStatus.BAD_REQUEST); } String passwordLostLink = RegistrationHelper.createLinkForEmail(passwordlostLinkPrefix, updatedUser.getId(), "oneTimePassword", newOneTimePassword); Map<String, Object> mailVariables = new HashMap<>(); mailVariables.put("lostpasswordlink", passwordLostLink); mailVariables.put("user", updatedUser); Locale locale = RegistrationHelper.getLocale(updatedUser.getLocale()); try { renderAndSendEmailService.renderAndSendEmail("lostpassword", fromAddress, email.get().getValue(), locale, mailVariables); } catch (OsiamException e) { return getErrorResponseEntity("Problems creating email for lost password: \"" + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } return new ResponseEntity<>(HttpStatus.OK); }
From source file:org.awesomeagile.webapp.security.BasicSecurityConfigTest.java
/** * Returns a ResultMatcher that asserts that the result status is either 401 (Unauthorized). * * @return a ResultMatcher//from w ww. java 2 s . c om */ private ResultMatcher isUnauthorized() { return new ResultMatcher() { @Override public void match(MvcResult result) throws Exception { HttpStatus status = HttpStatus.valueOf(result.getResponse().getStatus()); assertTrue("Response status", status == HttpStatus.UNAUTHORIZED); } }; }
From source file:de.metas.ui.web.config.WebuiExceptionHandler.java
private void addStatus(final Map<String, Object> errorAttributes, final RequestAttributes requestAttributes) { Integer status = null;//from w w w . j a va 2 s. c om // // Extract HTTP status from EXCEPTION_HTTPSTATUS map final Throwable error = getError(requestAttributes); if (error != null) { final Class<? extends Throwable> errorClass = error.getClass(); status = EXCEPTION_HTTPSTATUS.entrySet().stream().filter(e -> isErrorMatching(e.getKey(), errorClass)) .map(e -> e.getValue().value()).findFirst().orElse(null); } // // Extract HTTP status from attributes if (status == null) { status = getAttribute(requestAttributes, RequestDispatcher.ERROR_STATUS_CODE); } if (status == null) { errorAttributes.put(ATTR_Status, 999); errorAttributes.put(ATTR_Error, "None"); return; } errorAttributes.put(ATTR_Status, status); try { errorAttributes.put(ATTR_Error, HttpStatus.valueOf(status).getReasonPhrase()); } catch (final Exception ex) { // Unable to obtain a reason errorAttributes.put(ATTR_Error, "Http Status " + status); } }