Class ClientRequest

All Implemented Interfaces:
ClientRequestContext, HttpHeaders, org.glassfish.jersey.internal.inject.InjectionManagerSupplier, PropertiesResolver

public class ClientRequest extends OutboundMessageContext implements ClientRequestContext, HttpHeaders, org.glassfish.jersey.internal.inject.InjectionManagerSupplier, PropertiesResolver
Jersey client request context.
Author:
Marek Potociar
  • Constructor Details

    • ClientRequest

      protected ClientRequest(URI requestUri, ClientConfig clientConfig, PropertiesDelegate propertiesDelegate)
      Create new Jersey client request context.
      Parameters:
      requestUri - request Uri.
      clientConfig - request configuration.
      propertiesDelegate - properties delegate.
    • ClientRequest

      public ClientRequest(ClientRequest original)
      Copy constructor.
      Parameters:
      original - original instance.
  • Method Details

    • resolveProperty

      public <T> T resolveProperty(String name, Class<T> type)
      Description copied from interface: PropertiesResolver
      Resolve a property value for the specified property name.

      The method returns the value of the property registered in the request-specific property bag, if available. If no property for the given property name is found in the request-specific property bag, the method looks at the properties stored in the global runtime configuration this request belongs to. If there is a value defined in the runtime configuration, it is returned, otherwise the method returns null if no such property is registered neither in the runtime nor in the request-specific property bag.

      Specified by:
      resolveProperty in interface PropertiesResolver
      Type Parameters:
      T - property Java type.
      Parameters:
      name - property name.
      type - expected property class type.
      Returns:
      resolved property value or null if no such property is registered.
    • resolveProperty

      public <T> T resolveProperty(String name, T defaultValue)
      Description copied from interface: PropertiesResolver
      Resolve a property value for the specified property name.

      The method returns the value of the property registered in the request-specific property bag, if available. If no property for the given property name is found in the request-specific property bag, the method looks at the properties stored in the global runtime configuration this request belongs to. If there is a value defined in the runtime configuration, it is returned, otherwise the method returns defaultValue if no such property is registered neither in the runtime nor in the request-specific property bag.

      Specified by:
      resolveProperty in interface PropertiesResolver
      Type Parameters:
      T - property Java type.
      Parameters:
      name - property name.
      defaultValue - default value to return if the property is not registered.
      Returns:
      resolved property value or defaultValue if no such property is registered.
    • hasProperty

      public boolean hasProperty(String name)
      Specified by:
      hasProperty in interface ClientRequestContext
    • getProperty

      public Object getProperty(String name)
      Specified by:
      getProperty in interface ClientRequestContext
    • getPropertyNames

      public Collection<String> getPropertyNames()
      Specified by:
      getPropertyNames in interface ClientRequestContext
    • setProperty

      public void setProperty(String name, Object object)
      Specified by:
      setProperty in interface ClientRequestContext
    • removeProperty

      public void removeProperty(String name)
      Specified by:
      removeProperty in interface ClientRequestContext
    • getUri

      public URI getUri()
      Specified by:
      getUri in interface ClientRequestContext
    • setUri

      public void setUri(URI uri)
      Specified by:
      setUri in interface ClientRequestContext
    • getMethod

      public String getMethod()
      Specified by:
      getMethod in interface ClientRequestContext
    • setMethod

      public void setMethod(String method)
      Specified by:
      setMethod in interface ClientRequestContext
    • getClient

      public JerseyClient getClient()
      Specified by:
      getClient in interface ClientRequestContext
    • abortWith

      public void abortWith(Response response)
      Specified by:
      abortWith in interface ClientRequestContext
    • getAbortResponse

      public Response getAbortResponse()
      Get the request filter chain aborting response if set, or null otherwise.
      Returns:
      request filter chain aborting response if set, or null otherwise.
    • getConfiguration

      public Configuration getConfiguration()
      Description copied from class: OutboundMessageContext
      The related client/server side Configuration. Can be null.
      Specified by:
      getConfiguration in interface ClientRequestContext
      Overrides:
      getConfiguration in class OutboundMessageContext
      Returns:
      Configuration the configuration
    • getRequestHeader

      public List<String> getRequestHeader(String name)
      Get the values of an HTTP request header if the header exists on the current request. The returned value will be a read-only List if the specified header exists or null if it does not. This is a shortcut for getRequestHeaders().get(name).
      Specified by:
      getRequestHeader in interface HttpHeaders
      Parameters:
      name - the header name, case insensitive.
      Returns:
      a read-only list of header values if the specified header exists, otherwise null.
      Throws:
      IllegalStateException - if called outside the scope of a request.
    • getRequestHeaders

      public MultivaluedMap<String,String> getRequestHeaders()
      Specified by:
      getRequestHeaders in interface HttpHeaders
    • getCookies

      public Map<String,Cookie> getCookies()
      Specified by:
      getCookies in interface ClientRequestContext
      Specified by:
      getCookies in interface HttpHeaders
    • getWorkers

      public MessageBodyWorkers getWorkers()
      Get the message body workers associated with the request.
      Returns:
      message body workers.
    • setWorkers

      public void setWorkers(MessageBodyWorkers workers)
      Set the message body workers associated with the request.
      Parameters:
      workers - message body workers.
    • accept

      public void accept(MediaType... types)
      Add new accepted types to the message headers.
      Parameters:
      types - accepted types to be added.
    • accept

      public void accept(String... types)
      Add new accepted types to the message headers.
      Parameters:
      types - accepted types to be added.
    • acceptLanguage

      public void acceptLanguage(Locale... locales)
      Add new accepted languages to the message headers.
      Parameters:
      locales - accepted languages to be added.
    • acceptLanguage

      public void acceptLanguage(String... locales)
      Add new accepted languages to the message headers.
      Parameters:
      locales - accepted languages to be added.
    • cookie

      public void cookie(Cookie cookie)
      Add new cookie to the message headers.
      Parameters:
      cookie - cookie to be added.
    • cacheControl

      public void cacheControl(CacheControl cacheControl)
      Add new cache control entry to the message headers.
      Parameters:
      cacheControl - cache control entry to be added.
    • encoding

      public void encoding(String encoding)
      Set message encoding.
      Parameters:
      encoding - message encoding to be set.
    • language

      public void language(String language)
      Set message language.
      Parameters:
      language - message language to be set.
    • language

      public void language(Locale language)
      Set message language.
      Parameters:
      language - message language to be set.
    • type

      public void type(MediaType type)
      Set message content type.
      Parameters:
      type - message content type to be set.
    • type

      public void type(String type)
      Set message content type.
      Parameters:
      type - message content type to be set.
    • variant

      public void variant(Variant variant)
      Set message content variant (type, language and encoding).
      Parameters:
      variant - message content content variant (type, language and encoding) to be set.
    • isAsynchronous

      public boolean isAsynchronous()
      Returns true if the request is called asynchronously using AsyncInvoker
      Returns:
      True if the request is asynchronous; false otherwise.
    • enableBuffering

      public void enableBuffering()
      Enable a buffering of serialized entity. The buffering will be configured from runtime configuration associated with this request. The property determining the size of the buffer is CommonProperties.OUTBOUND_CONTENT_LENGTH_BUFFER.

      The buffering functionality is by default disabled and could be enabled by calling this method. In this case this method must be called before first bytes are written to the entity stream.

    • writeEntity

      public void writeEntity() throws IOException
      Write (serialize) the entity set in this request into the entity stream. The method use writer interceptors and message body writer.

      This method modifies the state of this request and therefore it can be called only once per request life cycle otherwise IllegalStateException is thrown.

      Note that OutboundMessageContext.setStreamProvider(org.glassfish.jersey.message.internal.OutboundMessageContext.StreamProvider) and optionally enableBuffering() must be called before calling this method.

      Throws:
      IOException - In the case of IO error.
    • getWriterInterceptors

      public Iterable<WriterInterceptor> getWriterInterceptors()
      Get writer interceptors of this request.
      Returns:
      Writer interceptors in the interceptor execution order.
    • getReaderInterceptors

      public Iterable<ReaderInterceptor> getReaderInterceptors()
      Get reader interceptors of this request.
      Returns:
      Reader interceptors in the interceptor execution order.
    • getInjectionManager

      public org.glassfish.jersey.internal.inject.InjectionManager getInjectionManager()
      Description copied from interface: org.glassfish.jersey.internal.inject.InjectionManagerSupplier
      Get injection manager.
      Specified by:
      getInjectionManager in interface org.glassfish.jersey.internal.inject.InjectionManagerSupplier
      Returns:
      injection manager.
    • ignoreUserAgent

      public boolean ignoreUserAgent()
      Indicates whether the User-Agent header should be omitted if not directly set to the map of headers.
      Returns:
      true if the header should be omitted, false otherwise.
    • ignoreUserAgent

      public void ignoreUserAgent(boolean ignore)
      Indicates whether the User-Agent header should be omitted if not directly set to the map of headers.
      Parameters:
      ignore - true if the header should be omitted, false otherwise.