void *CbirGVT::GetGvtImagesCommon(string& access_token) const { string msg = "CbirGVT::GetGvtImagesCommon() : "; GetDataBase()->WriteLog(msg+"starting"); string endpoint, username; // Get access_token access_token = getAccessToken(username); static bool first = true; if (first) { soap_ssl_init(); // init OpenSSL (just once) first = false; } // Create the soap client ImageCollectionServiceSoapBindingProxy *imageCollection = new ImageCollectionServiceSoapBindingProxy; if (imageCollection == NULL) { cerr << "Cannot connect to Web Service. Exiting." << endl; return NULL; } if (!endpoint.empty()) { // User gave an alternate endpoint, use it imageCollection->soap_endpoint = endpoint.c_str(); } // Set the alternate cacert if needed if (!OpenXerox::GSoap::setCacert(imageCollection)) { return NULL; } // Set the proxy from the https_proxy environment variable OpenXerox::GSoap::setHttpsProxy(imageCollection); // Set authentication before each call setAuthorization(imageCollection, access_token); gvt__getLoginName loginname_payload; gvt__getLoginNameResponse loginname_response; if (imageCollection->getLoginName(&loginname_payload, &loginname_response) == SOAP_OK) { // cerr << "Your login name is: " << *loginname_response.return_ << endl; } else { soap_print_fault(imageCollection, stderr); } setAuthorization(imageCollection, access_token); return imageCollection; }
void QgsWcsCapabilities::capabilitiesReplyFinished() { if ( mCapabilitiesReply->error() == QNetworkReply::NoError ) { QVariant redirect = mCapabilitiesReply->attribute( QNetworkRequest::RedirectionTargetAttribute ); if ( !redirect.isNull() ) { emit statusChanged( tr( "Capabilities request redirected." ) ); QNetworkRequest request( redirect.toUrl() ); setAuthorization( request ); request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork ); request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true ); mCapabilitiesReply->deleteLater(); QgsDebugMsg( QString( "redirected getcapabilities: %1" ).arg( redirect.toString() ) ); mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request ); connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) ); connect( mCapabilitiesReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( capabilitiesReplyProgress( qint64, qint64 ) ) ); return; } mCapabilitiesResponse = mCapabilitiesReply->readAll(); if ( mCapabilitiesResponse.isEmpty() ) { mErrorFormat = "text/plain"; mError = tr( "empty of capabilities: %1" ).arg( mCapabilitiesReply->errorString() ); } } else { // Resend request if AlwaysCache QNetworkRequest request = mCapabilitiesReply->request(); if ( request.attribute( QNetworkRequest::CacheLoadControlAttribute ).toInt() == QNetworkRequest::AlwaysCache ) { QgsDebugMsg( "Resend request with PreferCache" ); request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache ); mCapabilitiesReply->deleteLater(); mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request ); connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) ); connect( mCapabilitiesReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( capabilitiesReplyProgress( qint64, qint64 ) ) ); return; } mErrorFormat = "text/plain"; mError = tr( "Download of capabilities failed: %1" ).arg( mCapabilitiesReply->errorString() ); QgsMessageLog::logMessage( mError, tr( "WCS" ) ); mCapabilitiesResponse.clear(); } mCapabilitiesReply->deleteLater(); mCapabilitiesReply = 0; }
void QgsWFSCapabilities::requestCapabilities() { mErrorCode = QgsWFSCapabilities::NoError; mErrorMessage.clear(); QNetworkRequest request( uriGetCapabilities() ); setAuthorization( request ); request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true ); mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request ); connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) ); }
bool QgsWcsCapabilities::sendRequest( QString const &url ) { QgsDebugMsg( "url = " + url ); mError.clear(); QNetworkRequest request( url ); QgsSetRequestInitiatorClass( request, QStringLiteral( "QgsWcsCapabilities" ) ); if ( !setAuthorization( request ) ) { mError = tr( "Download of capabilities failed: network request update failed for authentication config" ); QgsMessageLog::logMessage( mError, tr( "WCS" ) ); return false; } request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true ); request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, mCacheLoadControl ); QgsDebugMsg( QStringLiteral( "mCacheLoadControl = %1" ).arg( mCacheLoadControl ) ); QgsDebugMsg( QStringLiteral( "getcapabilities: %1" ).arg( url ) ); mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request ); if ( !setAuthorizationReply( mCapabilitiesReply ) ) { mCapabilitiesReply->deleteLater(); mCapabilitiesReply = nullptr; mError = tr( "Download of capabilities failed: network reply update failed for authentication config" ); QgsMessageLog::logMessage( mError, tr( "WCS" ) ); return false; } connect( mCapabilitiesReply, &QNetworkReply::finished, this, &QgsWcsCapabilities::capabilitiesReplyFinished ); connect( mCapabilitiesReply, &QNetworkReply::downloadProgress, this, &QgsWcsCapabilities::capabilitiesReplyProgress ); QEventLoop loop; connect( this, &QgsWcsCapabilities::downloadFinished, &loop, &QEventLoop::quit ); loop.exec( QEventLoop::ExcludeUserInputEvents ); if ( mCapabilitiesResponse.isEmpty() ) { if ( mError.isEmpty() ) { mErrorFormat = QStringLiteral( "text/plain" ); mError = tr( "empty capabilities document" ); } return false; } if ( mCapabilitiesResponse.startsWith( "<html>" ) || mCapabilitiesResponse.startsWith( "<HTML>" ) ) { mErrorFormat = QStringLiteral( "text/html" ); mError = mCapabilitiesResponse; return false; } return true; }
bool QgsWcsCapabilities::sendRequest( QString const & url ) { QgsDebugMsg( "url = " + url ); mError = ""; QNetworkRequest request( url ); if ( !setAuthorization( request ) ) { mError = tr( "Download of capabilities failed: network request update failed for authentication config" ); QgsMessageLog::logMessage( mError, tr( "WCS" ) ); return false; } request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true ); request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, mCacheLoadControl ); QgsDebugMsg( QString( "mCacheLoadControl = %1" ).arg( mCacheLoadControl ) ); QgsDebugMsg( QString( "getcapabilities: %1" ).arg( url ) ); mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request ); connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) ); connect( mCapabilitiesReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( capabilitiesReplyProgress( qint64, qint64 ) ) ); while ( mCapabilitiesReply ) { QCoreApplication::processEvents( QEventLoop::ExcludeUserInputEvents ); } if ( mCapabilitiesResponse.isEmpty() ) { if ( mError.isEmpty() ) { mErrorFormat = "text/plain"; mError = tr( "empty capabilities document" ); } return false; } if ( mCapabilitiesResponse.startsWith( "<html>" ) || mCapabilitiesResponse.startsWith( "<HTML>" ) ) { mErrorFormat = "text/html"; mError = mCapabilitiesResponse; return false; } return true; }
void QgsWFSCapabilities::capabilitiesReplyFinished() { QNetworkReply *reply = mCapabilitiesReply; reply->deleteLater(); mCapabilitiesReply = 0; // handle network errors if ( reply->error() != QNetworkReply::NoError ) { mErrorCode = QgsWFSCapabilities::NetworkError; mErrorMessage = reply->errorString(); emit gotCapabilities(); return; } // handle HTTP redirects QVariant redirect = reply->attribute( QNetworkRequest::RedirectionTargetAttribute ); if ( !redirect.isNull() ) { QgsDebugMsg( "redirecting to " + redirect.toUrl().toString() ); QNetworkRequest request( redirect.toUrl() ); setAuthorization( request ); request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork ); request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true ); mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request ); connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) ); return; } QByteArray buffer = reply->readAll(); QgsDebugMsg( "parsing capabilities: " + buffer ); // parse XML QString capabilitiesDocError; QDomDocument capabilitiesDocument; if ( !capabilitiesDocument.setContent( buffer, true, &capabilitiesDocError ) ) { mErrorCode = QgsWFSCapabilities::XmlError; mErrorMessage = capabilitiesDocError; emit gotCapabilities(); return; } QDomElement doc = capabilitiesDocument.documentElement(); // hangle exceptions if ( doc.tagName() == "ExceptionReport" ) { QDomNode ex = doc.firstChild(); QString exc = ex.toElement().attribute( "exceptionCode", "Exception" ); QDomElement ext = ex.firstChild().toElement(); mErrorCode = QgsWFSCapabilities::ServerExceptionError; mErrorMessage = exc + ": " + ext.firstChild().nodeValue(); emit gotCapabilities(); return; } mCaps.clear(); //test wfs version QString version = capabilitiesDocument.documentElement().attribute( "version" ); if ( version != "1.0.0" && version != "1.0" ) { mErrorCode = WFSVersionNotSupported; mErrorMessage = tr( "Either the WFS server does not support WFS version 1.0.0 or the WFS url is wrong" ); emit gotCapabilities(); return; } // get the <FeatureType> elements QDomNodeList featureTypeList = capabilitiesDocument.elementsByTagNameNS( WFS_NAMESPACE, "FeatureType" ); for ( unsigned int i = 0; i < featureTypeList.length(); ++i ) { FeatureType featureType; QDomElement featureTypeElem = featureTypeList.at( i ).toElement(); //Name QDomNodeList nameList = featureTypeElem.elementsByTagNameNS( WFS_NAMESPACE, "Name" ); if ( nameList.length() > 0 ) { featureType.name = nameList.at( 0 ).toElement().text(); } //Title QDomNodeList titleList = featureTypeElem.elementsByTagNameNS( WFS_NAMESPACE, "Title" ); if ( titleList.length() > 0 ) { featureType.title = titleList.at( 0 ).toElement().text(); } //Abstract QDomNodeList abstractList = featureTypeElem.elementsByTagNameNS( WFS_NAMESPACE, "Abstract" ); if ( abstractList.length() > 0 ) { featureType.abstract = abstractList.at( 0 ).toElement().text(); } //DefaultSRS is always the first entry in the feature srs list QDomNodeList defaultCRSList = featureTypeElem.elementsByTagNameNS( WFS_NAMESPACE, "DefaultSRS" ); if ( defaultCRSList.length() > 0 ) { featureType.crslist.append( defaultCRSList.at( 0 ).toElement().text() ); } //OtherSRS QDomNodeList otherCRSList = featureTypeElem.elementsByTagNameNS( WFS_NAMESPACE, "OtherSRS" ); for ( unsigned int i = 0; i < otherCRSList.length(); ++i ) { featureType.crslist.append( otherCRSList.at( i ).toElement().text() ); } //Support <SRS> for compatibility with older versions QDomNodeList srsList = featureTypeElem.elementsByTagNameNS( WFS_NAMESPACE, "SRS" ); for ( unsigned int i = 0; i < srsList.length(); ++i ) { featureType.crslist.append( srsList.at( i ).toElement().text() ); } mCaps.featureTypes.append( featureType ); } emit gotCapabilities(); }
void QgsWcsCapabilities::capabilitiesReplyFinished() { if ( mCapabilitiesReply->error() == QNetworkReply::NoError ) { QVariant redirect = mCapabilitiesReply->attribute( QNetworkRequest::RedirectionTargetAttribute ); if ( !redirect.isNull() ) { emit statusChanged( tr( "Capabilities request redirected." ) ); QNetworkRequest request( redirect.toUrl() ); QgsSetRequestInitiatorClass( request, QStringLiteral( "QgsWcsCapabilities" ) ); if ( !setAuthorization( request ) ) { mCapabilitiesResponse.clear(); mError = tr( "Download of capabilities failed: network request update failed for authentication config" ); QgsMessageLog::logMessage( mError, tr( "WCS" ) ); return; } request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork ); request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true ); mCapabilitiesReply->deleteLater(); QgsDebugMsg( QStringLiteral( "redirected getcapabilities: %1" ).arg( redirect.toString() ) ); mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request ); if ( !setAuthorizationReply( mCapabilitiesReply ) ) { mCapabilitiesResponse.clear(); mCapabilitiesReply->deleteLater(); mCapabilitiesReply = nullptr; mError = tr( "Download of capabilities failed: network reply update failed for authentication config" ); QgsMessageLog::logMessage( mError, tr( "WCS" ) ); return; } connect( mCapabilitiesReply, &QNetworkReply::finished, this, &QgsWcsCapabilities::capabilitiesReplyFinished ); connect( mCapabilitiesReply, &QNetworkReply::downloadProgress, this, &QgsWcsCapabilities::capabilitiesReplyProgress ); return; } mCapabilitiesResponse = mCapabilitiesReply->readAll(); if ( mCapabilitiesResponse.isEmpty() ) { mErrorFormat = QStringLiteral( "text/plain" ); mError = tr( "empty of capabilities: %1" ).arg( mCapabilitiesReply->errorString() ); } } else { // Resend request if AlwaysCache QNetworkRequest request = mCapabilitiesReply->request(); QgsSetRequestInitiatorClass( request, QStringLiteral( "QgsWcsCapabilities" ) ); if ( request.attribute( QNetworkRequest::CacheLoadControlAttribute ).toInt() == QNetworkRequest::AlwaysCache ) { QgsDebugMsg( QStringLiteral( "Resend request with PreferCache" ) ); request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache ); mCapabilitiesReply->deleteLater(); mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request ); if ( !setAuthorizationReply( mCapabilitiesReply ) ) { mCapabilitiesResponse.clear(); mCapabilitiesReply->deleteLater(); mCapabilitiesReply = nullptr; mError = tr( "Download of capabilities failed: network reply update failed for authentication config" ); QgsMessageLog::logMessage( mError, tr( "WCS" ) ); return; } connect( mCapabilitiesReply, &QNetworkReply::finished, this, &QgsWcsCapabilities::capabilitiesReplyFinished ); connect( mCapabilitiesReply, &QNetworkReply::downloadProgress, this, &QgsWcsCapabilities::capabilitiesReplyProgress ); return; } mErrorFormat = QStringLiteral( "text/plain" ); mError = tr( "Download of capabilities failed: %1" ).arg( mCapabilitiesReply->errorString() ); QgsMessageLog::logMessage( mError, tr( "WCS" ) ); mCapabilitiesResponse.clear(); } mCapabilitiesReply->deleteLater(); mCapabilitiesReply = nullptr; emit downloadFinished(); }