当前位置: 首页>>代码示例>>C++>>正文


C++ Endpoint::getPublicUrl方法代码示例

本文整理汇总了C++中Endpoint::getPublicUrl方法的典型用法代码示例。如果您正苦于以下问题:C++ Endpoint::getPublicUrl方法的具体用法?C++ Endpoint::getPublicUrl怎么用?C++ Endpoint::getPublicUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Endpoint的用法示例。


在下文中一共展示了Endpoint::getPublicUrl方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: authHeader

SwiftResult<HTTPClientSession*>* Object::swiftCreateReplaceObject(std::ostream* &outputStream,
    std::vector<HTTPHeader>* _uriParams, std::vector<HTTPHeader>* _reqMap) {
  //Check Container
  if (container == nullptr)
    return returnNullError<HTTPClientSession*>("container");

  if (container->getAccount() == nullptr)
    return returnNullError<HTTPClientSession*>("account");
  Endpoint* swiftEndpoint =
      container->getAccount()->getSwiftService()->getFirstEndpoint();
  if (swiftEndpoint == nullptr)
    return returnNullError<HTTPClientSession*>("SWIFT Endpoint");

  //Create parameter map
  vector<HTTPHeader> reqParamMap;
  //Add authentication token
  string tokenID = container->getAccount()->getToken()->getId();
  HTTPHeader authHeader("X-Auth-Token", tokenID);
  reqParamMap.push_back(authHeader);
  //Push Chuncked Encoding
  HTTPHeader encHeader("Transfer-Encoding", "chunked");
  reqParamMap.push_back(encHeader);
  //Add rest of request Parameters
  if (_reqMap != nullptr && _reqMap->size() > 0) {
    for (uint i = 0; i < _reqMap->size(); i++) {
      reqParamMap.push_back(_reqMap->at(i));
    }
  }

  //Path
  string path = container->getName() + "/" + name;
  URI uri(swiftEndpoint->getPublicUrl());
  string encoded;
  URI::encode(path,"",encoded);
  path = encoded;
  uri.setPath(uri.getPath() + "/" + path);

  if (_uriParams != nullptr && _uriParams->size() > 0) {
    //Create appropriate URI
    ostringstream queryStream;
    for (uint i = 0; i < _uriParams->size(); i++) {
      if (i > 0)
        queryStream << ",";
      queryStream << _uriParams->at(i).getQueryValue();
    }
    uri.setQuery(queryStream.str());
    //cout << uri.toString() << endl;
  }

  //Creating HTTP Session
  HTTPClientSession *httpSession = nullptr;
  try {
    /** This operation does not accept a request body. **/
    httpSession = doHTTPIO(uri, HTTPRequest::HTTP_PUT, &reqParamMap, outputStream);
    //Now we should increase number of calls to SWIFT API
    container->getAccount()->increaseCallCounter();
  } catch (Exception &e) {
    SwiftResult<HTTPClientSession*> *result = new SwiftResult<HTTPClientSession*>();
    SwiftError error(SwiftError::SWIFT_EXCEPTION, e.displayText());
    result->setError(error);
    //Try to set HTTP Response as the payload
    result->setSession(httpSession);
    result->setResponse(nullptr);
    result->setPayload(nullptr);
    return result;
  }

  //Everything seems fine
  SwiftResult<HTTPClientSession*> *result = new SwiftResult<HTTPClientSession*>();
  result->setError(SWIFT_OK);
  result->setSession(httpSession);
  result->setResponse(nullptr);
  result->setPayload(httpSession);
  return result;
}
开发者ID:RobinSystems,项目名称:Swift_CPP_SDK,代码行数:75,代码来源:Object.cpp

示例2: authHeader

