uCosminexus Application Server, Web Service Development Guide

[Contents][Glossary][Index][Back][Next]

11.4.4 Setting an HTTP header

A client API provides various methods to set an HTTP header in an HTTP request object. For details on supported methods, see 25.1 The support range of client API interfaces and classes. This subsection describes one of the following HTTP request objects:

An HTTP request object contains the MultivaluedMap object that stores a value corresponding to the HTTP header.

The following figure shows the initialization of the MultivaluedMap object that stores the HTTP header.

Figure 11-5 Mechanism of initializing the MultivaluedMap object

[Figure]

In the figure, a user program creates an HTTP request object by using the resource() method of the Client class or create() static method of the ClientRequest class.

Here, an empty MultivaluedMap object is initialized.

The following figures show and describe the examples of setting an HTTP header in the MultivaluedMap object.

Example 1
[Figure]

Example 2
[Figure]

Example 3
[Figure]

Example 4
[Figure]

In all the methods shown in example 1 through example 4, a user program can create an HTTP request object that contains the HTTP Accept headers having the values text/xml and text/plain. This also applies to the HTTP Accept-Language header and HTTP Cookie header. For HTTP Accept-Language headers and HTTP Cookie headers, substitute the accept method with the acceptLanguage() method and cookie() method respectively.

The following figures show the operation in example 1 and example 3 for the HTTP Content-Type headers.

Example 1
[Figure]

Example 3
[Figure]

The value of the Content-Type HTTP header set in the HTTP request object in both the examples above is text/plain. Also, because the HTTP Content-Type header can contain only one value, you cannot use the methods described in example 2 and example 4.

Prior to the HTTP communication, all the HTTP headers and respective values added in the HTTP request object are set in the HttpURLConnection object. The following figure shows the mechanism:

[Figure]

The corresponding HTTP header value included in the HTTP request object is set in the respective HTTP header. Accordingly, a non-null value of the corresponding HTTP header included in the HTTP request object is set to the value returned by the toString() method. The JAX-RS engine does not verify the value of an HTTP header. Set a value of an HTTP header in the HTTP request object according to the standard specifications.

Further, until establishing the HTTP communication, the operation when no specific HTTP header is set in the HTTP request object is same as the operation when no HTTP header is set in the HttpURLConnection object.