當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpMethodBase.setRequestHeader方法代碼示例

本文整理匯總了Java中org.apache.commons.httpclient.HttpMethodBase.setRequestHeader方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpMethodBase.setRequestHeader方法的具體用法?Java HttpMethodBase.setRequestHeader怎麽用?Java HttpMethodBase.setRequestHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.httpclient.HttpMethodBase的用法示例。


在下文中一共展示了HttpMethodBase.setRequestHeader方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setAuthorizationHeader

import org.apache.commons.httpclient.HttpMethodBase; //導入方法依賴的package包/類
/**
 * adding OAuth authorization headers to a httpMethod
 *
 * @param httpMethod method which wants to add Authorization header
 */
private void setAuthorizationHeader(HttpMethodBase httpMethod)
        throws IdentityProvisioningException {

    boolean isDebugEnabled = log.isDebugEnabled();

    String accessToken = authenticate();
    if (StringUtils.isNotBlank(accessToken)) {
        httpMethod.setRequestHeader(SalesforceConnectorConstants.AUTHORIZATION_HEADER_NAME,
                SalesforceConnectorConstants.AUTHORIZATION_HEADER_OAUTH + " " + accessToken);

        if (isDebugEnabled) {
            log.debug("Setting authorization header for method : " + httpMethod.getName()
                    + " as follows,");
            Header authorizationHeader = httpMethod
                    .getRequestHeader(SalesforceConnectorConstants.AUTHORIZATION_HEADER_NAME);
            log.debug(authorizationHeader.getName() + ": " + authorizationHeader.getValue());
        }
    } else {
        throw new IdentityProvisioningException("Authentication failed");
    }

}
 
開發者ID:wso2-attic,項目名稱:carbon-identity,代碼行數:28,代碼來源:SalesforceProvisioningConnector.java

示例2: setAcceptHeader

import org.apache.commons.httpclient.HttpMethodBase; //導入方法依賴的package包/類
private static void setAcceptHeader(HttpMethodBase method, String value) {
	if (!value.equals("")) {
		method.setRequestHeader("Accept", value);
	} else {
		method.setRequestHeader("Accept", "application/xml");
	}
}
 
開發者ID:nyuuyn,項目名稱:chef4bpel,代碼行數:8,代碼來源:HighLevelRestApi.java

示例3: newMethod

import org.apache.commons.httpclient.HttpMethodBase; //導入方法依賴的package包/類
/**************************************************************************/

    protected HttpMethodBase newMethod(String url, String accept)
    {
        HttpMethodBase method = newBaseMethod(_config.getMethod(), url);

        if ( accept != null ) { method.setRequestHeader("Accept", accept); }

        String agent = _config.getAgent();
        if ( agent != null ) { method.setRequestHeader("User-Agent", agent); }

        method.setFollowRedirects(false);

        HttpMethodParams params = new HttpMethodParams();
        params.setParameter(HttpMethodParams.RETRY_HANDLER, RETRY_HANDLER);
        method.setParams(params);

        return method;
    }
 
開發者ID:hugomanguinhas,項目名稱:europeana,代碼行數:20,代碼來源:NegotiationValidator.java

示例4: populateCommonProperties

import org.apache.commons.httpclient.HttpMethodBase; //導入方法依賴的package包/類
/**
 * Method used to copy all the common properties
 *
 * @param msgContext       - The messageContext of the request message
 * @param url              - The target URL
 * @param httpMethod       - The http method used to send the request
 * @param httpClient       - The httpclient used to send the request
 * @param soapActionString - The soap action atring of the request message
 * @return MessageFormatter - The messageFormatter for the relavent request message
 * @throws AxisFault - Thrown in case an exception occurs
 */
protected MessageFormatter populateCommonProperties(MessageContext msgContext, URL url,
                                                  HttpMethodBase httpMethod,
                                                  HttpClient httpClient,
                                                  String soapActionString)
        throws AxisFault {

    if (isAuthenticationEnabled(msgContext)) {
        httpMethod.setDoAuthentication(true);
    }

    MessageFormatter messageFormatter = MessageProcessorSelector
                    .getMessageFormatter(msgContext);

    url = messageFormatter.getTargetAddress(msgContext, format, url);

    httpMethod.setPath(url.getPath());

    httpMethod.setQueryString(url.getQuery());

    // If adding the Content-Type header from the message formatter needs to be skipped
    if (Boolean.parseBoolean((String)msgContext.getProperty(HTTPConstants.NO_DEFAULT_CONTENT_TYPE))) {
        // Check whether message context already has the Content-Type header,
        // if so use that as the Content-Type header
        Object transportHeadersObj = msgContext.getProperty(MessageContext.TRANSPORT_HEADERS);
        if (transportHeadersObj != null && transportHeadersObj instanceof Map) {
            Map transportHeaders = (Map) transportHeadersObj;
            Object headerContentType = transportHeaders.get(HTTPConstants.HEADER_CONTENT_TYPE);
            if (headerContentType != null) {
                httpMethod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE, headerContentType.toString());
            }
        }
        // If NO_DEFAULT_CONTENT_TYPE is set to true and the Content-Type header is not present
        // in the message context, backend will receive a request without a Content-Type header
    } else {
        httpMethod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE,
                messageFormatter.getContentType(msgContext, format, soapActionString));
    }

    httpMethod.setRequestHeader(HTTPConstants.HEADER_HOST, url.getHost());

    if (msgContext.getOptions() != null && msgContext.getOptions().isManageSession()) {
        // setting the cookie in the out path
        Object cookieString = msgContext.getProperty(HTTPConstants.COOKIE_STRING);

        if (cookieString != null) {
            StringBuffer buffer = new StringBuffer();
            buffer.append(cookieString);
            httpMethod.setRequestHeader(HTTPConstants.HEADER_COOKIE, buffer.toString());
        }
    }

    if (httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10)) {
        httpClient.getParams().setVersion(HttpVersion.HTTP_1_0);
    }
    return messageFormatter;
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:68,代碼來源:AbstractHTTPSender.java


注:本文中的org.apache.commons.httpclient.HttpMethodBase.setRequestHeader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。