SwiftResult<T>* doSwiftTransaction(Account *_account, std::string &_uriPath,
    const std::string &_method, std::vector<HTTPHeader>* _uriParams,
    std::vector<HTTPHeader>* _reqMap, std::vector<int> *_httpValidCodes,
    const char *bodyReqBuffer, ulong size, std::string *contentType) {
  //Start locking
  lock_guard<recursive_mutex> guard(transactionMutex);
  //Start of function
  if (_account == nullptr)
    return returnNullError<T>("account");
  Endpoint* swiftEndpoint = _account->getSwiftService()->getFirstEndpoint();
  if (swiftEndpoint == nullptr)
    return returnNullError<T>("SWIFT Endpoint");

  //Create parameter map
  vector<HTTPHeader> reqParamMap;
  //Add authentication token
  string tokenID = _account->getToken()->getId();
  HTTPHeader authHeader("X-Auth-Token", tokenID);
  reqParamMap.push_back(authHeader);
  //Add rest of request Parameters
  if (_reqMap != nullptr && _reqMap->size() > 0) {
    for (uint i = 0; i < _reqMap->size(); i++) {
      reqParamMap.push_back(_reqMap->at(i));
    }
  }

  URI uri(swiftEndpoint->getPublicUrl());
  string encoded;
  URI::encode(_uriPath,"",encoded);
  _uriPath = encoded;
  if (uri.getPath().size() > 0)
    uri.setPath(uri.getPath() + "/" + _uriPath);
  else
    uri.setPath(_uriPath);

  if (_uriParams != nullptr && _uriParams->size() > 0) {
    //Create appropriate URI
    ostringstream queryStream;
    //queryStream << "?";
    for (uint i = 0; i < _uriParams->size(); i++) {
      if (i > 0)
        queryStream << ",";
      queryStream << _uriParams->at(i).getQueryValue();
    }
    uri.setQuery(queryStream.str());
  }

  //Creating HTTP Session
  HTTPResponse *httpResponse = new HTTPResponse();
  HTTPClientSession *httpSession = nullptr;
  istream* resultStream = nullptr;

  try {
    /** This operation does not accept a request body. **/
    if (bodyReqBuffer == nullptr)
      httpSession = doHTTPIO(uri, _method, &reqParamMap);
    else {
      if (contentType != nullptr)
        httpSession = doHTTPIO(uri, _method, &reqParamMap, bodyReqBuffer, size,
            *contentType);
      else
        httpSession = doHTTPIO(uri, _method, &reqParamMap, bodyReqBuffer, size,"");
    }

    //Now we should increase number of calls to SWIFT API
    _account->increaseCallCounter();
    if (std::is_same<T, std::istream*>::value)
      resultStream = &httpSession->receiveResponse(*httpResponse);
    else
    	httpSession->receiveResponse(*httpResponse);
  } catch (Exception &e) {
    SwiftResult<T> *result = new SwiftResult<T>();
    SwiftError error(SwiftError::SWIFT_EXCEPTION, e.displayText());
    result->setError(error);
    //Try to set HTTP Response as the payload
    result->setSession(httpSession);
    result->setResponse(httpResponse);
    result->setPayload(nullptr);
    return result;
  }

  /**
   * Check HTTP return code
   */
  bool valid = false;
  for (uint i = 0; i < _httpValidCodes->size(); i++)
    if (_httpValidCodes->at(i) == httpResponse->getStatus()) {
      valid = true;
      break;
    }

  if (!valid) {
  	cout<<"Invalid Return code:";
    httpResponse->write(cout);
    if(httpResponse->getStatus() == 200)
    	cerr<<"bullshit"<<endl;
    if(httpResponse->getStatus() == HTTPResponse::HTTP_UNAUTHORIZED) {
      if(_account->reAuthenticate()) {
        delete httpSession;httpSession = nullptr;
        delete httpResponse;httpResponse = nullptr;
//.........这里部分代码省略.........
开发者ID:RobinSystems,项目名称:Swift_CPP_SDK,代码行数:101,代码来源:HTTPIO.cpp


注:本文中的Endpoint::getPublicUrl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。