handleGetAppInfoResponse_(appName, xhr) {
    XhrUtils.logRawXhr(this.logger_, 'GetAppInfo', 'GET', xhr);
    if (!XhrUtils.isSuccess(xhr)) {
      if (xhr.status == NetUtils.HttpStatus.NOT_FOUND) {
        throw new AppInfoNotFoundError();
      } else {
        throw new Error(`Response error: ${xhr.status}`);
      }
    }

    const xml = XhrUtils.parseXml(xhr.responseText);
    if (!xml) {
      this.logger_.info('Invalid or empty response');
      throw new Error('Invalid or empty response');
    }

    const service = xml.getElementsByTagName('service');
    if (!service || service.length != 1) {
      this.logger_.info('Invalid GET response (invalid service)');
      throw new Error('Invalid GET response (invalid service)');
    }
    const appInfo = new AppInfo();
    for (var i = 0, l = service[0].childNodes.length; i < l; i++) {
      const node = service[0].childNodes[i];
      if (node.nodeName == 'state') {
        appInfo.state = Client.parseDialAppState_(node.textContent);
      } else if (node.nodeName == 'name') {
        appInfo.name = node.textContent;
      } else if (node.nodeName == 'link') {
        appInfo.resource = node.getAttribute('href');
      } else if (node.nodeName == 'options') {
        // The default value for allowStop is true per DIAL spec.
        appInfo.allowStop = (node.getAttribute('allowStop') != 'false');
      } else {
        appInfo.extraData[node.nodeName] = node.innerHTML;
      }
    }

    // Validate mandatory fields (name, state).
    if (appInfo.name == 'unknown') {
      this.logger_.info('GET response missing name value');
      throw new Error('GET response missing name value');
    }

    if (appInfo.name != appName) {
      this.logger_.info('GET app name mismatch');
      throw new Error('GET app name mismatch');
    }

    if (appInfo.state == DialAppState.ERROR) {
      this.logger_.info('GET response missing state value');
      throw new Error('GET response missing state value');
    }

    // Parse state.
    const installable = /installable=(.+)/.exec(appInfo.state);
    if (installable && installable[1]) {
      appInfo.state = DialAppState.INSTALLABLE;
      appInfo.installUrl = installable[1];
    } else if (
        appInfo.state == DialAppState.RUNNING ||
        appInfo.state == DialAppState.STOPPED) {
      // Valid state.  Continue.
    } else {
      this.logger_.info('GET response has invalid state value');
      throw new Error('GET response has invalid state value');
    }

    // Success!
    return appInfo;
  }
/**
   * Parses the response from a Xhr GET request.
   * @param {string} appName App nam used in the request.
   * @param {!XMLHttpRequest} xhr
   * @return {!AppInfo}
   * @private
   */
Parses the response from a Xhr GET request.
@param {string} appName App nam used in the request.
Parses the response from a Xhr GET request . @param { string } appName App nam used in the request .
handleGetAppInfoResponse_(appName, xhr) {
    XhrUtils.logRawXhr(this.logger_, 'GetAppInfo', 'GET', xhr);
    if (!XhrUtils.isSuccess(xhr)) {
      if (xhr.status == NetUtils.HttpStatus.NOT_FOUND) {
        throw new AppInfoNotFoundError();
      } else {
        throw new Error(`Response error: ${xhr.status}`);
      }
    }
    const xml = XhrUtils.parseXml(xhr.responseText);
    if (!xml) {
      this.logger_.info('Invalid or empty response');
      throw new Error('Invalid or empty response');
    }
    const service = xml.getElementsByTagName('service');
    if (!service || service.length != 1) {
      this.logger_.info('Invalid GET response (invalid service)');
      throw new Error('Invalid GET response (invalid service)');
    }
    const appInfo = new AppInfo();
    for (var i = 0, l = service[0].childNodes.length; i < l; i++) {
      const node = service[0].childNodes[i];
      if (node.nodeName == 'state') {
        appInfo.state = Client.parseDialAppState_(node.textContent);
      } else if (node.nodeName == 'name') {
        appInfo.name = node.textContent;
      } else if (node.nodeName == 'link') {
        appInfo.resource = node.getAttribute('href');
      } else if (node.nodeName == 'options') {
        appInfo.allowStop = (node.getAttribute('allowStop') != 'false');
      } else {
        appInfo.extraData[node.nodeName] = node.innerHTML;
      }
    }
    if (appInfo.name == 'unknown') {
      this.logger_.info('GET response missing name value');
      throw new Error('GET response missing name value');
    }
    if (appInfo.name != appName) {
      this.logger_.info('GET app name mismatch');
      throw new Error('GET app name mismatch');
    }
    if (appInfo.state == DialAppState.ERROR) {
      this.logger_.info('GET response missing state value');
      throw new Error('GET response missing state value');
    }
    const installable = /installable=(.+)/.exec(appInfo.state);
    if (installable && installable[1]) {
      appInfo.state = DialAppState.INSTALLABLE;
      appInfo.installUrl = installable[1];
    } else if (
        appInfo.state == DialAppState.RUNNING ||
        appInfo.state == DialAppState.STOPPED) {
    } else {
      this.logger_.info('GET response has invalid state value');
      throw new Error('GET response has invalid state value');
    }
    return appInfo;
  }
