return verifyInnerElementWorker(stanza, "query");
}
@Override
protected Stanza handleGet(IQStanza stanza, ServerRuntimeContext serverRuntimeContext, SessionContext sessionContext) {
ServiceCollector serviceCollector = null;
// TODO if the target entity does not exist, return error/cancel/item-not-found
// TODO more strictly, server can also return error/cancel/service-unavailable
// retrieve the service collector
try {
serviceCollector = (ServiceCollector)serverRuntimeContext.getServerRuntimeContextService(ServiceDiscoveryRequestListenerRegistry.SERVICE_DISCOVERY_REQUEST_LISTENER_REGISTRY);
} catch (Exception e) {
logger.error("error retrieving ServiceCollector service {}", e);
serviceCollector = null;
}
if (serviceCollector == null) {
return ServerErrorResponses.getInstance().getStanzaError(StanzaErrorCondition.INTERNAL_SERVER_ERROR, stanza,
StanzaErrorType.CANCEL,
"cannot retrieve IQ-get-info result from internal components",
getErrorLanguage(serverRuntimeContext, sessionContext), null);
}
// if "vysper.org" is the server entity, 'to' can either be "vysper.org", "node@vysper.org", "service.vysper.org".
Entity to = stanza.getTo();
boolean isServerInfoRequest = false;
boolean isComponentInfoRequest = false;
Entity serviceEntity = serverRuntimeContext.getServerEnitity();
if (to == null || to.equals(serviceEntity)) {
isServerInfoRequest = true; // this can only be meant to query the server
} else if (serverRuntimeContext.getComponentStanzaProcessor(to.getDomain()) != null) {
isComponentInfoRequest = true; // this is a query to a component
} else if (!to.isNodeSet()) {
isServerInfoRequest = serviceEntity.equals(to);
if (!isServerInfoRequest) {
return ServerErrorResponses.getInstance().getStanzaError(StanzaErrorCondition.ITEM_NOT_FOUND, stanza,
StanzaErrorType.CANCEL,
"server does not handle info query requests for " + to.getFullQualifiedName(),
getErrorLanguage(serverRuntimeContext, sessionContext), null);
}
}
XMLElement queryElement = stanza.getFirstInnerElement();
String node = queryElement != null ? queryElement.getAttributeValue("node") : null;
// collect all the info response elements
List<InfoElement> elements = null;
try {
if (isServerInfoRequest) {
elements = serviceCollector.processServerInfoRequest(new InfoRequest(stanza.getFrom(), to, node, stanza.getID()));
} else if (isComponentInfoRequest) {
elements = serviceCollector.processComponentInfoRequest(new InfoRequest(stanza.getFrom(), to, node, stanza.getID()));
} else {
elements = serviceCollector.processInfoRequest(new InfoRequest(stanza.getFrom(), to, node, stanza.getID()));
}
} catch (ServiceDiscoveryRequestException e) {
// the request yields an error
StanzaErrorCondition stanzaErrorCondition = e.getErrorCondition();
if (stanzaErrorCondition == null) stanzaErrorCondition = StanzaErrorCondition.INTERNAL_SERVER_ERROR;