public ServiceMetadata getMetadataInfoFromWMTS(String urlServer) {

    ServiceMetadata servMetadata = new ServiceMetadata();

    try {
      // get WMTS manager
      WMTSOGCManager wmtsMan = WMTSOGCLocator.getManager();

      WMTSClient wmtsClient = wmtsMan.createWMTSClient(urlServer);
      wmtsClient.connect(true, null);

      WMTSServiceIdentification wmtsServIden = wmtsClient.getServiceIdentification();

      servMetadata.setUrl(urlServer);
      servMetadata.setName(wmtsServIden.getServiceType());
      servMetadata.setAbstractStr(wmtsServIden.getAbstract());
      servMetadata.setAccessConstraints(wmtsServIden.getAccessConstraints());
      servMetadata.setFees(wmtsServIden.getFees());
      servMetadata.setKeywords(StringUtils.join(wmtsServIden.getKeywords(), ','));
      servMetadata.setVersion(wmtsServIden.getServiceTypeVersion());
      servMetadata.setTitle(wmtsServIden.getTitle());

      // get contact info
      WMTSServiceProvider serviceProvider = wmtsClient.getServiceProvider();

      ContactMetadata contact = null;
      // TODO I can't get all the info of contact and contact address
      if (StringUtils.isNotEmpty(serviceProvider.getServiceContact())
          || StringUtils.isNotEmpty(serviceProvider.getProviderName())) {
        contact = new ContactMetadata();
        contact.setPerson(serviceProvider.getServiceContact());
        contact.setOrganization(serviceProvider.getProviderName());
      }
      servMetadata.setContact(contact);

      // get layers
      List<Layer> lstLayers = null;
      WMTSThemes layerListAsThemes = wmtsClient.getLayerListAsThemes();
      if (layerListAsThemes != null && layerListAsThemes.getChildCount() > 0) {
        lstLayers = new ArrayList<Layer>();
        for (int i = 0; i < layerListAsThemes.getChildCount(); i++) {
          WMTSTheme wmtsTheme = layerListAsThemes.getChildren(i);
          WMTSLayer wmtsLayer = wmtsTheme.getLayer();
          Layer layer = new Layer();
          layer.setName(wmtsLayer.getIdentifier());
          layer.setTitle(wmtsLayer.getTitle());
          lstLayers.add(layer);
        }
      }
      servMetadata.setLayers(lstLayers);

    } catch (Exception exc) {
      // Show exception in log
      logger.error("Exception on getMetadataInfoFromWMTS", exc);
      throw new ServerGeoException();
    }

    return servMetadata;
  }
  public ServiceMetadata getMetadataInfoFromWMS(String urlServer) {

    ServiceMetadata servMetadata = new ServiceMetadata();

    try {
      WMSClient wms = new WMSClient(urlServer);
      wms.connect(null);

      // set server information
      WMSServiceInformation serviceInfo = wms.getServiceInformation();

      servMetadata.setAbstractStr(serviceInfo.abstr);
      servMetadata.setFees(serviceInfo.fees);
      servMetadata.setKeywords(serviceInfo.keywords);
      servMetadata.setName(serviceInfo.name);
      servMetadata.setTitle(serviceInfo.title);
      servMetadata.setUrl(urlServer);
      servMetadata.setVersion(serviceInfo.version);
      // I can't get from service the accessConstraints value
      // servMetadata.setAccessConstraints(accessConstraints);

      // get layers
      TreeMap layers = wms.getLayers();
      if (layers != null) {
        List<Layer> lstLayers = new ArrayList<Layer>();
        Set<String> keys = layers.keySet();
        for (String key : keys) {
          WMSLayer wmsLayer = (WMSLayer) layers.get(key);
          Layer layer = new Layer();
          layer.setName(wmsLayer.getName());
          layer.setTitle(wmsLayer.getTitle());
          lstLayers.add(layer);
        }
        servMetadata.setLayers(lstLayers);
      }

      // get operations
      Hashtable supportedOperations = serviceInfo.getSupportedOperationsByName();
      if (supportedOperations != null) {
        List<OperationsMetadata> lstOperations = new ArrayList<OperationsMetadata>();
        Set<String> keys = supportedOperations.keySet();
        for (String key : keys) {
          OperationsMetadata opMetadata = new OperationsMetadata();
          opMetadata.setName(key);
          opMetadata.setUrl((String) supportedOperations.get(key));
          lstOperations.add(opMetadata);
        }
        servMetadata.setOperations(lstOperations);
      }
      // get contact address
      ContactAddressMetadata contactAddress = null;
      if (StringUtils.isNotEmpty(serviceInfo.address)
          || StringUtils.isNotEmpty(serviceInfo.addresstype)
          || StringUtils.isNotEmpty(serviceInfo.place)
          || StringUtils.isNotEmpty(serviceInfo.country)
          || StringUtils.isNotEmpty(serviceInfo.postcode)
          || StringUtils.isNotEmpty(serviceInfo.province)) {
        contactAddress = new ContactAddressMetadata();
        contactAddress.setAddress(serviceInfo.address);
        contactAddress.setAddressType(serviceInfo.addresstype);
        contactAddress.setCity(serviceInfo.place);
        contactAddress.setCountry(serviceInfo.country);
        contactAddress.setPostCode(serviceInfo.postcode);
        contactAddress.setStateProvince(serviceInfo.province);
      }

      // get contact info
      ContactMetadata contactMetadata = null;
      if (contactAddress != null
          || StringUtils.isNotEmpty(serviceInfo.email)
          || StringUtils.isNotEmpty(serviceInfo.fax)
          || StringUtils.isNotEmpty(serviceInfo.organization)
          || StringUtils.isNotEmpty(serviceInfo.personname)
          || StringUtils.isNotEmpty(serviceInfo.function)
          || StringUtils.isNotEmpty(serviceInfo.phone)) {
        contactMetadata = new ContactMetadata();
        contactMetadata.setContactAddress(contactAddress);
        contactMetadata.setEmail(serviceInfo.email);
        contactMetadata.setFax(serviceInfo.fax);
        contactMetadata.setOrganization(serviceInfo.organization);
        contactMetadata.setPerson(serviceInfo.personname);
        contactMetadata.setPosition(serviceInfo.function);
        contactMetadata.setTelephone(serviceInfo.phone);
      }
      servMetadata.setContact(contactMetadata);

    } catch (Exception exc) {
      // Show exception in log
      logger.error("Exception on getMetadataInfoFromWMS", exc);
      throw new ServerGeoException();
    }

    return servMetadata;
  }