Event receipt – HP Intelligent Management Center Licenses User Manual

Page 28

Advertising
background image

Notes:

1.

The strings "imc_host" and "8080" represent the iMC server address and port number. The
"type_code" string represents the message type of the registration. For more information about
message types, see the related API references.

2.

The "accept" message header defines the format of notification messages. The valid message
formats include XML (application/xml) and JSON (application/json).

3.

The query criteria must include the "type" parameter, which defines the type of the message
to be registered. You can set other parameters (see related API references) to narrow down
the query results.

4.

If the registration succeeds, the server returns the 202 (Accepted) status code, and maintains
the HTTP connection for transmitting subsequent notifications. If the registration fails, the server
returns other status codes and closes the HTTP connection.

The server can return the following status codes for event registration:

202 (Accepted): Registration succeeded. The server maintains the HTTP connection for
transmitting subsequent messages.

400 (Bad Request): Invalid query parameters. The server returns this status code if the registration
request message does not include the "type" parameter, or the event type specified by the
parameter is not supported.

403 (Forbidden): The client denied registration of the message. For more information, see the
Security Control section.

405 (Method Not Allowed): The HTTP method of the registration request is not GET. The iMC-RS
framework supports only the GET type message in event registration and notification.

406 (Not Acceptable): Unsupported content type (which is the "accept" message header in
the registration request). The iMC-RS framework supports only the following content types in
event registration and notification: application/xml and application/json.

Event receipt

When the server generates a registration event, it pushes the event in real time to the corresponding
client by using the existing HTTP connection. The following is an example.

......
if (conn.getResponseCode() == 202) {
// Registration succeeds. Start to receive the event notification.
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line = null;
StringBuilder sb = new StringBuilder();
while ((line = br.readLine()) != null) {
if (line.length() != 0) {
// The event message is not over. Continue to read the message.
sb.append(line);
} else {
// Read a complete event. Process the event.
String str = sb.toString();
sb.delete(0, sb.length());
if (!"#HEART_BEAT".equals(str)) {
// The event is not a heartbeat event. Process the event message.
......
}
}
}
......
}

Notes:

28

R&D References

Advertising