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


Java BoundRequestBuilder.setHeaders方法代码示例

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


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

示例1: connect

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

    final TransportOptions options = context.getTransportOptions();

    if (!options.getTryWebSockets()) {
        throw new IllegalStateException("WebSockets are not supported by the server");
    }

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

    boundRequestBuilder.setHeaders(headers);

    // Send request.
    final WebSocketUpgradeHandler.Builder builder = new WebSocketUpgradeHandler.Builder();
    final WebSocketTextListenerAdapter listener = new WebSocketTextListenerAdapter(handler);

    builder.addWebSocketListener(listener);

    try {
        boundRequestBuilder.execute(builder.build());
    } catch (final IOException e) {
        return Promises.newFailure(e);
    }

    return listener.getChannel();
}
 
开发者ID:mtamme,项目名称:signalr-client,代码行数:37,代码来源:WebSocketTransport.java

示例2: negotiate

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

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

    boundRequestBuilder.setHeaders(headers);

    // 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, NegotiationResponse>() {
        @Override
        protected NegotiationResponse doApply(final Response response) throws Exception {
            final JsonMapper mapper = context.getMapper();
            final String body = response.getResponseBody();

            return mapper.toObject(body, NegotiationResponse.class);
        }
    });
}
 
开发者ID:mtamme,项目名称:signalr-client,代码行数:33,代码来源:AbstractTransport.java

示例3: ping

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

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

    boundRequestBuilder.setHeaders(headers);

    // 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, PingResponse>() {
        @Override
        protected PingResponse doApply(final Response response) throws Exception {
            final JsonMapper mapper = context.getMapper();
            final String body = response.getResponseBody();

            return mapper.toObject(body, PingResponse.class);
        }
    });
}
 
开发者ID:mtamme,项目名称:signalr-client,代码行数:33,代码来源:AbstractTransport.java

示例4: 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

示例5: setHeader

import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; //导入方法依赖的package包/类
protected void setHeader(BoundRequestBuilder builder) {
    FluentCaseInsensitiveStringsMap header = new FluentCaseInsensitiveStringsMap();
    header.add("Accept", "application/json");
    header.add("Authorization", "BEARER " + oAuthToken.getAccessToken());
    header.add("x-ddc-client-id", config.get("x-ddc-client-id"));
    
    header.add("UserClient", "salesforce-datacom-api-java-client-v1");
    
    builder.setHeaders(header);
}
 
开发者ID:forcedotcom,项目名称:salesforce-datacom-api-java-client,代码行数:11,代码来源:AbstractService.java


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