Java Reference
In-Depth Information
Use the HeaderSet interface to set and get the values of user-defined headers. To add a
user-defined header to a HeaderSet , use this method:
void setHeader(int headerID, java.lang.Object headerValue);
Check Table 12-6 to determine an identifier to use and the corresponding header type. For
example, to add a user-defined string-typed header to a HeaderSet called OutHeader , use this:
String seekHeight = "tall";
OutHeader.setHeader(48, seekHeight);
From Table 12-6, you can see that the identifier value of 48 contains a user-defined header
of Unicode string type.
To obtain the value of a particular header, use this method:
Object getHeader(int headerID);
For example, to retrieve the string-valued header set earlier using setHeader() , from a
HeaderSet called InHeader , you can use
String seekHeight = (String) InHeader.getHeader(48);
You can get an array of int containing the identifiers of all the headers in a HeaderSet with
this method:
int[] getHeaderList()
The array returned by getHeaderList() will only contain headers that have values set; you
can call getHeader() on any of the returned indexes safely.
Every request that returns a HeaderSet has a response code from the OBEX server. However,
since a Java method cannot return multiple values of different types, you must make an addi-
tional API call on the returned HeaderSet to obtain the OBEX response code for the request:
int getResponseCode();
To interpret the response code from an OBEX server, consult the documentation for the
ResponseCodes class. This class defines the static constants for all the possible OBEX response
codes. Table 12-7 shows some of the most frequently used ones, and those used in the upcoming
example.
Table 12-7 OBEX Response Codes (Partial)
Value
Description
ResponseCodes.OBEX_HTTP_OK
Successful request or operations
ResponseCodes.OBEX_HTTP_VERSION
Version of OBEX_HTTP not supported
ResponseCodes.OBEX_HTTP_UNAUTHORIZED
Unauthorized connection
ResponseCodes.OBEX_HTTP_FORBIDDEN
Forbidden access
Search WWH ::




Custom Search