javax.ws.rs.core
Interface RequestHeaders


public interface RequestHeaders

An injectable interface that provides access to HTTP request header information. This interface can only be injected as part of the request or response processing scope. Alternatively, the interface can be retrieved from a Request instance via its getHeaders() method.

Since:
2.0
Author:
Marek Potociar
See Also:
Context

Method Summary
 MultivaluedMap<String,String> asMap()
          Get the map of HTTP message header names to their respective values.
 List<Locale> getAcceptableLanguages()
          Get a list of languages that are acceptable for the response.
 List<MediaType> getAcceptableMediaTypes()
          Get a list of media types that are acceptable for the response.
 Map<String,Cookie> getCookies()
          Get any cookies that accompanied the request.
 Date getDate()
          Get message date.
 String getHeader(String name)
          Get a HTTP header as a single string value.
 List<String> getHeaderValues(String name)
          Get the values of a single HTTP message header.
 Locale getLanguage()
          Get the language of the entity
 int getLength()
          Get Content-Length value.
 Link getLink(String relation)
          Get the link for the relation.
 Link.Builder getLinkBuilder(String relation)
          Convenience method that returns a Link.Builder for the relation.
 Set<Link> getLinks()
          Get the links attached to the message as header.
 MediaType getMediaType()
          Get the media type of the entity
 boolean hasLink(String relation)
          Check if link for relation exists.
 

Method Detail

getDate

Date getDate()
Get message date.

Returns:
the message date, otherwise null if not present.
Since:
2.0

getHeader

String getHeader(String name)
Get a HTTP header as a single string value.

Each single header value is converted to String using a RuntimeDelegate.HeaderDelegate if one is available via RuntimeDelegate.createHeaderDelegate(java.lang.Class) for the header value class or using its toString method if a header delegate is not available.

Parameters:
name - the HTTP header.
Returns:
the HTTP header value. If the HTTP header is not present then null is returned. If the HTTP header is present but has no value then the empty string is returned. If the HTTP header is present more than once then the values of joined together and separated by a ',' character.
Since:
2.0
See Also:
asMap(), getHeaderValues(java.lang.String)

asMap

MultivaluedMap<String,String> asMap()
Get the map of HTTP message header names to their respective values. The returned map is case-insensitive wrt. keys and is read-only.

Each single header value is converted to String using a RuntimeDelegate.HeaderDelegate if one is available via RuntimeDelegate.createHeaderDelegate(java.lang.Class) for the header value class or using its toString method if a header delegate is not available.

Returns:
a read-only map of header names and values.
Throws:
IllegalStateException - if called outside of the message processing scope.
Since:
2.0
See Also:
getHeader(java.lang.String), getHeaderValues(java.lang.String)

getHeaderValues

List<String> getHeaderValues(String name)
Get the values of a single HTTP message header. The returned List is read-only. This is a convenience shortcut for asMap().get(name).

Each single header value is converted to String using a RuntimeDelegate.HeaderDelegate if one is available via RuntimeDelegate.createHeaderDelegate(java.lang.Class) for the header value class or using its toString method if a header delegate is not available.

Parameters:
name - the header name, case insensitive.
Returns:
a read-only list of header values.
Throws:
IllegalStateException - if called outside of the message processing scope.
Since:
2.0
See Also:
asMap(), getHeader(java.lang.String)

getLanguage

Locale getLanguage()
Get the language of the entity

Returns:
the language of the entity or null if not specified
Since:
2.0

getLength

int getLength()
Get Content-Length value.

Returns:
Content-Length as integer if present and valid number. In other cases returns -1.
Since:
2.0

getMediaType

MediaType getMediaType()
Get the media type of the entity

Returns:
the media type or null if there is no request entity.
Since:
2.0

getAcceptableMediaTypes

List<MediaType> getAcceptableMediaTypes()
Get a list of media types that are acceptable for the response.

Returns:
a read-only list of requested response media types sorted according to their q-value, with highest preference first.
Since:
2.0

getAcceptableLanguages

List<Locale> getAcceptableLanguages()
Get a list of languages that are acceptable for the response.

Returns:
a read-only list of acceptable languages sorted according to their q-value, with highest preference first.
Since:
2.0

getCookies

Map<String,Cookie> getCookies()
Get any cookies that accompanied the request.

Returns:
a read-only map of cookie name (String) to Cookie.
Since:
2.0

getLinks

Set<Link> getLinks()
Get the links attached to the message as header.

Returns:
links, may return empty Set if no links are present. Never returns null.
Since:
2.0

hasLink

boolean hasLink(String relation)
Check if link for relation exists.

Parameters:
relation - link relation.
Returns:
outcome of boolean test.
Since:
2.0

getLink

Link getLink(String relation)
Get the link for the relation.

Parameters:
relation - link relation.
Returns:
the link for the relation, otherwise null if not present.
Since:
2.0

getLinkBuilder

Link.Builder getLinkBuilder(String relation)
Convenience method that returns a Link.Builder for the relation.

Parameters:
relation - link relation.
Returns:
the link builder for the relation, otherwise null if not present.
Since:
2.0


Copyright © 2007-2012 Oracle Corporation. All Rights Reserved. Use is subject to license terms.