本文整理汇总了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();
}
示例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);
}
});
}
示例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);
}
});
}
示例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;
}
});
}
示例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);
}