Java Code Examples for org.springframework.http.HttpStatus#equals()
The following examples show how to use
org.springframework.http.HttpStatus#equals() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebMvcTags.java From foremast with Apache License 2.0 | 6 votes |
/** * 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 * @return the uri tag derived from the request */ public static Tag uri(@Nullable HttpServletRequest request, @Nullable HttpServletResponse response) { if (request != null) { String pattern = getMatchingPattern(request); if (pattern != null) { return Tag.of("uri", pattern); } else if (response != null) { HttpStatus status = extractStatus(response); if (status != null && status.is3xxRedirection()) { return URI_REDIRECTION; } if (status != null && status.equals(HttpStatus.NOT_FOUND)) { return URI_NOT_FOUND; } } String pathInfo = getPathInfo(request); if (pathInfo.isEmpty()) { return URI_ROOT; } } return URI_UNKNOWN; }
Example 2
Source File: WebMvcTags.java From foremast with Apache License 2.0 | 6 votes |
/** * 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 * @return the uri tag derived from the request */ public static Tag uri(@Nullable HttpServletRequest request, @Nullable HttpServletResponse response) { if (request != null) { String pattern = getMatchingPattern(request); if (pattern != null) { return Tag.of("uri", pattern); } else if (response != null) { HttpStatus status = extractStatus(response); if (status != null && status.is3xxRedirection()) { return URI_REDIRECTION; } if (status != null && status.equals(HttpStatus.NOT_FOUND)) { return URI_NOT_FOUND; } } String pathInfo = getPathInfo(request); if (pathInfo.isEmpty()) { return URI_ROOT; } } return URI_UNKNOWN; }
Example 3
Source File: FootballEcosystem.java From football-events with MIT License | 6 votes |
public HttpStatus command(String url, HttpMethod method, String json, HttpStatus retryStatus) { logger.trace(json); HttpStatus currentStatus; long endTime = System.currentTimeMillis() + restTimeout; do { currentStatus = command(url, method, json); if (!currentStatus.equals(retryStatus)) { return currentStatus; } logger.trace("Retry status received ({}), trying again...", retryStatus); sleep(500); } while (System.currentTimeMillis() < endTime); throw new AssertionError("Response timeout, last status: " + currentStatus); }
Example 4
Source File: CommonController.java From halo with GNU General Public License v3.0 | 5 votes |
/** * Handle error * * @param request request * @return String */ @GetMapping public String handleError(HttpServletRequest request, HttpServletResponse response, Model model) { log.error("Request URL: [{}], URI: [{}], Request Method: [{}], IP: [{}]", request.getRequestURL(), request.getRequestURI(), request.getMethod(), ServletUtil.getClientIP(request)); handleCustomException(request); Map<String, Object> errorDetail = Collections.unmodifiableMap(getErrorAttributes(request, isIncludeStackTrace(request))); model.addAttribute("error", errorDetail); model.addAttribute("meta_keywords", optionService.getSeoKeywords()); model.addAttribute("meta_description", optionService.getSeoDescription()); log.debug("Error detail: [{}]", errorDetail); HttpStatus status = getStatus(request); if (status.equals(HttpStatus.INTERNAL_SERVER_ERROR)) { return contentInternalError(); } else if (status.equals(HttpStatus.NOT_FOUND)) { return contentNotFound(); } else { return defaultErrorHandler(); } }
Example 5
Source File: RemoteJobConfigurationRepository.java From spring-batch-lightmin with Apache License 2.0 | 4 votes |
private void evaluateReponse(final ResponseEntity<?> responseEntity, final HttpStatus expectedStatus) { if (!expectedStatus.equals(responseEntity.getStatusCode())) { throw new SpringBatchLightminApplicationException("Could not execute remote call HttpStatusCode: " + responseEntity.getStatusCode()); } }