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


Java BoundRequestBuilder.addHeader方法代码示例

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


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

示例1: forwardEvent

import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; //导入方法依赖的package包/类
public void forwardEvent(Event event, Position position) {

        BoundRequestBuilder requestBuilder = Context.getAsyncHttpClient().preparePost(url);

        requestBuilder.addHeader("Content-Type", "application/json; charset=utf-8");
        if (!header.equals("")) {
            String[] headerLines = header.split("\\r?\\n");
            for (String headerLine: headerLines) {
                String[] splitedLine = headerLine.split(":", 2);
                if (splitedLine.length == 2) {
                    requestBuilder.setHeader(splitedLine[0].trim(), splitedLine[1].trim());
                }
            }
        }

        requestBuilder.setBody(preparePayload(event, position));
        requestBuilder.execute();
    }
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:19,代码来源:EventForwarder.java

示例2: makeAccessTokenRequest

import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; //导入方法依赖的package包/类
private BoundRequestBuilder makeAccessTokenRequest() {
    final BoundRequestBuilder requestBuilder = HttpRequestTask.ASYNC_HTTP_CLIENT.preparePost(
        HttpRequestTask.createBaseURL(ServerProtocol.AUTH_AUTHORITY, ServerProtocol.ACCESS_TOKEN_PATH));
    final Entry<String,String> entry = HttpRequestTask.KA_HEADER.entrySet().iterator().next();
    requestBuilder.addHeader(entry.getKey(), entry.getValue());

    if (accessTokenRequest.isAccessTokenRequestWithAuthCode()) {
        requestBuilder.addQueryParameter(ServerProtocol.GRANT_TYPE_KEY, ServerProtocol.GRANT_TYPE_AUTHORIZATION_CODE);
        requestBuilder.addQueryParameter(ServerProtocol.CODE_KEY, accessTokenRequest.getAuthorizationCode());
        requestBuilder.addQueryParameter(ServerProtocol.REDIRECT_URI_KEY, accessTokenRequest.getRedirectURI());
    } else { //if(request.isAccessTokenRequestWithRefreshToken()) {
        requestBuilder.addQueryParameter(ServerProtocol.GRANT_TYPE_KEY, ServerProtocol.REFRESH_TOKEN_KEY);
        requestBuilder.addQueryParameter(ServerProtocol.REFRESH_TOKEN_KEY, accessTokenRequest.getRefreshToken());
    }
    requestBuilder.addQueryParameter(ServerProtocol.CLIENT_ID_KEY, accessTokenRequest.getAppKey());
    requestBuilder.addQueryParameter(ServerProtocol.ANDROID_KEY_HASH, accessTokenRequest.getKeyHash());
    return requestBuilder;
}
 
开发者ID:yongbeam,项目名称:Android-kakaologin-gradle-sample,代码行数:19,代码来源:GetterAccessToken.java

示例3: copyHeadersAndParams

import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; //导入方法依赖的package包/类
private void copyHeadersAndParams(BoundRequestBuilder requestBuilder, HttpServletRequest request) {
  Enumeration<String> headerNames = request.getHeaderNames();
  if (headerNames != null) {
    while (headerNames.hasMoreElements()) {
      String headerName = headerNames.nextElement();
      requestBuilder.addHeader(headerName, request.getHeader(headerName));
      LOG.trace("Copied header {}:{}", headerName, request.getHeader(headerName));
    }
  }
  Enumeration<String> parameterNames = request.getParameterNames();
  if (parameterNames != null) {
    while (parameterNames.hasMoreElements()) {
      String parameterName = parameterNames.nextElement();
      requestBuilder.addQueryParameter(parameterName, request.getParameter(parameterName));
      LOG.trace("Copied query param {}={}", parameterName, request.getParameter(parameterName));
    }
  }
}
 
开发者ID:HubSpot,项目名称:Singularity,代码行数:19,代码来源:AbstractLeaderAwareResource.java

示例4: addHeaders

import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; //导入方法依赖的package包/类
/**
 * Adds the headers.
 *
 * @param builder
 *            the builder
 * @param headerMap
 *            the header map
 */
public static void addHeaders(BoundRequestBuilder builder,
        Map<String, String> headerMap) {
    for (Entry<String, String> entry : headerMap.entrySet()) {
        String name = entry.getKey();
        String value = entry.getValue();
        builder.addHeader(name, value);
    }

}
 
开发者ID:eBay,项目名称:parallec,代码行数:18,代码来源:PcHttpUtils.java

示例5: prepare

