本文整理汇总了Java中com.ning.http.client.AsyncHttpClient.BoundRequestBuilder.addQueryParameter方法的典型用法代码示例。如果您正苦于以下问题:Java BoundRequestBuilder.addQueryParameter方法的具体用法?Java BoundRequestBuilder.addQueryParameter怎么用?Java BoundRequestBuilder.addQueryParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ning.http.client.AsyncHttpClient.BoundRequestBuilder
的用法示例。
在下文中一共展示了BoundRequestBuilder.addQueryParameter方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: addQueryParams
import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; //导入方法依赖的package包/类
/**
* String/Boolean/Number만 지원.
*/
public static void addQueryParams(BoundRequestBuilder requestBuilder, Bundle parameters) {
if(parameters == null)
return;
Set<String> keys = parameters.keySet();
for (String key : keys) {
Object value = parameters.get(key);
String valueStr = null;
if (value == null) {
value = "";
}
if (isSupportedParameterType(value)) {
valueStr = parameterToString(value);
} else {
throw new IllegalArgumentException(String.format("Unsupported parameter type for GET request: %s",
value.getClass().getSimpleName()));
}
requestBuilder.addQueryParameter(key, valueStr);
}
}
示例3: getContents
import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; //导入方法依赖的package包/类
public Optional<String> getContents(String user, String repo, String path, Optional<String> ref) {
try {
final BoundRequestBuilder builder = asyncHttpClient.prepareGet(String.format("%s/repos/%s/%s/contents/%s", baseUrl, user, repo, path))
.addHeader("Accept", "application/vnd.github.v3.raw");
if (ref.isPresent()) {
builder.addQueryParameter("ref", ref.get());
}
if (accessToken.isPresent()) {
builder.addQueryParameter("access_token", accessToken.get());
}
final Response response = builder.execute().get();
if (response.getStatusCode() == 200) {
return Optional.of(response.getResponseBody());
} else if (response.getStatusCode() == 404) {
return Optional.absent();
} else {
throw new RuntimeException(response.getResponseBody()); // TODO: better exception
}
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
示例4: 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));
}
}
}
示例5: buildAgentRequest
import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; //导入方法依赖的package包/类
private AsyncHttpClient.BoundRequestBuilder buildAgentRequest(String url, AgentRequestType requestType) {
final BoundRequestBuilder builder;
switch (requestType) {
case APPLY:
builder = asyncHttpClient.preparePost(url);
break;
case REVERT:
case CANCEL:
builder = asyncHttpClient.prepareDelete(url);
break;
default:
throw new RuntimeException("Don't know how to send requests for " + requestType);
}
if (baragonAuthKey.isPresent()) {
builder.addQueryParameter("authkey", baragonAuthKey.get());
}
return builder;
}
示例6: 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;
}
示例7: addAllQueryParams
import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; //导入方法依赖的package包/类
private void addAllQueryParams(BoundRequestBuilder boundRequestBuilder, Map<String, String> queryParams) {
for (Map.Entry<String, String> entry : queryParams.entrySet()) {
boundRequestBuilder.addQueryParameter(entry.getKey(), entry.getValue());
}
}
示例8: addQueryString
import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; //导入方法依赖的package包/类
/**
* Adds the queryString-part of the url to the BoundRequestBuilder
*/
protected void addQueryString(BoundRequestBuilder requestBuilder) {
// AsyncHttpClient is by default encoding everything in utf-8 so for us to be able to use
// different encoding we have configured AHC to use raw urls. When using raw urls,
// AHC does not encode url and QueryParam with utf-8 - but there is another problem:
// If we send raw (none-encoded) url (with queryString) to AHC, it does not url-encode it,
// but transform all illegal chars to '?'.
// If we pre-encoded the url with QueryString before sending it to AHC, ahc will decode it, and then
// later break it with '?'.
// This method basically does the same as RequestBuilderBase.buildUrl() except from destroying the
// pre-encoding
// does url contain query_string?
int i = url.indexOf('?');
if ( i > 0) {
try {
// extract query-string-part
String queryPart = url.substring(i+1);
// parse queryPart - and decode it... (it is going to be re-encoded later)
for( String param : queryPart.split("&")) {
i = param.indexOf('=');
String name;
String value = null;
if ( i<=0) {
// only a flag
name = URLDecoder.decode(param, encoding);
} else {
name = URLDecoder.decode(param.substring(0,i), encoding);
value = URLDecoder.decode(param.substring(i+1), encoding);
}
if (value == null) {
requestBuilder.addQueryParameter(URLEncoder.encode(name, encoding), null);
} else {
requestBuilder.addQueryParameter(URLEncoder.encode(name, encoding), URLEncoder.encode(value, encoding));
}
}
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Error parsing query-part of url",e);
}
}
}