if (resultMediaType != null && resultMediaType.startsWith(MEDIATYPE_SSE)) {
try {
logger.log(Level.FINEST, "Response is SSE - about to read events");
closeSse = false;
ProprietaryReader<GfSseEventReceiver> reader = new GfSseEventReceiverProprietaryReader();
GfSseEventReceiver eventReceiver = reader.readFrom(urlConnection.getInputStream(), resultMediaType);
GfSseInboundEvent event;
String instanceId = null;
do {
event = eventReceiver.readEvent();
if (event != null) {
if (logger.isLoggable(Level.FINEST)) {
logger.log(Level.FINEST, "Event: {0}", event.getName());
}
fireEvent(event.getName(), event);
if (AdminCommandState.EVENT_STATE_CHANGED.equals(event.getName())) {
AdminCommandState acs = event.getData(AdminCommandState.class, MEDIATYPE_JSON);
if (acs.getId() != null) {
instanceId = acs.getId();
if (logger.isLoggable(Level.FINEST)) {
logger.log(Level.FINEST, "Command instance ID: {0}", instanceId);
}
}
if (acs.getState() == AdminCommandState.State.COMPLETED ||
acs.getState() == AdminCommandState.State.RECORDED) {
if (acs.getActionReport() != null) {
setActionReport(acs.getActionReport());
}
closeSse = true;
if (!acs.isOutboundPayloadEmpty()) {
logger.log(Level.FINEST, "Romote command holds data. Must load it");
downloadPayloadFromManaged(instanceId);
}
}
}
}
} while (event != null && !eventReceiver.isClosed() && !closeSse);
if (closeSse) {
try { eventReceiver.close(); } catch (Exception exc) {}
}
} catch (Exception ex) {
throw new CommandException(ex.getMessage(), ex);
}
} else {