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


C++ Response::getBodyPtr方法代码示例

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


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

示例1: responseTree

/* 
 * Throws XMLTree::PraseException and other 
 * std::exception's from string methods 
 */
std::vector<std::string>
BaseService::parseGenericResponse(const Http::Response& response,
				  const char *expectedId) const
{
    XMLTree responseTree(false, response.getBodyPtr(), response.getBodyLen());
    XMLElement element = responseTree.getRootElement();
    std::vector<std::string> responses;

    if (element.isNamed(RESPONSE_SET)) {
	std::string version;
	std::string requestId;

	if (element.getAttributeValue(VERSION, version) &&
	    std::strcmp(version.c_str(), RESPONSE_SET_VERSION) == 0 &&
	    element.getAttributeValue(REQUEST_ID, requestId) &&
	    std::strcmp(requestId.c_str(), expectedId) == 0) {
	    std::string responseData;

	    for (element = element.getFirstSubElement();
		 element.isNamed(RESPONSE);
		 element.nextSibling()) {
		if (element.getValue(responseData)) {
		    responses.push_back(responseData);
		} else {
		    element.log(logModule, Log::LOG_ERROR);
		    throw XMLTree::ParseException("unable to get Response "
						  "data");
		}
	    }
	    if (element.isValid()) {
		element.log(logModule, Log::LOG_ERROR);
		throw XMLTree::ParseException("unexpected element in "
					      "ResponseSet");
	    }
	} else if (std::strcmp(version.c_str(), RESPONSE_SET_VERSION) == 0) {
	    element.log(logModule, Log::LOG_ERROR);
	    throw XMLTree::ParseException(std::string("missing or mismatched "
						      "request id in "
						      "ResponseSet: ") +
					  requestId);
	} else {
	    element.log(logModule, Log::LOG_ERROR);
	    throw XMLTree::ParseException(std::string("missing or unsupported "
						      "version in "
						      "ResponseSet: ") +
					  version);
	}
    } else {
	element.log(logModule, Log::LOG_ERROR);
	throw XMLTree::ParseException("unexpected element in response");
    }

    return responses;
}
开发者ID:,项目名称:,代码行数:58,代码来源:

示例2: getAgentAttributes

/**
 * Fetches agent profile attributes using REST attribute service
 * Agent has to be authenticated before doing this.
 * If successful, properties object gets loaded with profile attributes
 */
am_status_t AgentProfileService::getAgentAttributes(
    const std::string appSSOToken, 
    const std::string sharedAgentProfileName, 
    const std::string realmName, 
    am_properties_t properties)
{
    am_status_t status = AM_FAILURE;
    Http::Response response;
    std::string certName;
    std::string::size_type pos;

    std::string encodedAgentToken = Http::encode(appSSOToken);
    std::string encodedSharedAgentProfileName = Http::encode(sharedAgentProfileName);
    std::string encodedRealmName = Http::encode(realmName);

    std::string urlParams = "?name=";
    urlParams.append(encodedSharedAgentProfileName);
    urlParams.append("&attributes_names=realm");
    urlParams.append("&attributes_values_realm=");
    urlParams.append(encodedRealmName); 
    urlParams.append("&attributes_names=objecttype");
    urlParams.append("&attributes_values_objecttype=Agent" );
    urlParams.append("&admin=" );
    urlParams.append(encodedAgentToken);

    try {
        setRestSvcInfo(mRestURL);
    } catch (InternalException &iex) {
        status = AM_FAILURE;
    }
    
    status =  doHttpGet(mRestSvcInfo, urlParams, Http::CookieList(),
                        response, READ_INIT_BUF_LEN,
                        certName);
    if(status == AM_SUCCESS) {
        std::string xmlResponse(response.getBodyPtr());
        pos = xmlResponse.find(EXCEPTION,0);
        if(pos != std::string::npos){
            status = AM_REST_ATTRS_SERVICE_FAILURE;
        } else {
            try {
                status = parseAgentResponse(xmlResponse, properties);
            } catch(...) {
                Log::log(logModule, Log::LOG_ERROR, 
                    "parseAgentResponse(): Attribute xml parsing error");
                status = AM_REST_ATTRS_SERVICE_FAILURE;
            }
        }
    } else {
        status = AM_REST_ATTRS_SERVICE_FAILURE;
    }
   return status;

}
开发者ID:dromero91,项目名称:openam,代码行数:59,代码来源:agent_profile_service.cpp