import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; //导入方法依赖的package包/类
private BoundRequestBuilder prepare(BoundRequestBuilder builder) {
    if (this.username != null && this.password != null && this.scheme != null) {
        AuthScheme authScheme;
        switch (this.scheme) {
        case DIGEST: authScheme = AuthScheme.DIGEST; break;
        case NTLM: authScheme = AuthScheme.NTLM; break;
        case KERBEROS: authScheme = AuthScheme.KERBEROS; break;
        case SPNEGO: authScheme = AuthScheme.SPNEGO; break;
        case BASIC: authScheme = AuthScheme.BASIC; break;
        default: throw new RuntimeException("Scheme " + this.scheme + " not supported by the UrlFetch WS backend.");
        }
        builder.setRealm(
                (new RealmBuilder())
                .setScheme(authScheme)
                .setPrincipal(this.username)
                .setPassword(this.password)
                .setUsePreemptiveAuth(true)
                .build()
        );
    }
    for (String key: this.headers.keySet()) {
        builder.addHeader(key, headers.get(key));
    }
    builder.setFollowRedirects(this.followRedirects);
    PerRequestConfig perRequestConfig = new PerRequestConfig();
    perRequestConfig.setRequestTimeoutInMs(this.timeout * 1000);
    builder.setPerRequestConfig(perRequestConfig);
    return builder;
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:30,代码来源:WSAsync.java

示例6: addHeaders

import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; //导入方法依赖的package包/类
public static void addHeaders(BoundRequestBuilder builder,
		Map<String, String> headerMap) {
	for (Entry<String, String> entry : headerMap.entrySet()) {
		String name = entry.getKey();
		String value = entry.getValue();
		builder.addHeader(name, value);
	}

}
 
开发者ID:eBay,项目名称:restcommander,代码行数:10,代码来源:MyHttpUtils.java

示例7: abort

import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; //导入方法依赖的package包/类
@Override
public final Promise<Void> abort(final TransportContext context) {
    if (context == null) {
        throw new IllegalArgumentException("Context must not be null");
    }

    // Setup request.
    final URI uri = Transports.buildAbortUri(context, this);
    final BoundRequestBuilder boundRequestBuilder = preparePost(uri);
    final Map<String, Collection<String>> headers = context.getHeaders();

    boundRequestBuilder.setHeaders(headers);
    boundRequestBuilder.addHeader(CONTENT_LENGTH_HEADER, "0");
    boundRequestBuilder.addHeader(CONTENT_TYPE_HEADER, "text/plain");

    // Send request.
    final ResponseHandler handler = new ResponseHandler();

    try {
        boundRequestBuilder.execute(handler);
    } catch (final Throwable t) {
        return Promises.newFailure(t);
    }

    return handler.getResponse().then(new Apply<Response, Void>() {
        @Override
        protected Void doApply(final Response response) throws Exception {
            return null;
        }
    });
}
 
开发者ID:mtamme,项目名称:signalr-client,代码行数:32,代码来源:AbstractTransport.java

示例8: buildAgentBatchRequest

import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; //导入方法依赖的package包/类
private AsyncHttpClient.BoundRequestBuilder buildAgentBatchRequest(String url, Set<BaragonRequestBatchItem> batch) throws JsonProcessingException {
  final BoundRequestBuilder builder = asyncHttpClient.preparePost(url);
  if (baragonAuthKey.isPresent()) {
    builder.addQueryParameter("authkey", baragonAuthKey.get());
  }
  builder.addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
  builder.setBody(objectMapper.writeValueAsBytes(batch));
  return builder;
}
 
开发者ID:HubSpot,项目名称:Baragon,代码行数:10,代码来源:AgentManager.java

示例9: authenticate

import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; //导入方法依赖的package包/类
/**
 * <p>
 * Authenticate using a username and password. This is discouraged by the
 * oauth flow, but it allows for transparent (and non human-intervention)
 * authentication).
 * </p>
 * 
 * @return The response retrieved from the REST API (usually an XML string
 *         with all the tokens)
 * @throws IOException
 * @throws UnauthenticatedSessionException
 * @throws AuthenticationException
 */
@Override
public OAuthToken authenticate() throws IOException, UnauthenticatedSessionException,
        AuthenticationException {
    String clientId = URLEncoder.encode(config.get("client_id"), "UTF-8");
    
    BoundRequestBuilder builder = getHttpClient().preparePost(
            (config.containsKey("server_url") ? config.get("server_url")
                    : "https://api.jigsaw.com/connect") + "/oauth2/token");
    
    builder.addHeader("Accept", "application/json");
    builder.addHeader("USER_CLIENT", "salesforce-datacom-api-java-client-v1");
    
    builder.addParameter("grant_type", "password");
    builder.addParameter("client_secret", config.containsKey("client_secret")
            ? config.get("client_secret") : "secret");
    builder.addParameter("client_id", clientId);
    builder.addParameter("username", config.get("username"));
    builder.addParameter("password", config.get("password"));
    
    Future<Response> f = builder.execute();
    int statusCode = -1;
    String responseBody = null;
    try {
        Response response = f.get();
        statusCode = response.getStatusCode();
        if (statusCode == 200) {
            return processResponse(responseBody = response.getResponseBody());
        }
    }
    catch (Exception e) {
        // TODO: handle exception
    }
    throw new UnauthenticatedSessionException(statusCode + " " + responseBody);
}
 
开发者ID:forcedotcom,项目名称:salesforce-datacom-api-java-client,代码行数:48,代码来源:UsernamePasswordAuthentication.java

示例10: addTokenHeader

import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; //导入方法依赖的package包/类
public static void addTokenHeader(final BoundRequestBuilder requestBuilder) {
    final Entry<String,String> entry = KA_HEADER.entrySet().iterator().next();
    requestBuilder.addHeader(entry.getKey(), entry.getValue());

    requestBuilder.addHeader(ServerProtocol.AUTHORIZATION_HEADER_KEY, getTokenAuthHeaderValue());
}
 
开发者ID:yongbeam,项目名称:Android-kakaologin-gradle-sample,代码行数:7,代码来源:APIHttpRequestTask.java

示例11: addGeneratedContentType

import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; //导入方法依赖的package包/类
/**
 * If generatedContentType is present AND if Content-type header is not already present,
 * add generatedContentType as Content-Type to headers in requestBuilder
 */
private void addGeneratedContentType(BoundRequestBuilder requestBuilder) {
    if (!headers.containsKey("Content-Type") && generatedContentType!=null) {
        requestBuilder.addHeader("Content-Type", generatedContentType);
    }
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:10,代码来源:WSAsync.java


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