本文整理汇总了Java中com.ning.http.client.RequestBuilder类的典型用法代码示例。如果您正苦于以下问题:Java RequestBuilder类的具体用法?Java RequestBuilder怎么用?Java RequestBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RequestBuilder类属于com.ning.http.client包,在下文中一共展示了RequestBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: populateHeaders
import com.ning.http.client.RequestBuilder; //导入依赖的package包/类
protected void populateHeaders(RequestBuilder builder, AhcEndpoint endpoint, Exchange exchange) {
HeaderFilterStrategy strategy = endpoint.getHeaderFilterStrategy();
// propagate headers as HTTP headers
for (Map.Entry<String, Object> entry : exchange.getIn().getHeaders().entrySet()) {
String headerValue = exchange.getIn().getHeader(entry.getKey(), String.class);
if (strategy != null && !strategy.applyFilterToCamelHeaders(entry.getKey(), headerValue, exchange)) {
if (log.isTraceEnabled()) {
log.trace("Adding header {} = {}", entry.getKey(), headerValue);
}
builder.addHeader(entry.getKey(), headerValue);
}
}
if (endpoint.isConnectionClose()) {
builder.addHeader("Connection", "close");
}
}
示例2: moveNodeToTrash
import com.ning.http.client.RequestBuilder; //导入依赖的package包/类
/**
* Move node to Trash, if the kind is not FILE, FOLDER, ASSET, it return null.
*
* @param acdSession
* @param node
* @return
*/
public static NodeInfo moveNodeToTrash(ACDSession acdSession, NodeInfo node) {
Log.d(Utils.getCurrentMethodName());
String resourceEndpoint = Utils.stringFormatter("{}/{}", root, node.getId());
Request request = new RequestBuilder()
.setUrl(acdSession.getMetadataUrl(resourceEndpoint))
.setBody("{}")
.setMethod("PUT")
.build();
Response response = acdSession.execute(request);
String kind = ((JsonObject) new JsonParser().parse(Utils.getResponseBody(response))).get("kind").getAsString();
NodeInfo rtnNodeInfo = null;
if (kind.equals("FILE")) {
rtnNodeInfo = Utils.getGson().fromJson(Utils.getResponseBody(response), FileInfo.class);
}
if (kind.equals("FOLDER")) {
rtnNodeInfo = Utils.getGson().fromJson(Utils.getResponseBody(response), FolderInfo.class);
}
if (kind.equals("ASSET")) {
rtnNodeInfo = Utils.getGson().fromJson(Utils.getResponseBody(response), AssetInfo.class);
}
return rtnNodeInfo;
}
示例3: restore
import com.ning.http.client.RequestBuilder; //导入依赖的package包/类
/**
* Restore node from trash.
*
* @param acdSession
* @param node key is required.
* @return
*/
public static NodeInfo restore(ACDSession acdSession, NodeInfo node) {
Log.d(Utils.getCurrentMethodName());
String resourceEndpoint = Utils.stringFormatter("{}/{}/restore", root, node.getId());
Request request = new RequestBuilder()
.setUrl(acdSession.getMetadataUrl(resourceEndpoint))
.setMethod("POST")
.build();
Response response = acdSession.execute(request);
String kind = ((JsonObject) new JsonParser().parse(Utils.getResponseBody(response))).get("kind").getAsString();
NodeInfo rtnNodeInfo = null;
if (kind.equals("FILE")) {
rtnNodeInfo = Utils.getGson().fromJson(Utils.getResponseBody(response), FileInfo.class);
}
if (kind.equals("FOLDER")) {
rtnNodeInfo = Utils.getGson().fromJson(Utils.getResponseBody(response), FolderInfo.class);
}
if (kind.equals("ASSET")) {
rtnNodeInfo = Utils.getGson().fromJson(Utils.getResponseBody(response), AssetInfo.class);
}
return rtnNodeInfo;
}
示例4: downloadFile
import com.ning.http.client.RequestBuilder; //导入依赖的package包/类
/**
* Download file as <code>InputStream</code>
*
* @param acdSession ACDSession
* @param downloadedFileInfo target file info
* @return
*/
public static InputStream downloadFile(ACDSession acdSession, FileInfo downloadedFileInfo) {
Log.d(Utils.getCurrentMethodName());
String resourceEndpoint = Utils.stringAppender(root, "/", downloadedFileInfo.getId(), "/content");
CreateStructure createStructure = new CreateStructure();
Request request = new RequestBuilder()
.setUrl(acdSession.getContentUrl(resourceEndpoint))
.setMethod("GET")
.build();
Response response = acdSession.execute(request);
try {
return response.getResponseBodyAsStream();
} catch (IOException e) {
throw new BadContentException("getResponseBodyAsStream()");
}
}
示例5: getFileMetadata
import com.ning.http.client.RequestBuilder; //导入依赖的package包/类
/**
* get File Metadata
*
* @param acdSession ACDSession
* @param id Node ID
* @param withTempLink if true, the response will contain tempLink for download. Default: false
* @param withAsset "ALL", "NONE". Default: "NONE"
* @return
*/
public static FileInfo getFileMetadata(ACDSession acdSession, String id, Boolean withTempLink, String withAsset) {
Log.d(Utils.getCurrentMethodName());
String resourceEndpoint;
resourceEndpoint = Utils.stringAppender(root, "/", id, "?");
if (withTempLink) {
resourceEndpoint = Utils.stringAppender(resourceEndpoint, "tempLink=true");
}
if (withAsset != null && withAsset != "") {
resourceEndpoint = Utils.stringAppender(resourceEndpoint, "&asset=", withAsset);
}
Response response = acdSession.execute(new RequestBuilder()
.setUrl(acdSession.getMetadataUrl(resourceEndpoint))
.setMethod("GET")
.build());
FileInfo fileInfo = Utils.getGson().fromJson(Utils.getResponseBody(response), FileInfo.class);
return fileInfo;
}
示例6: updateFileMetadata
import com.ning.http.client.RequestBuilder; //导入依赖的package包/类
/**
* update File Metadata, only accept name, description and labels
*
* @param acdSession ACDSession
* @param fileInfo File Info
* @return
*/
public static FileInfo updateFileMetadata(ACDSession acdSession, FileInfo fileInfo) {
Log.d(Utils.getCurrentMethodName());
String resourceEndpoint = Utils.stringAppender(root, "/", fileInfo.getId());
PatchStructure patchStructure = new PatchStructure();
patchStructure.name = fileInfo.getName();
patchStructure.description = fileInfo.getDescription();
patchStructure.labels = fileInfo.getLabels();
String body = Utils.getGson().toJson(patchStructure);
Response response = acdSession.execute(new RequestBuilder()
.setUrl(acdSession.getMetadataUrl(resourceEndpoint))
.setMethod("PATCH")
.setBody(body)
.build());
FileInfo rtnFileInfo = Utils.getGson().fromJson(Utils.getResponseBody(response), FileInfo.class);
return rtnFileInfo;
}
示例7: createFolder
import com.ning.http.client.RequestBuilder; //导入依赖的package包/类
/**
* Create Folder by <code>folderInfo</code><br>
* name is required. <br>
* kind must be <code>FOLDER</code>. <br>
* description is optional. <br>
* labels is optional. <br>
* parents is optional. <br>
*
* @param acdSession ACDSession
* @param folderInfo Folder Info create folder according to <code>folderInfo</code>.
* @return the created <code>FolderInfo</code>
*/
public static FolderInfo createFolder(ACDSession acdSession, FolderInfo folderInfo) {
Log.d(Utils.getCurrentMethodName());
String resourceEndpoint = root;
CreateStructure createStructure = new CreateStructure();
createStructure.name = folderInfo.getName();
createStructure.description = folderInfo.getDescription();
createStructure.labels = folderInfo.getLabels();
createStructure.kind = "FOLDER";
createStructure.parents = folderInfo.getParents();
String body = Utils.getGson().toJson(createStructure);
Request request = new RequestBuilder()
.setUrl(acdSession.getMetadataUrl(resourceEndpoint))
.setMethod("POST")
.setBody(body)
.build();
Response response = acdSession.execute(request);
FolderInfo rtnFolderInfo = Utils.getGson().fromJson(Utils.getResponseBody(response), FolderInfo.class);
return rtnFolderInfo;
}
示例8: updateFolderMetadata
import com.ning.http.client.RequestBuilder; //导入依赖的package包/类
/**
* update Folder Metadata, only accept name, description and labels
*
* @param acdSession ACDSession
* @param folderInfo Folder Info
* @return
*/
public static FolderInfo updateFolderMetadata(ACDSession acdSession, FolderInfo folderInfo) {
Log.d(Utils.getCurrentMethodName());
String resourceEndpoint = Utils.stringAppender(root, "/", folderInfo.getId());
PatchStructure patchStructure = new PatchStructure();
patchStructure.name = folderInfo.getName();
patchStructure.description = folderInfo.getDescription();
patchStructure.labels = folderInfo.getLabels();
String body = Utils.getGson().toJson(patchStructure);
Response response = acdSession.execute(new RequestBuilder()
.setUrl(acdSession.getMetadataUrl(resourceEndpoint))
.setMethod("PATCH")
.setBody(body)
.build());
FolderInfo rtnFolderInfo = Utils.getGson().fromJson(Utils.getResponseBody(response), FolderInfo.class);
return rtnFolderInfo;
}
示例9: getFolderInfoLists
import com.ning.http.client.RequestBuilder; //导入依赖的package包/类
/**
* Get List of all FolderInfo. each query return 200 max FolderInfo
*
* @param acdSession ACDSession
* @param startToken <code>nextToken</code> from previous request for access more content. Default: null
* @return
*/
public static FolderInfoList getFolderInfoLists(ACDSession acdSession, String startToken) {
Log.d(Utils.getCurrentMethodName());
String resourceEndpoint;
resourceEndpoint = root.concat("?filters=kind:FOLDER");
if (startToken != null) {
resourceEndpoint = Utils.stringFormatter("{}&startToken={}", resourceEndpoint, startToken);
}
Response response = acdSession.execute(new RequestBuilder()
.setUrl(acdSession.getMetadataUrl(resourceEndpoint))
.setMethod("GET")
.build());
FolderInfoList folderInfoList = Utils.getGson().fromJson(Utils.getResponseBody(response), FolderInfoList
.class);
return folderInfoList;
}
示例10: sendAsyncHttpRequest
import com.ning.http.client.RequestBuilder; //导入依赖的package包/类
/**
* Send async http request.
*
* @param url the url
* @param httpMethodType the http method type
* @param body the body
* @param listener the listener
*/
public void sendAsyncHttpRequest(String url, String httpMethodType, String body, final CallStatsAsyncHttpResponseListener listener) {
if (StringUtils.isNotBlank(url) || StringUtils.isNotBlank(httpMethodType) || StringUtils.isNotBlank(body) || listener == null) {
throw new IllegalArgumentException("sendAsyncHttpRequest: Arguments cannot be null");
}
RequestBuilder builder = new RequestBuilder("POST");
Request request = builder.setUrl(BASE_URL+url)
.addHeader("Accept", "application/json")
.addHeader("Accept-Charset", "utf-8")
.setBody(body)
.build();
httpClient.executeRequest(request, new AsyncCompletionHandler<Response>() {
public Response onCompleted(Response response) throws Exception {
logger.info("Response is " + response.getResponseBody());
listener.onResponse(response);
return null;
}
public void onThrowable(Throwable e) {
listener.onFailure((Exception)e);
}
});
}
示例11: doExecute
import com.ning.http.client.RequestBuilder; //导入依赖的package包/类
@Override
protected HttpResponse doExecute() throws Exception {
HttpUrl endpoint = getEndpoint();
String scheme = endpoint.getScheme();
String userInfo = null;
String host = endpoint.getHost();
int port = endpoint.getPort();
String path = UTF8UrlEncoder.encodePath(endpoint.getPath());
String query = null;
Uri uri = new Uri(scheme, userInfo, host, port, path, query);
String method = getMethod().getVerb();
RequestBuilder builder = new RequestBuilder(method, true).setUri(uri);
handleQueryParameters(builder);
handleBody(builder);
handleHeaders(builder);
handleCookies(builder);
Request request = builder.build();
long start = nanoTime();
Response response = client.executeRequest(request).get();
return new NingAsyncHttpResponse(response, nanoTime() - start);
}
示例12: buildCustomGETHeaders
import com.ning.http.client.RequestBuilder; //导入依赖的package包/类
public RequestBuilder buildCustomGETHeaders(RequestBuilder request, HTTPLogObject http_log) {
String one_time_GET_header = GETHeaderCache.instance.fetchPayload(http_log.getRequest());
String header_delimiter = ConfigurationSingleton.instance
.getConfigItem("replay.request.headers.delimiter");
String[] headers = one_time_GET_header.split(header_delimiter);
for (int i = 0; i < headers.length; i++) {
try {
String header_key = headers[i].split(":")[0].trim();
String header_value = headers[i].split(":")[1].trim();
request.addHeader(header_key, header_value);
}
catch (Exception e) {
logger.trace("No or invalid header detected for " + http_log.getRequest() + ".");
}
}
return request;
}
示例13: buildCustomPOSTHeaders
import com.ning.http.client.RequestBuilder; //导入依赖的package包/类
public RequestBuilder buildCustomPOSTHeaders(RequestBuilder request, HTTPLogObject http_log) {
String one_time_POST_header = POSTHeaderCache.instance.fetchPayload(http_log.getRequest());
String header_delimiter = ConfigurationSingleton.instance
.getConfigItem("replay.request.headers.delimiter");
String[] headers = one_time_POST_header.split(header_delimiter);
for (int i = 0; i < headers.length; i++) {
try {
String header_key = headers[i].split(":")[0].trim();
String header_value = headers[i].split(":")[1].trim();
request.addHeader(header_key, header_value);
}
catch (Exception e) {
logger.trace("No or invalid header detected for " + http_log.getRequest() + ".");
}
}
return request;
}
示例14: asyncHealthcheck
import com.ning.http.client.RequestBuilder; //导入依赖的package包/类
private void asyncHealthcheck(final SingularityTask task) {
final SingularityHealthcheckAsyncHandler handler = new SingularityHealthcheckAsyncHandler(exceptionNotifier, configuration, this, newTaskChecker, taskManager, task);
final Optional<String> uri = getHealthcheckUri(task);
if (!uri.isPresent()) {
saveFailure(handler, "Invalid healthcheck uri or ports not present");
return;
}
final Long timeoutSeconds = task.getTaskRequest().getDeploy().getHealthcheckTimeoutSeconds().or(configuration.getHealthcheckTimeoutSeconds());
try {
PerRequestConfig prc = new PerRequestConfig();
prc.setRequestTimeoutInMs((int) TimeUnit.SECONDS.toMillis(timeoutSeconds));
RequestBuilder builder = new RequestBuilder("GET");
builder.setFollowRedirects(true);
builder.setUrl(uri.get());
builder.setPerRequestConfig(prc);
LOG.trace("Issuing a healthcheck ({}) for task {} with timeout {}s", uri.get(), task.getTaskId(), timeoutSeconds);
http.prepareRequest(builder.build()).execute(handler);
} catch (Throwable t) {
LOG.debug("Exception while preparing healthcheck ({}) for task ({})", uri, task.getTaskId(), t);
exceptionNotifier.notify(t, ImmutableMap.of("taskId", task.getTaskId().toString()));
saveFailure(handler, String.format("Healthcheck failed due to exception: %s", t.getMessage()));
}
}
示例15: prepareRequest
import com.ning.http.client.RequestBuilder; //导入依赖的package包/类
public Request prepareRequest(AhcEndpoint endpoint, Exchange exchange) throws CamelExchangeException {
if (endpoint.isBridgeEndpoint()) {
exchange.setProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.TRUE);
// Need to remove the Host key as it should be not used
exchange.getIn().getHeaders().remove("host");
}
RequestBuilder builder = new RequestBuilder();
try {
// creating the url to use takes 2-steps
String url = AhcHelper.createURL(exchange, endpoint);
URI uri = AhcHelper.createURI(exchange, url, endpoint);
// get the url from the uri
url = uri.toASCIIString();
log.trace("Setting url {}", url);
builder.setUrl(url);
} catch (Exception e) {
throw new CamelExchangeException("Error creating URL", exchange, e);
}
String method = extractMethod(exchange);
log.trace("Setting method {}", method);
builder.setMethod(method);
populateHeaders(builder, endpoint, exchange);
populateBody(builder, endpoint, exchange);
return builder.build();
}