Class ContainerRequestBuilder


  • public final class ContainerRequestBuilder
    extends Object
    Used by unit tests / benchmarks to create mock ContainerRequest instances.
    Since:
    2.17
    Author:
    Michal Gajdos, Martin Matula
    • Method Detail

      • from

        public static ContainerRequestBuilder from​(String requestUri,
                                                   String method,
                                                   Configuration configuration)
        Create new Jersey container request context builder. The builder and built request context are supposed to be used only for testing purposes.
        Parameters:
        requestUri - request URI.
        method - request HTTP method name.
        configuration - container request configuration
        Returns:
        new builder instance.
      • from

        public static ContainerRequestBuilder from​(String baseUri,
                                                   String requestUri,
                                                   String method,
                                                   Configuration configuration)
        Create new Jersey container request context builder. The builder and built request context are supposed to be used only for testing purposes.
        Parameters:
        baseUri - base application URI.
        requestUri - request URI.
        method - request HTTP method name.
        configuration - container request configuration
        Returns:
        new builder instance.
      • from

        public static ContainerRequestBuilder from​(String baseUri,
                                                   String requestUri,
                                                   String method,
                                                   SecurityContext securityContext,
                                                   org.glassfish.jersey.internal.PropertiesDelegate propertiesDelegate,
                                                   Configuration configuration)
        Create new Jersey container request context builder. The builder and built request context are supposed to be used only for testing purposes.
        Parameters:
        baseUri - base application URI.
        requestUri - request URI.
        method - request HTTP method name.
        securityContext - security context of the current request. May be null. The SecurityContext.getUserPrincipal() must return null if the current request has not been authenticated by the container.
        propertiesDelegate - custom properties delegate to be used by the context, may be null.
        configuration - container request configuration
        Returns:
        new builder instance.
      • from

        public static ContainerRequestBuilder from​(URI requestUri,
                                                   String method,
                                                   Configuration configuration)
        Create new Jersey container request context builder. The builder and built request context are supposed to be used only for testing purposes.
        Parameters:
        requestUri - request URI.
        method - request HTTP method name.
        configuration - container request configuration
        Returns:
        new builder instance.
      • from

        public static ContainerRequestBuilder from​(URI baseUri,
                                                   URI requestUri,
                                                   String method,
                                                   Configuration configuration)
        Create new Jersey container request context builder. The builder and built request context are supposed to be used only for testing purposes.
        Parameters:
        baseUri - base application URI.
        requestUri - request URI.
        method - request HTTP method name.
        configuration - container request configuration
        Returns:
        new builder instance.
      • from

        public static ContainerRequestBuilder from​(URI baseUri,
                                                   URI requestUri,
                                                   String method,
                                                   SecurityContext securityContext,
                                                   org.glassfish.jersey.internal.PropertiesDelegate propertiesDelegate,
                                                   Configuration configuration)
        Create new Jersey container request context builder. The builder and built request context are supposed to be used only for testing purposes.
        Parameters:
        baseUri - base application URI.
        requestUri - request URI.
        method - request HTTP method name.
        securityContext - security context of the current request. May be null. The SecurityContext.getUserPrincipal() must return null if the current request has not been authenticated by the container.
        propertiesDelegate - custom properties delegate to be used by the context, may be null.
        configuration - container request configuration
        Returns:
        new builder instance.
      • accept

        public ContainerRequestBuilder accept​(String... mediaTypes)
        Add the accepted response media types.
        Parameters:
        mediaTypes - accepted response media types. If cookie is null then all current headers of the same name will be removed.
        Returns:
        the updated builder.
      • accept

        public ContainerRequestBuilder accept​(MediaType... mediaTypes)
        Add the accepted response media types.
        Parameters:
        mediaTypes - accepted response media types. If cookie is null then all current headers of the same name will be removed.
        Returns:
        the updated builder.
      • entity

        public ContainerRequestBuilder entity​(InputStream stream)
        Set the request entity input stream. Entity null values are ignored.
        Parameters:
        stream - request entity input stream.
        Returns:
        the updated builder.
      • entity

        public ContainerRequestBuilder entity​(Object entity,
                                              org.glassfish.jersey.message.MessageBodyWorkers workers)
        Set the request entity and entity input stream. Entity null values are ignored.

        MessageBodyWorkers are used to transform the object into entity input stream required to process the request.

        NOTE: Entity transformation into entity input stream doesn't have any impact on benchmarks.

        Parameters:
        entity - request entity instance.
        workers - message body workers to transform entity into entity input stream.
        Returns:
        the updated builder.
      • entity

        public ContainerRequestBuilder entity​(Object entity,
                                              ApplicationHandler handler)
        Set the request entity and entity input stream. Entity null values are ignored.

        ApplicationHandler is required to obtain MessageBodyWorkers to transform the object into entity input stream used for processing the request.

        NOTE: Entity transformation into entity input stream doesn't have any impact on benchmarks.

        Parameters:
        entity - request entity instance.
        handler - application handler to obtain message body workers from.
        Returns:
        the updated builder.
      • type

        public ContainerRequestBuilder type​(String contentType)
        Add content type of the entity.
        Parameters:
        contentType - content media type.
        Returns:
        the updated builder.
      • type

        public ContainerRequestBuilder type​(MediaType contentType)
        Add content type of the entity.
        Parameters:
        contentType - content media type.
        Returns:
        the updated builder.
      • cookie

        public ContainerRequestBuilder cookie​(Cookie cookie)
        Add a cookie to be set.
        Parameters:
        cookie - to be set. If cookie is null then all current headers of the same name will be removed.
        Returns:
        the updated builder.
      • cookies

        public ContainerRequestBuilder cookies​(Cookie... cookies)
        Add cookies to be set.
        Parameters:
        cookies - to be set. If cookies is null then all current headers of the same name will be removed.
        Returns:
        the updated builder.