Spring Framework HttpStatus - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework HttpStatus class.

This code example shows how to use the following methods:equals, is3xxRedirection, value
			throws Exception { 
 
		String viewName = getViewName(); 
 
		if (getStatusCode() != null) { 
			if (getStatusCode().is3xxRedirection()) { 
				request.setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, getStatusCode()); 
				viewName = (viewName != null && !viewName.startsWith("redirect:") ? "redirect:" + viewName : viewName); 
			} 
			else { 
				response.setStatus(getStatusCode().value()); 
				if (isStatusOnly() || (getStatusCode().equals(HttpStatus.NO_CONTENT) && getViewName() == null)) { 
					return null; 
				} 
			} 
		} 
 
		ModelAndView modelAndView = new ModelAndView(); 
		modelAndView.addAllObjects(RequestContextUtils.getInputFlashMap(request)); 
 
8
CodeRank
This code example shows how to use the following methods:name, value
	public HttpClientErrorException(HttpStatus statusCode, String statusText) { 
		super(statusCode, statusText); 
	} 
 
	/** 
	 * Construct a new instance of {@code HttpClientErrorException} based on an 
	 * {@link HttpStatus}, status text, and response body content. 
	 * @param statusCode the status code 
	 * @param statusText the status text 
	 * @param responseBody the response body content, may be {@code null} 
	 * @param responseCharset the response body charset, may be {@code null} 
	 */ 
	public HttpClientErrorException(HttpStatus statusCode, String statusText, 
			byte[] responseBody, Charset responseCharset) { 
		super(statusCode, statusText, responseBody, responseCharset); 
	} 
 
	/** 
	 * Construct a new instance of {@code HttpClientErrorException} based on an 
	 * {@link HttpStatus}, status text, and response body content. 

7
CodeRank
This code example shows how to use the following methods:name, value
	public HttpServerErrorException(HttpStatus statusCode, String statusText) { 
		super(statusCode, statusText); 
	} 
 
	/** 
	 * Construct a new instance of {@code HttpServerErrorException} based on an 
	 * {@link HttpStatus}, status text, and response body content. 
	 * @param statusCode	  the status code 
	 * @param statusText	  the status text 
	 * @param responseBody	the response body content, may be {@code null} 
	 * @param responseCharset the response body charset, may be {@code null} 
	 * @since 3.0.5 
	 */ 
	public HttpServerErrorException(HttpStatus statusCode, String statusText, 
			byte[] responseBody, Charset responseCharset) { 
		super(statusCode, statusText, responseBody, responseCharset); 
	} 
 
	/** 
	 * Construct a new instance of {@code HttpServerErrorException} based on a 

7
CodeRank
This code example shows how to use the following methods:value
 
	@Override 
	public <T> boolean handleTimeout(NativeWebRequest request, DeferredResult<T> deferredResult) throws Exception {
		HttpServletResponse servletResponse = request.getNativeResponse(HttpServletResponse.class);
		if (!servletResponse.isCommitted()) {
			servletResponse.sendError(HttpStatus.SERVICE_UNAVAILABLE.value());
		} 
		return false; 
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:value
 
	@Override 
	public <T> Object handleTimeout(NativeWebRequest request, Callable<T> task) throws Exception {
		HttpServletResponse servletResponse = request.getNativeResponse(HttpServletResponse.class);
		if (!servletResponse.isCommitted()) {
			servletResponse.sendError(HttpStatus.SERVICE_UNAVAILABLE.value());
		} 
		return CallableProcessingInterceptor.RESPONSE_HANDLED;
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:name, value
	 * Construct a new instance of {@code HttpStatusCodeException} based on an 
	 * {@link HttpStatus}. 
	 * @param statusCode the status code 
	 */ 
	protected HttpStatusCodeException(HttpStatus statusCode) {
		this(statusCode, statusCode.name(), null, null, null);
	} 
 
	/** 
	 * Construct a new instance of {@code HttpStatusCodeException} based on an 
	 * {@link HttpStatus} and status text. 
	 * @param statusCode the status code 
	 * @param statusText the status text 
	 */ 
	protected HttpStatusCodeException(HttpStatus statusCode, String statusText) {
		this(statusCode, statusText, null, null, null);
	} 
 
	/** 
	 * Construct a new instance of {@code HttpStatusCodeException} based on an 

6
CodeRank
This code example shows how to use the following methods:is3xxRedirection
	 * 
	 * <p>If not set, {@link org.springframework.web.servlet.view.RedirectView} 
	 * will select {@code HttpStatus.MOVED_TEMPORARILY (302)} by default. 
	 */ 
	public RedirectViewControllerRegistration setStatusCode(HttpStatus statusCode) {
		Assert.isTrue(statusCode.is3xxRedirection(), "Not a redirect status code.");
		this.redirectView.setStatusCode(statusCode);
		return this;
	} 
 
	/** 
	 * Whether to interpret a given redirect URL that starts with a slash ("/") 
	 * as relative to the current ServletContext, i.e. as relative to the web 
	 * application root. 
	 * 
	 * <p>Default is {@code true}. 
	 */ 
	public RedirectViewControllerRegistration setContextRelative(boolean contextRelative) {
		this.redirectView.setContextRelative(contextRelative);
		return this;
6
CodeRank
This code example shows how to use the following methods:value
		return this.status;
	} 
 
	@Override 
	public int getRawStatusCode() throws IOException {
		return this.status.value();
	} 
 
	@Override 
	public String getStatusText() throws IOException {
		return this.status.getReasonPhrase();
	} 
 
	@Override 
	public void close() { 
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:equals
	/** 
	 * 处理异常,对于客户端自己的异常,抛出HystrixBadRequestException,不算入短路统计内。 
	 */ 
	protected Exception handleException(HttpStatusCodeException e) {
		HttpStatus status = e.getStatusCode();
		if (status.equals(HttpStatus.BAD_REQUEST)) {
			throw new HystrixBadRequestException(e.getResponseBodyAsString(), e);
		} 
		throw e;
	} 
} 
6
CodeRank
This code example shows how to use the following methods:value
 
	private static final long serialVersionUID = 1L;
	final HttpStatus status;
	 
	public HttpException(HttpStatus status) {
		super("Http error code " + status.value());
		this.status = status;
	} 
	 
	   public HttpException(HttpStatus status, String message) {
	        super("Http error code " + status.value() + ". Cause: " + message);
	        this.status = status;
	    } 
} 
5
CodeRank
See Code Examples for Spring Framework HttpStatus Methods: