Example usage for org.springframework.http HttpStatus series

List of usage examples for org.springframework.http HttpStatus series

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus series.

Prototype

public Series series() 

Source Link

Document

Return the HTTP status series of this status code.

Usage

From source file:org.craftercms.profile.controllers.rest.ExceptionHandlers.java

protected ResponseEntity<Object> handleExceptionInternal(Exception ex, HttpHeaders headers, HttpStatus status,
        ErrorCode errorCode, WebRequest request) {
    if (status.series() == HttpStatus.Series.SERVER_ERROR) {
        logger.error(LOG_KEY_REST_ERROR, ex, ((ServletWebRequest) request).getRequest().getRequestURI(),
                status);//from w  w  w.j  a  va 2s  . c  om
    } else {
        logger.debug(LOG_KEY_REST_ERROR, ex, ((ServletWebRequest) request).getRequest().getRequestURI(),
                status);
    }

    return new ResponseEntity<Object>(new ErrorDetails(errorCode, ex.getLocalizedMessage()), headers, status);
}

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 ww .ja v  a2 s . c om*/
 * @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:nl.gridshore.nosapi.impl.NosApiResponseErrorHandler.java

@Override
public void handleError(ClientHttpResponse response) throws IOException {
    logger.debug("Handle error '{}' received from the NOS server.", response.getStatusCode().name());
    HttpStatus statusCode = response.getStatusCode();
    MediaType contentType = response.getHeaders().getContentType();
    Charset charset = contentType != null ? contentType.getCharSet() : null;
    byte[] body = FileCopyUtils.copyToByteArray(response.getBody());

    switch (statusCode) {
    case BAD_REQUEST:
    case UNAUTHORIZED:
    case FORBIDDEN:
        throwClientException(charset, body);
    default:/*from  w ww.  j  a  va2 s .c o  m*/
        // do nothing, let the series resolving do it' work
    }

    switch (statusCode.series()) {
    case CLIENT_ERROR:
        throw new HttpClientErrorException(statusCode, response.getStatusText(), body, charset);
    case SERVER_ERROR:
        throw new HttpServerErrorException(statusCode, response.getStatusText(), body, charset);
    default:
        throw new RestClientException("Unknown status code [" + statusCode + "]");
    }
}

From source file:com.appglu.impl.AppGluResponseErrorHandler.java

public void handleError(ClientHttpResponse response) throws IOException {
    HttpStatus statusCode = response.getStatusCode();

    Error error = this.readErrorFromResponse(response);

    if (statusCode == HttpStatus.NOT_FOUND) {
        throw new AppGluHttpNotFoundException(error);
    }//from w ww  .  j  av  a  2s  .co  m

    if (error.getCode() == ErrorCode.APP_USER_UNAUTHORIZED) {
        throw new AppGluHttpUserUnauthorizedException(error);
    }

    if (error.getCode() == ErrorCode.APP_USER_USERNAME_ALREADY_USED) {
        throw new AppGluHttpInvalidUserSignupException(statusCode.value(), error);
    }

    if (error.getCode() == ErrorCode.INCOMPATIBLE_CLIENT_VERSION) {
        throw new AppGluHttpIncompatibleClientVersionException(error);
    }

    switch (statusCode.series()) {
    case CLIENT_ERROR:
        throw new AppGluHttpClientException(statusCode.value(), error);
    case SERVER_ERROR:
        throw new AppGluHttpServerException(statusCode.value(), error);
    default:
        throw new AppGluHttpStatusCodeException(statusCode.value(), error);
    }
}

From source file:org.zalando.riptide.SeriesSelector.java

@Override
public Optional<HttpStatus.Series> attributeOf(final ClientHttpResponse response) throws IOException {
    return Optional.of(response.getStatusCode().series());
}

From source file:org.zalando.riptide.Conditions.java

public static UntypedCondition<HttpStatus.Series> anySeries() {
    return any(HttpStatus.Series.class);
}

From source file:nu.yona.server.rest.RestClientErrorHandler.java

private Optional<ErrorResponseDto> getYonaErrorResponse(ClientHttpResponse response) {
    try {//from  w  w  w.  j ava2 s  .co  m
        if (getStatusCode(response).series() == HttpStatus.Series.CLIENT_ERROR) {
            return Optional.ofNullable(objectMapper.readValue(response.getBody(), ErrorResponseDto.class));
        }
    } catch (IOException e) {
        // Ignore and just return empty
    }
    return Optional.empty();
}

From source file:org.jasig.portlet.notice.service.ssp.MarkTaskCompletedAction.java

@Override
public void invoke(ActionRequest req, ActionResponse res) throws IOException {
    ResponseEntity<String> updateResponse = null;

    @SuppressWarnings("unchecked")
    SSPApiRequest<String> updateReq = new SSPApiRequest<String>(MARK_TASK_COMPLETE_FRAGMENT, String.class)
            .setMethod(HttpMethod.PUT).addUriParameter("taskId", taskId).addUriParameter("completed", true);

    try {/*w  ww  .j  a  va  2 s . co m*/
        // since these may be serialized and cached, need to actually look up the
        // service vs. injecting it or passing it in.
        ISSPApi sspApi = SSPApiLocator.getSSPApi();
        updateResponse = sspApi.doRequest(updateReq);
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    }

    if (updateResponse != null && updateResponse.getStatusCode().series() != HttpStatus.Series.SUCCESSFUL) {
        throw new RuntimeException("Error updating task: " + updateResponse.getBody());
    }
}

From source file:nu.yona.server.rest.ErrorLoggingFilter.java

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) servletRequest;
    HttpServletResponse response = (HttpServletResponse) servletResponse;

    try (LoggingContext loggingContext = LoggingContext.createInstance(request)) {
        chain.doFilter(request, response);
        Series responseStatus = HttpStatus.Series.valueOf(response.getStatus());
        if (responseStatus == Series.SUCCESSFUL) {
            return;
        }/*from   w w w.j a v  a  2s  .  c  om*/

        logResponseStatus(request, response, responseStatus);
    }
}