Example usage for io.vertx.core.http HttpHeaders RETRY_AFTER

List of usage examples for io.vertx.core.http HttpHeaders RETRY_AFTER

Introduction

In this page you can find the example usage for io.vertx.core.http HttpHeaders RETRY_AFTER.

Prototype

CharSequence RETRY_AFTER

To view the source code for io.vertx.core.http HttpHeaders RETRY_AFTER.

Click Source Link

Document

Retry-After header name

Usage

From source file:org.eclipse.hono.adapter.http.AbstractVertxBasedHttpProtocolAdapter.java

License:Open Source License

/**
 * Ends a response with HTTP status code 503 (Service Unavailable) and sets the <em>Retry-After</em> HTTP header
 * to a given number of seconds./*from  w ww .j  a v a  2s . c  om*/
 * 
 * @param response The HTTP response to write to.
 * @param retryAfterSeconds The number of seconds to set in the header.
 * @param detail The message to write to the response's body (may be {@code null}).
 * @param contentType The content type of the message (if {@code null}, then <em>text/plain</em> is used}.
 * @throws NullPointerException if response is {@code null}.
 */
protected static void serviceUnavailable(final HttpServerResponse response, final int retryAfterSeconds,
        final String detail, final String contentType) {

    LOG.debug("Service unavailable: {}", detail);
    Map<CharSequence, CharSequence> headers = new HashMap<>(2);
    headers.put(HttpHeaders.CONTENT_TYPE, contentType != null ? contentType : "text/plain");
    headers.put(HttpHeaders.RETRY_AFTER, String.valueOf(retryAfterSeconds));
    endWithStatus(response, HTTP_UNAVAILABLE, headers, detail, contentType);
}

From source file:org.eclipse.hono.service.http.HttpEndpointUtils.java

License:Open Source License

/**
 * Ends a response with HTTP status code 503 (Service Unavailable) and sets the <em>Retry-After</em> HTTP header to
 * a given number of seconds.// www  .  j  av a  2  s . co  m
 *
 * @param response The HTTP response to write to.
 * @param retryAfterSeconds The number of seconds to set in the header.
 * @param detail The message to write to the response's body (may be {@code null}).
 * @param contentType The content type of the message (if {@code null}, then <em>text/plain</em> is used}.
 * @throws NullPointerException if response is {@code null}.
 */
public static void serviceUnavailable(final HttpServerResponse response, final int retryAfterSeconds,
        final String detail, final String contentType) {

    LOG.debug("Service unavailable: {}", detail);
    Map<CharSequence, CharSequence> headers = new HashMap<>(2);
    headers.put(HttpHeaders.CONTENT_TYPE, contentType != null ? contentType : "text/plain");
    headers.put(HttpHeaders.RETRY_AFTER, String.valueOf(retryAfterSeconds));
    endWithStatus(response, HTTP_UNAVAILABLE, headers, detail, contentType);
}

From source file:org.eclipse.hono.service.http.HttpUtils.java

License:Open Source License

/**
 * Fails a routing context with HTTP status code 503 (Service Unavailable) and sets the <em>Retry-After</em> HTTP header
 * to a given number of seconds.// w  w  w  .  j a  va 2 s . com
 * 
 * @param ctx The vert.x routing context to fail.
 * @param retryAfterSeconds The number of seconds to set in the header.
 * @param detail The message to write to the response's body (may be {@code null}).
 * @throws NullPointerException if routing context is {@code null}.
 */
public static void serviceUnavailable(final RoutingContext ctx, final int retryAfterSeconds,
        final String detail) {

    final Map<CharSequence, CharSequence> headers = new HashMap<>(1);
    headers.put(HttpHeaders.RETRY_AFTER, String.valueOf(retryAfterSeconds));
    failWithStatus(ctx, HttpURLConnection.HTTP_UNAVAILABLE, headers, detail);
}