handleGetAppInfoResponse_ ( appName , xhr ) { XhrUtils . logRawXhr ( this . logger_ , 'GetAppInfo' , 'GET' , xhr ) ; if ( ! XhrUtils . isSuccess ( xhr ) ) { if ( xhr . status == NetUtils . HttpStatus . NOT_FOUND ) { throw new AppInfoNotFoundError ( ) ; } else { throw new Error ( ` ${ xhr . status } ` ) ; } } const xml = XhrUtils . parseXml ( xhr . responseText ) ; if ( ! xml ) { this . logger_ . info ( 'Invalid or empty response' ) ; throw new Error ( 'Invalid or empty response' ) ; } const service = xml . getElementsByTagName ( 'service' ) ; if ( ! service || service . length != 1 ) { this . logger_ . info ( 'Invalid GET response (invalid service)' ) ; throw new Error ( 'Invalid GET response (invalid service)' ) ; } const appInfo = new AppInfo ( ) ; for ( var i = 0 , l = service [ 0 ] . childNodes . length ; i < l ; i ++ ) { const node = service [ 0 ] . childNodes [ i ] ; if ( node . nodeName == 'state' ) { appInfo . state = Client . parseDialAppState_ ( node . textContent ) ; } else if ( node . nodeName == 'name' ) { appInfo . name = node . textContent ; } else if ( node . nodeName == 'link' ) { appInfo . resource = node . getAttribute ( 'href' ) ; } else if ( node . nodeName == 'options' ) { appInfo . allowStop = ( node . getAttribute ( 'allowStop' ) != 'false' ) ; } else { appInfo . extraData [ node . nodeName ] = node . innerHTML ; } } if ( appInfo . name == 'unknown' ) { this . logger_ . info ( 'GET response missing name value' ) ; throw new Error ( 'GET response missing name value' ) ; } if ( appInfo . name != appName ) { this . logger_ . info ( 'GET app name mismatch' ) ; throw new Error ( 'GET app name mismatch' ) ; } if ( appInfo . state == DialAppState . ERROR ) { this . logger_ . info ( 'GET response missing state value' ) ; throw new Error ( 'GET response missing state value' ) ; } const installable = / installable=(.+) / . exec ( appInfo . state ) ; if ( installable && installable [ 1 ] ) { appInfo . state = DialAppState . INSTALLABLE ; appInfo . installUrl = installable [ 1 ] ; } else if ( appInfo . state == DialAppState . RUNNING || appInfo . state == DialAppState . STOPPED ) { } else { this . logger_ . info ( 'GET response has invalid state value' ) ; throw new Error ( 'GET response has invalid state value' ) ; } return appInfo ; }
Parses the response from a Xhr GET request.
Parses the response from a Xhr GET request .
// The default value for allowStop is true per DIAL spec. // Validate mandatory fields (name, state). // Parse state. // Valid state.  Continue. // Success!