uCosminexus Application Server, Web Service Development Guide
![[Contents]](FIGURE/CONTENT.GIF)
![[Glossary]](FIGURE/GLOSS.GIF)
![[Index]](FIGURE/INDEX.GIF)
![[Back]](FIGURE/FRONT.GIF)
header(String name, Object value) method
Description
This method adds an HTTP header.
Syntax
public T header(String name,
Object value)
Parameters
- name
- This is the name of an HTTP header.
- value
- This is the value of an HTTP header.
Return value
The method returns the builder (WebResource.Builder object).
Notes
- If the value of both name and value parameters is null, the method is not invoked.
- Even if the value of the name parameter is not null, but if the value of the value parameter is null, the method is not invoked.
- If the value of the name parameter is null and the value of the value parameter is not null, an error (KDJJ18888-E) occurs and the ClientHandlerException exception that wraps the NullPointerException exception is thrown.
- You cannot set the HTTP headers Content-Length, Connection, or Host with this method. If you specify these headers in the name parameter, the method is not invoked even if the value of the value parameter is not null. Note that HttpURLConnection sets each of the HTTP headers.
- The value returned by the toString() method of a non-null object specified with the value parameter is set as the value of the HTTP header specified with the name parameter. The JAX-RS engine does not validate the values returned by the toString() method. Specify the value in the value parameter according to the standard specifications.
- You can also use the following methods to add the HTTP headers accept, acceptLanguage, and cookie:
- ClientRequest.Builder class
accept(MediaType... types) method
accept(String... types) method
acceptLanguage(Locale... locales) method
acceptLanguage(String... locales) method
cookie(Cookie cookie) method
- WebResource class
accept(MediaType... types) method
accept(String... types) method
acceptLanguage(Locale... locales) method
acceptLanguage(String... locales) method
cookie(Cookie cookie) method
- WebResource.Builder class
accept(MediaType... types) method
accept(String... types) method
acceptLanguage(Locale... locales) method
acceptLanguage(String... locales) method
cookie(Cookie cookie) method
The operation when none of the HTTP headers is added with these methods and the header(String name, Object value) method is the same as the operation when none of the HTTP headers is added in the HttpURLConnection object.
- If the Content-Type HTTP header is already set by using the following methods, the value is overwritten by the value of the value parameter:
- ClientRequest.Builder class
entity(Object entity, MediaType type) method
entity(Object entity, String type) method
header(String name, Object value) method
type(MediaType type) method
type(String type) method
- WebResource class
entity(Object entity, MediaType type) method
entity(Object entity, String type) method
header(String name, Object value) method
type(MediaType type) method
type(String type) method
- WebResource.Builder class
entity(Object entity, MediaType type) method
entity(Object entity, String type) method
type(MediaType type) method
type(String type) method
The operation when the MIME media type is not set with these methods and the header(String name, Object value) method is the same as the operation when the Content-Type HTTP header is not set in the HttpURLConnection object before performing HTTP communication.
All Rights Reserved. Copyright (C) 2013, Hitachi, Ltd.