本文整理汇总了Java中com.ning.http.client.AsyncHttpClient.BoundRequestBuilder.execute方法的典型用法代码示例。如果您正苦于以下问题:Java BoundRequestBuilder.execute方法的具体用法?Java BoundRequestBuilder.execute怎么用?Java BoundRequestBuilder.execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ning.http.client.AsyncHttpClient.BoundRequestBuilder
的用法示例。
在下文中一共展示了BoundRequestBuilder.execute方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例2: replay
import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; //导入方法依赖的package包/类
public ListenableFuture<Response> replay(final LogLineData logLineData) throws IOException {
BoundRequestBuilder req = asyncHttpClient.prepareGet(host + logLineData.getRequest());
req.setFollowRedirects(followRedirects);
String usedHostHeader = null;
if (logLineData.getHost() == null) {
if (hostHeader != null) {
usedHostHeader = hostHeader;
}
} else {
usedHostHeader = logLineData.getHost();
}
req = req.setVirtualHost(usedHostHeader);
for (final Header header : headers) {
req = req.setHeader(header.getName(), header.getValue());
}
if (logLineData.getUserAgent() != null) {
req.setHeader("user-agent", logLineData.getUserAgent());
}
LOG.info("Executing request {}: {} with host headers {}", req, host + logLineData.getRequest(), usedHostHeader);
return req.execute(new LoggingAsyncCompletionHandler(logLineData, resultDataLogger));
}
示例3: postRequest
import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; //导入方法依赖的package包/类
public Promise<WSResponse> postRequest(URL url, String contentType, byte[] body,
RequestPreparer postRequestPreparer) throws IOException {
final scala.concurrent.Promise<WSResponse> scalaPromise =
scala.concurrent.Promise$.MODULE$.apply();
BoundRequestBuilder builder = asyncHttpClient.preparePost(url.toString())
.setHeader("Content-Type", contentType)
.setContentLength(body.length)
.setBody(body);
if (postRequestPreparer != null) {
postRequestPreparer.prepare(builder, contentType, url);
}
builder.execute(new AsyncCompletionHandler<Response>() {
@Override
public Response onCompleted(Response response) {
scalaPromise.success(new NingWSResponse(response));
return response;
}
@Override
public void onThrowable(Throwable t) {
scalaPromise.failure(t);
}
});
return Promise.wrap(scalaPromise.future());
}
示例4: internalSendCommand
import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; //导入方法依赖的package包/类
private void internalSendCommand(String machineIdentifier, String url) throws IOException {
logger.debug("Calling url {}", url);
BoundRequestBuilder builder = client.prepareGet(url).setHeaders(getDefaultHeaders())
.setHeader("X-Plex-Target-Client-Identifier", machineIdentifier);
builder.execute(new AsyncCompletionHandler<Response>() {
@Override
public Response onCompleted(Response response) throws Exception {
if (response.getStatusCode() != 200) {
logger.error("Error while sending command to Plex: {}\r\n{}", response.getStatusText(),
response.getResponseBody());
}
return response;
}
@Override
public void onThrowable(Throwable t) {
logger.error("Error sending command to Plex", t);
}
});
}
示例5: executeRequest
import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; //导入方法依赖的package包/类
public void executeRequest(int identifier, Request request) {
AsyncRequestHandler requestHandler = getRequestHandler(identifier);
requestHandler.setRequest(request);
BoundRequestBuilder httpRequest;
switch (request.getType()) {
case FEED:
httpRequest = createFeedRequest((RequestFeed) request);
httpRequest.execute(requestHandler);
break;
case FOLLOW:
httpRequest = createFollowRequest((RequestFollow) request);
httpRequest.execute(requestHandler);
break;
case POST:
httpRequest = createPostRequest((RequestPost) request);
httpRequest.execute(requestHandler);
break;
case UNFOLLOW:
httpRequest = createUnfollowRequest((RequestUnfollow) request);
httpRequest.execute(requestHandler);
break;
case USER:
httpRequest = createUserRequest((RequestUser) request);
httpRequest.execute(requestHandler);
break;
default:
throw new IllegalArgumentException("Unknown request type \""
+ request.getType() + "\"!");
}
}
示例6: 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();
}
示例7: 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);
}
});
}
示例8: 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);
}
});
}
示例9: 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;
}
});
}
示例10: 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