示例3: contentLineChunk


//.........这里部分代码省略.........
		        for(std::size_t i = 0; i<bodyChunkList.size(); ++i) {
			    if(!bodyChunkList[i].secure) {
			        commString.append(bodyChunkList[i].data);
			    } else {
			        commString.append("<secure data>");
			    }
		        }
		        for(std::size_t commPos = commString.find("%");
		    	    commPos != std::string::npos &&
			    commPos < commString.size();
			    commPos = commString.find("%", commPos)) {
			    commString.replace(commPos, 1, "%%");
			    commPos += 2;
		        }
		        Log::log(logModule, Log::LOG_MAX_DEBUG,
			     commString.c_str());
		    }

                    std::string requestString = iter->getURI();
                    /*
                     * In case the following request would go to a proxy
                     * we need to use full URL and special headers.
                     * If the resource is HTTPS, we're not posting our
                     * request to the proxy, but to the server 
                     * through proxy tunnel
                     */

                    if (useProxy && !(iter->useSSL())) {
                        requestString = iter->getURL();
                        headerList = proxyHeaderList;
                    }
		    status = sendRequest(conn, headerPrefix, requestString,
				     uriParameters, headerList, cookieList,
				     contentLineChunk, headerSuffix,
				     bodyChunkList);
		    if (AM_SUCCESS == status) {
		        operation = "receiving from";
		        status = response.readAndParse(logModule, conn,
						   initialBufferLen);
		        if (AM_SUCCESS == status) {
			    Log::log(logModule, Log::LOG_MAX_DEBUG, "%.*s",
				 response.getBodyLen(), response.getBodyPtr());
		        }
		    }

		    if (AM_NSPR_ERROR == status) {
		        PRErrorCode nspr_code = PR_GetError();
		        Log::log(logModule, Log::LOG_ALWAYS,
			     "BaseService::doRequest() NSPR failure while "
			     "%s %s, error = %s", operation,
			     (*iter).toString().c_str(), 
			     PR_ErrorToName(nspr_code));
		    }
		
		    if (AM_SUCCESS == status) {
		        if(serverInfo != NULL) *serverInfo = &(*iter);
		            break;
		    } else {
                        if(retryCount < retryAttempts) {
                            continue;
                        } else {
                           Log::log(logModule, Log::LOG_DEBUG,
                               "BaseService::doRequest() Invoking markSeverDown");
                           svrInfo.markServerDown(poll_primary_server);
                        }
		    }
	        } catch (const NSPRException& exc) {
		    Log::log(logModule, Log::LOG_DEBUG,
			 "BaseService::doRequest() caught %s: %s called by %s "
			 "returned %s", exc.what(), exc.getNsprMethod(),
			 exc.getThrowingMethod(), 
			 PR_ErrorToName(exc.getErrorCode()));

                   if(retryCount < retryAttempts) {
		       status = AM_NSPR_ERROR;
                       continue;
                    } else {
                       Log::log(logModule, Log::LOG_DEBUG,
                           "BaseService::doRequest() Invoking markSeverDown");
                       svrInfo.markServerDown(poll_primary_server);
		       status = AM_NSPR_ERROR;
                    }
	        }
            } //end of while

            if (AM_SUCCESS == status) {
               if(serverInfo != NULL) *serverInfo = &(*iter);
                    break;
            }
            if (status = AM_NSPR_ERROR) {
               continue;
            }

	} // end of for
    } else {
	status = AM_BUFFER_TOO_SMALL;
    }

    return status;
}
开发者ID:,项目名称:,代码行数:101,代码来源:

