javax.ws.rs.core

Class Response.ResponseBuilder

  • Enclosing class:
    Response

    public abstract static class Response.ResponseBuilder
    extends Object
    A class used to build Response instances that contain metadata instead of or in addition to an entity. An initial instance may be obtained via static methods of the Response class, instance methods provide the ability to set metadata. E.g. to create a response that indicates the creation of a new resource:
    @POST
     Response addWidget(...) {
       Widget w = ...
       URI widgetId = UriBuilder.fromResource(Widget.class)...
       return Response.created(widgetId).build();
     }

    Several methods have parameters of type URI, UriBuilder provides convenient methods to create such values as does URI.create().

    Where multiple variants of the same method are provided, the type of the supplied parameter is retained in the metadata of the built Response.

    • Constructor Detail

      • ResponseBuilder

        protected ResponseBuilder()
        Protected constructor, use one of the static methods of Response to obtain an instance.
    • Method Detail

      • newInstance

        protected static Response.ResponseBuilder newInstance()
        Create a new builder instance.
        Returns:
        a new response builder.
      • build

        public abstract Response build()
        Create a Response instance from the current ResponseBuilder. The builder is reset to a blank state equivalent to calling the ok method.
        Returns:
        a Response instance.
      • clone

        public abstract Response.ResponseBuilder clone()

        Create a copy of the ResponseBuilder preserving its state.

        Overrides:
        clone in class Object
        Returns:
        a copy of the ResponseBuilder.
      • status

        public abstract Response.ResponseBuilder status(int status)
        Set the status on the ResponseBuilder.
        Parameters:
        status - the response status.
        Returns:
        the updated response builder.
        Throws:
        IllegalArgumentException - if status is less than 100 or greater than 599.
      • allow

        public abstract Response.ResponseBuilder allow(String... methods)
        Set the list of allowed methods for the resource. Any duplicate method names will be truncated to a single entry.
        Parameters:
        methods - the methods to be listed as allowed for the resource, if null any existing allowed method list will be removed.
        Returns:
        the updated response builder.
        Since:
        2.0
      • allow

        public abstract Response.ResponseBuilder allow(Set<String> methods)
        Set the list of allowed methods for the resource.
        Parameters:
        methods - the methods to be listed as allowed for the resource, if null any existing allowed method list will be removed.
        Returns:
        the updated response builder.
        Since:
        2.0
      • cacheControl

        public abstract Response.ResponseBuilder cacheControl(CacheControl cacheControl)
        Set the cache control data of the message.
        Parameters:
        cacheControl - the cache control directives, if null any existing cache control directives will be removed.
        Returns:
        the updated response builder.
      • encoding

        public abstract Response.ResponseBuilder encoding(String encoding)
        Set the message entity content encoding.
        Parameters:
        encoding - the content encoding of the message entity, if null any existing value for content encoding will be removed.
        Returns:
        the updated response builder.
        Since:
        2.0
      • replaceAll

        public abstract Response.ResponseBuilder replaceAll(MultivaluedMap<String,Object> headers)
        Replaces all existing headers with the newly supplied headers.
        Parameters:
        headers - new headers to be set, if null all existing headers will be removed.
        Returns:
        the updated response builder.
        Since:
        2.0
      • language

        public abstract Response.ResponseBuilder language(String language)
        Set the message entity language.
        Parameters:
        language - the language of the message entity, if null any existing value for language will be removed.
        Returns:
        the updated response builder.
      • language

        public abstract Response.ResponseBuilder language(Locale language)
        Set the message entity language.
        Parameters:
        language - the language of the message entity, if null any existing value for type will be removed.
        Returns:
        the updated response builder.
      • type

        public abstract Response.ResponseBuilder type(MediaType type)
        Set the message entity media type.
        Parameters:
        type - the media type of the message entity. If null, any existing value for type will be removed.
        Returns:
        the updated response builder.
      • type

        public abstract Response.ResponseBuilder type(String type)
        Set the message entity media type.
        Parameters:
        type - the media type of the message entity. If null, any existing value for type will be removed.
        Returns:
        the updated response builder.
      • contentLocation

        public abstract Response.ResponseBuilder contentLocation(URI location)
        Set the content location.
        Parameters:
        location - the content location. Relative or absolute URIs may be used for the value of content location. If null any existing value for content location will be removed.
        Returns:
        the updated response builder.
      • expires

        public abstract Response.ResponseBuilder expires(Date expires)
        Set the response expiration date.
        Parameters:
        expires - the expiration date, if null removes any existing expires value.
        Returns:
        the updated response builder.
      • lastModified

        public abstract Response.ResponseBuilder lastModified(Date lastModified)
        Set the response entity last modification date.
        Parameters:
        lastModified - the last modified date, if null any existing last modified value will be removed.
        Returns:
        the updated response builder.
      • location

        public abstract Response.ResponseBuilder location(URI location)
        Set the location.
        Parameters:
        location - the location. If a relative URI is supplied it will be converted into an absolute URI by resolving it relative to the base URI of the application (see UriInfo.getBaseUri()). If null any existing value for location will be removed.
        Returns:
        the updated response builder.
      • tag

        public abstract Response.ResponseBuilder tag(EntityTag tag)
        Set a response entity tag.
        Parameters:
        tag - the entity tag, if null any existing entity tag value will be removed.
        Returns:
        the updated response builder.
      • tag

        public abstract Response.ResponseBuilder tag(String tag)
        Set a strong response entity tag.

        This is a shortcut for tag(new EntityTag(value)).

        Parameters:
        tag - the string content of a strong entity tag. The JAX-RS runtime will quote the supplied value when creating the header. If null any existing entity tag value will be removed.
        Returns:
        the updated response builder.
      • variants

        public abstract Response.ResponseBuilder variants(Variant... variants)
        Add a Vary header that lists the available variants.
        Parameters:
        variants - a list of available representation variants, a null value will remove an existing value for Vary header.
        Returns:
        the updated response builder.
        Since:
        2.0
      • variants

        public abstract Response.ResponseBuilder variants(List<Variant> variants)
        Add a Vary header that lists the available variants.
        Parameters:
        variants - a list of available representation variants, a null value will remove an existing value for Vary header.
        Returns:
        the updated response builder.
      • public abstract Response.ResponseBuilder links(Link... links)
        Add one or more link headers.
        Parameters:
        links - links to be added to the message as headers, a null value will remove any existing Link headers.
        Returns:
        the updated response builder.
        Since:
        2.0
      • public abstract Response.ResponseBuilder link(URI uri,
                                                      String rel)
        Add a link header.
        Parameters:
        uri - underlying URI for link header.
        rel - value of "rel" parameter.
        Returns:
        the updated response builder.
        Since:
        2.0
      • public abstract Response.ResponseBuilder link(String uri,
                                                      String rel)
        Add a link header.
        Parameters:
        uri - underlying URI for link header.
        rel - value of "rel" parameter.
        Returns:
        the updated response builder.
        Since:
        2.0

Traduction non disponible

Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.

Version en cache

21/08/2025 16:59:12 Cette version de la page est en cache (à la date du 21/08/2025 16:59:12) afin d'accélérer le traitement.
Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la version plus récente de la page.

Document créé le 11/06/2005, dernière modification le 18/08/2025
Source du document imprimé : https://www.gaudry.be/java-api-javaee-rf-javax/ws/rs/core/response.responsebuilder.html

L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.

Références

  1. Consulter le document html Langue du document :fr Manuel PHP : https://docs.oracle.com

Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.