Class OslcResponses.OslcResponseBuilder

  • Enclosing class:
    OslcResponses

    public static class OslcResponses.OslcResponseBuilder
    extends Object
    A class used to build Response instances
    Since:
    1.3.0
    • Method Detail

      • header

        public OslcResponses.OslcResponseBuilder header​(String name,
                                                        Object value)
        Add a header to the ResponseBuilder.
        Parameters:
        name - the name of the header.
        value - the value of the header. If value is null then all current headers of the same name will be removed.
        Returns:
        the updated ResponseBuilder.
      • headers

        public OslcResponses.OslcResponseBuilder headers​(ResourceResponse<?> response,
                                                         String... names)
        Copies headers matching the specified header names from the specified response into this builder.

        If no header names are provided, the copied headers will default to:

        • ETag
        • Last-Modified

        If headers were automatically copied when creating this builder instance, they are no modified by this operation.

        Parameters:
        response - a response whose headers are to copy.
        names - the headers names to copy. Any response header not part of this list is ignored.
        Returns:
        the updated ResponseBuilder.
        See Also:
        OslcResponses.from(ResourceResponse)
      • headers

        public OslcResponses.OslcResponseBuilder headers​(ClientResponse response,
                                                         String... names)
        Copies headers matching the specified header names from the specified response into this builder.

        If no header names are provided, the copied headers will default to:

        • Cache-Control
        • Content-Type
        • Content-Length
        • ETag
        • Expires
        • Last-Modified

        If headers were automatically copied when creating this builder instance, they are no modified by this operation.

        Parameters:
        response - a response whose headers are to copy.
        names - the headers names to copy. Any response header not part of this list is ignored.
        Returns:
        the updated ResponseBuilder.
        See Also:
        OslcResponses.from(ClientResponse)
      • headers

        public OslcResponses.OslcResponseBuilder headers​(MultivaluedMap<String,​?> headers,
                                                         String... names)
        Copies headers matching the specified header names from the specified map into this builder.

        If no header names are provided, this method has no effect.

        Parameters:
        headers - a map of headers.
        names - the headers names to copy. Any header not part of this list is ignored.
        Returns:
        the updated ResponseBuilder.
      • noCache

        public OslcResponses.OslcResponseBuilder noCache()
        Adds or replaces existing cache management headers to this builder, in order to prevent the response from being cached.

        The headers are:

        • Cache-Control
        • Pragma
        • Expires
        Returns:
        the updated ResponseBuilder.
        Since:
        1.10.0
      • alertSuccess

        public OslcResponses.OslcResponseBuilder alertSuccess​(String message)
        Adds a X-com-sodius-web-alert-success header in the response, whose value is a rich text to display in the calling web page as a success notification. This shall be used for example to confirm the creation of an element on server side, as requested by the user.

        The message must contain valid XHTML content, so that HTML formatting can be used to render the message in the web page (e.g. <strong> elements).

        Such notification is usually displayed at top right of the screen and auto hides after a few seconds.

        Parameters:
        message - the rich text message to display in the caller web page.
        Returns:
        the updated ResponseBuilder.
        Since:
        1.14.0
      • alertInfo

        public OslcResponses.OslcResponseBuilder alertInfo​(String message)
        Adds a X-com-sodius-web-alert-info header in the response, whose value is a rich text to display in the calling web page as a information notification. This shall be used for example to let the user know the request was fulfilled but he has another action to take to complete the overall process.

        The message must contain valid XHTML content, so that HTML formatting can be used to render the message in the web page (e.g. <strong> elements).

        Such notification is usually displayed at top right of the screen.

        Parameters:
        message - the rich text message to display in the caller web page.
        Returns:
        the updated ResponseBuilder.
        Since:
        1.14.0
      • alertWarning

        public OslcResponses.OslcResponseBuilder alertWarning​(String message)
        Adds a X-com-sodius-web-alert-warning header in the response, whose value is a rich text to display in the calling web page as a warning notification. This shall be used for example to let the user know the request was fulfilled but something is suspicious and he's recommended to review some settings.

        The message must contain valid XHTML content, so that HTML formatting can be used to render the message in the web page (e.g. <strong> elements).

        Such notification is usually displayed at top right of the screen.

        Parameters:
        message - the rich text message to display in the caller web page.
        Returns:
        the updated ResponseBuilder.
        Since:
        1.14.0
      • build

        public Response build​(HttpServletRequest request,
                              HttpHeaders headers)
        Converts the underlying entity, if any, to a StreamingOutput and creates a Response instance from the current ResponseBuilder. The builder is reset to a blank state.

        This conversion capability is usually the responsibility of the JAX-RS framework. However there are cases where the list of providers used or the priority of those providers cannot be controlled. This method uses OslcStreams to serialize the entity and control the providers used for that. Refer to the documentation of OslcStreams for more information

        Parameters:
        request - the servlet request to inject into providers.
        headers - the HTTP headers to inject into providers.
        Returns:
        a Response instance.
        Throws:
        IllegalArgumentException - if either the entity type or media type is not supported by this class.
        Since:
        1.13.0
        See Also:
        OslcStreams.toStream(Object, HttpServletRequest, HttpHeaders)
      • buildException

        public WebApplicationException buildException()
        Creates a WebApplicationException that wraps the response. The builder is reset to a blank state.
        Returns:
        a WebApplicationException.