示例4: contentLineChunk


//.........这里部分代码省略.........
                    // allocate enough for a base64-encoded digest
                    size_t authSize = proxyUser.size() +
                            proxyPassword.size() + 1;
                    // 11 extra bytes for prefix and terminator
                    char * digest = (char *) malloc(authSize * 4 / 3 + 11);
                    strcpy(digest, "Basic ");
                    encode_base64((proxyUser + ":" + proxyPassword).c_str(),
                            authSize, (digest + 6));
                    Log::log(logModule, Log::LOG_MAX_DEBUG,
                            "BaseService::doRequest(): Using proxy auth as: %s",
                            proxyUser.c_str());
                    hostHeader = Http::Cookie("Proxy-Authorization", digest);
                    proxyHeaderList.push_back(hostHeader);
                    free(digest);
                }
            }
#endif
#endif

            // retry to connect to server before marking it as down.
            // making the number of attempts configurable may have a negative
            // side effect on performance, if the the value is a high number.
            int retryAttempts = 3;
            int retryCount = 0;
            while (retryCount < retryAttempts) {
                retryCount++;
                try {
                    const char *operation = "sending to";
                    Connection conn(svrInfo.getHost().c_str(), svrInfo.getPort(), svrInfo.useSSL());
#ifdef AGENT_PROXY_SUPPORT
                    std::string requestString = svrInfo.getURI().c_str();
                    /*
                     * In case the following request would go to a proxy
                     * we need to use full URL and special headers.
                     */

                    if (useProxy && !(iter->useSSL())) {
                       requestString = iter->getURL();
                       headerList = proxyHeaderList;
                    }
#endif
                    status = sendRequest(conn, headerPrefix, svrInfo.getURI(),
                            uriParameters, headerList, cookieList,
                            dataLen > 0 ? contentLineChunk : emptyContentLine, headerSuffix,
                            bodyChunkList);
                    if (AM_SUCCESS == status) {
                        operation = "receiving from";
                        status = response.readAndParse(logModule, conn);
                        if (AM_SUCCESS == status) {
                            Log::log(logModule, Log::LOG_MAX_DEBUG, "Response::readAndParse() (%d) %s",
                                    response.getBodyLen(), response.getBodyPtr() ? response.getBodyPtr() : "(NULL)");
                        }
                    }

                    if (AM_NSPR_ERROR == status) {
                        Log::log(logModule, Log::LOG_ALWAYS,
                                "BaseService::doRequest() NSPR failure while "
                                "%s %s", operation,
                                svrInfo.getURL().c_str());
                    }

                    if (AM_SUCCESS == status) {
                        break;
                    } else {
                        if (retryCount < retryAttempts) {
                            continue;
                        } else {
                            Log::log(logModule, Log::LOG_DEBUG,
                                    "BaseService::doRequest() Invoking markSeverDown");
                            /*svrInfo.markServerDown(poll_primary_server);*/
                        }
                    }
                } catch (const NSPRException& exc) {
                    Log::log(logModule, Log::LOG_ERROR,
                            "BaseService::doRequest() caught %s: %s called by %s", exc.what(), exc.getNsprMethod(),
                            exc.getThrowingMethod());

                    if (retryCount < retryAttempts) {
                        status = AM_NSPR_ERROR;
                        continue;
                    } else {
                        Log::log(logModule, Log::LOG_ERROR,
                                "BaseService::doRequest() Invoking markSeverDown");
                        /*svrInfo.markServerDown(poll_primary_server);*/
                        status = AM_NSPR_ERROR;
                    }
                }
            } //end of while

            if (AM_SUCCESS == status) {
                break;
            }

        } // end of for
    } else {
        status = AM_BUFFER_TOO_SMALL;
    }

    return status;
}
开发者ID:JonathanFu,项目名称:OpenAM-1,代码行数:101,代码来源:base_service.cpp


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