Search in sources :

Example 51 with HttpStatus

use of org.springframework.http.HttpStatus in project pinpoint by naver.

the class ListenableFutureInterceptor method doInAfterTrace.

@Override
protected void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
    recorder.recordServiceType(RestTemplateConstants.SERVICE_TYPE);
    recorder.recordException(throwable);
    recorder.recordApi(methodDescriptor);
    if (args.length == 1 && args[0] instanceof AbstractClientHttpResponse) {
        AbstractClientHttpResponse response = (AbstractClientHttpResponse) args[0];
        try {
            HttpStatus statusCode = response.getStatusCode();
            if (statusCode != null) {
                recorder.recordAttribute(AnnotationKey.HTTP_STATUS_CODE, statusCode.value());
            }
            this.responseHeaderRecorder.recordHeader(recorder, response);
        } catch (IOException ioException) {
            logger.warn("Failed to after process. {}", ioException.getMessage(), ioException);
        }
    }
}
Also used : HttpStatus(org.springframework.http.HttpStatus) AbstractClientHttpResponse(org.springframework.http.client.AbstractClientHttpResponse) IOException(java.io.IOException)

Example 52 with HttpStatus

use of org.springframework.http.HttpStatus in project spring-boot by spring-projects.

the class ManagementWebSecurityAutoConfigurationTests method usesMatchersBasedOffConfiguredActuatorBasePath.

@Test
void usesMatchersBasedOffConfiguredActuatorBasePath() {
    this.contextRunner.withPropertyValues("management.endpoints.web.base-path=/").run((context) -> {
        HttpStatus status = getResponseStatus(context, "/health");
        assertThat(status).isEqualTo(HttpStatus.OK);
    });
}
Also used : HttpStatus(org.springframework.http.HttpStatus) Test(org.junit.jupiter.api.Test)

Example 53 with HttpStatus

use of org.springframework.http.HttpStatus in project spring-boot by spring-projects.

the class ManagementWebSecurityAutoConfigurationTests method permitAllForHealth.

@Test
void permitAllForHealth() {
    this.contextRunner.run((context) -> {
        assertThat(context).hasBean(MANAGEMENT_SECURITY_FILTER_CHAIN_BEAN);
        HttpStatus status = getResponseStatus(context, "/actuator/health");
        assertThat(status).isEqualTo(HttpStatus.OK);
    });
}
Also used : HttpStatus(org.springframework.http.HttpStatus) Test(org.junit.jupiter.api.Test)

Example 54 with HttpStatus

use of org.springframework.http.HttpStatus in project spring-boot by spring-projects.

the class WebMvcTags method uri.

/**
 * Creates a {@code uri} tag based on the URI of the given {@code request}. Uses the
 * {@link HandlerMapping#BEST_MATCHING_PATTERN_ATTRIBUTE} best matching pattern if
 * available. Falling back to {@code REDIRECTION} for 3xx responses, {@code NOT_FOUND}
 * for 404 responses, {@code root} for requests with no path info, and {@code UNKNOWN}
 * for all other requests.
 * @param request the request
 * @param response the response
 * @param ignoreTrailingSlash whether to ignore the trailing slash
 * @return the uri tag derived from the request
 */
public static Tag uri(HttpServletRequest request, HttpServletResponse response, boolean ignoreTrailingSlash) {
    if (request != null) {
        String pattern = getMatchingPattern(request);
        if (pattern != null) {
            if (ignoreTrailingSlash && pattern.length() > 1) {
                pattern = TRAILING_SLASH_PATTERN.matcher(pattern).replaceAll("");
            }
            if (pattern.isEmpty()) {
                return URI_ROOT;
            }
            return Tag.of("uri", pattern);
        }
        if (response != null) {
            HttpStatus status = extractStatus(response);
            if (status != null) {
                if (status.is3xxRedirection()) {
                    return URI_REDIRECTION;
                }
                if (status == HttpStatus.NOT_FOUND) {
                    return URI_NOT_FOUND;
                }
            }
        }
        String pathInfo = getPathInfo(request);
        if (pathInfo.isEmpty()) {
            return URI_ROOT;
        }
    }
    return URI_UNKNOWN;
}
Also used : HttpStatus(org.springframework.http.HttpStatus)

Example 55 with HttpStatus

use of org.springframework.http.HttpStatus in project spring-boot by spring-projects.

the class MyControllerAdvice method getStatus.

private HttpStatus getStatus(HttpServletRequest request) {
    Integer code = (Integer) request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
    HttpStatus status = HttpStatus.resolve(code);
    return (status != null) ? status : HttpStatus.INTERNAL_SERVER_ERROR;
}
Also used : HttpStatus(org.springframework.http.HttpStatus)

Aggregations

HttpStatus (org.springframework.http.HttpStatus)165 ResponseEntity (org.springframework.http.ResponseEntity)43 HttpHeaders (org.springframework.http.HttpHeaders)38 Test (org.junit.jupiter.api.Test)26 MediaType (org.springframework.http.MediaType)17 Mono (reactor.core.publisher.Mono)17 IOException (java.io.IOException)16 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)15 Collections (java.util.Collections)13 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 URI (java.net.URI)12 List (java.util.List)11 Optional (java.util.Optional)11 Test (org.junit.Test)11 Map (java.util.Map)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 ClassPathResource (org.springframework.core.io.ClassPathResource)9 Resource (org.springframework.core.io.Resource)9 HashMap (java.util.HashMap)8