本文整理汇总了Java中org.asynchttpclient.Param类的典型用法代码示例。如果您正苦于以下问题:Java Param类的具体用法?Java Param怎么用?Java Param使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Param类属于org.asynchttpclient包,在下文中一共展示了Param类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: signatureBaseString
import org.asynchttpclient.Param; //导入依赖的package包/类
StringBuilder signatureBaseString(String method, Uri uri, long oauthTimestamp, String nonce,
List<Param> formParams, List<Param> queryParams) {
// beware: must generate first as we're using pooled StringBuilder
String baseUrl = baseUrl(uri);
String encodedParams = encodedParams(oauthTimestamp, nonce, formParams, queryParams);
StringBuilder sb = StringUtils.stringBuilder();
sb.append(method); // POST / GET etc (nothing to URL encode)
sb.append('&');
Utf8UrlEncoder.encodeAndAppendQueryElement(sb, baseUrl);
// and all that needs to be URL encoded (... again!)
sb.append('&');
Utf8UrlEncoder.encodeAndAppendQueryElement(sb, encodedParams);
return sb;
}
示例2: send
import org.asynchttpclient.Param; //导入依赖的package包/类
public void send(String to, String text) {
ArrayList<Param> params = new ArrayList<>();
params.add(new Param("api_key", key));
params.add(new Param("api_secret", secret));
params.add(new Param("from", "Blynk"));
params.add(new Param("to", to));
params.add(new Param("text", text));
httpclient.preparePost("https://rest.nexmo.com/sms/json")
.setQueryParams(params)
.execute(new AsyncCompletionHandler<Response>() {
@Override
public Response onCompleted(org.asynchttpclient.Response response) throws Exception {
if (response.getStatusCode() == 200) {
SmsResponse smsResponse = smsResponseReader.readValue(response.getResponseBody());
if (!smsResponse.messages[0].status.equals("0")) {
log.error(smsResponse.messages[0].error);
}
}
return response;
}
});
}
示例3: paramsToString
import org.asynchttpclient.Param; //导入依赖的package包/类
/**
* Returns string without double quotations marks, spaces, semi-colons from com.ning.http.client.FluentStringsMap.toString()
*
* @param params
* @param limit
* @return
*/
private String paramsToString(List<Param> params, int limit) {
StringBuilder result = new StringBuilder(limit * 2);
for (Param param : params) {
if (result.length() > 0) {
result.append(',');
}
result.append(param.getName());
result.append('=');
result.append(param.getValue());
if (result.length() >= limit) {
break;
}
}
return result.toString();
}
示例4: visitCustomHeaders
import org.asynchttpclient.Param; //导入依赖的package包/类
protected void visitCustomHeaders(PartVisitor visitor) {
if (isNonEmpty(part.getCustomHeaders())) {
for (Param param : part.getCustomHeaders()) {
visitor.withBytes(CRLF_BYTES);
visitor.withBytes(param.getName().getBytes(US_ASCII));
visitor.withBytes(param.getValue().getBytes(US_ASCII));
}
}
}
示例5: urlEncodeFormParams0
import org.asynchttpclient.Param; //导入依赖的package包/类
private static StringBuilder urlEncodeFormParams0(List<Param> params) {
StringBuilder sb = StringUtils.stringBuilder();
for (Param param : params) {
encodeAndAppendFormParam(sb, param.getName(), param.getValue());
}
sb.setLength(sb.length() - 1);
return sb;
}
示例6: testGetCalculateSignature
import org.asynchttpclient.Param; //导入依赖的package包/类
@Test(groups = "standalone")
public void testGetCalculateSignature() {
ConsumerKey consumer = new ConsumerKey(CONSUMER_KEY, CONSUMER_SECRET);
RequestToken user = new RequestToken(TOKEN_KEY, TOKEN_SECRET);
OAuthSignatureCalculator calc = new OAuthSignatureCalculator(consumer, user);
List<Param> queryParams = new ArrayList<>();
queryParams.add(new Param("file", "vacation.jpg"));
queryParams.add(new Param("size", "original"));
String url = "http://photos.example.net/photos";
String sig = calc.calculateSignature("GET", Uri.create(url), TIMESTAMP, NONCE, null, queryParams);
assertEquals(sig, "tR3+Ty81lMeYAr/Fid0kMTYa/WM=");
}
示例7: testPostCalculateSignature
import org.asynchttpclient.Param; //导入依赖的package包/类
@Test(groups = "standalone")
public void testPostCalculateSignature() {
ConsumerKey consumer = new ConsumerKey(CONSUMER_KEY, CONSUMER_SECRET);
RequestToken user = new RequestToken(TOKEN_KEY, TOKEN_SECRET);
OAuthSignatureCalculator calc = new StaticOAuthSignatureCalculator(consumer, user, TIMESTAMP, NONCE);
List<Param> formParams = new ArrayList<Param>();
formParams.add(new Param("file", "vacation.jpg"));
formParams.add(new Param("size", "original"));
String url = "http://photos.example.net/photos";
final Request req = post(url)//
.setFormParams(formParams)//
.setSignatureCalculator(calc)//
.build();
// From the signature tester, POST should look like:
// normalized parameters:
// file=vacation.jpg&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_nonce=kllo9940pd9333jh&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1191242096&oauth_token=nnch734d00sl2jdk&oauth_version=1.0&size=original
// signature base string:
// POST&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal
// signature: wPkvxykrw+BTdCcGqKr+3I+PsiM=
// header: OAuth
// realm="",oauth_version="1.0",oauth_consumer_key="dpf43f3p2l4k3l03",oauth_token="nnch734d00sl2jdk",oauth_timestamp="1191242096",oauth_nonce="kllo9940pd9333jh",oauth_signature_method="HMAC-SHA1",oauth_signature="wPkvxykrw%2BBTdCcGqKr%2B3I%2BPsiM%3D"
String authHeader = req.getHeaders().get("Authorization");
Matcher m = Pattern.compile("oauth_signature=\"(.+?)\"").matcher(authHeader);
assertEquals(m.find(), true);
String encodedSig = m.group(1);
String sig = null;
try {
sig = URLDecoder.decode(encodedSig, "UTF-8");
} catch (UnsupportedEncodingException e) {
fail("bad encoding", e);
}
assertEquals(sig, "wPkvxykrw+BTdCcGqKr+3I+PsiM=");
}
示例8: testGetWithRequestBuilderAndQuery
import org.asynchttpclient.Param; //导入依赖的package包/类
@Test(groups = "standalone")
public void testGetWithRequestBuilderAndQuery() {
ConsumerKey consumer = new ConsumerKey(CONSUMER_KEY, CONSUMER_SECRET);
RequestToken user = new RequestToken(TOKEN_KEY, TOKEN_SECRET);
OAuthSignatureCalculator calc = new StaticOAuthSignatureCalculator(consumer, user, TIMESTAMP, NONCE);
String url = "http://photos.example.net/photos?file=vacation.jpg&size=original";
final Request req = get(url)//
.setSignatureCalculator(calc)//
.build();
final List<Param> params = req.getQueryParams();
assertEquals(params.size(), 2);
// From the signature tester, the URL should look like:
//normalized parameters: file=vacation.jpg&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_nonce=kllo9940pd9333jh&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1191242096&oauth_token=nnch734d00sl2jdk&oauth_version=1.0&size=original
//signature base string: GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal
//signature: tR3+Ty81lMeYAr/Fid0kMTYa/WM=
//Authorization header: OAuth realm="",oauth_version="1.0",oauth_consumer_key="dpf43f3p2l4k3l03",oauth_token="nnch734d00sl2jdk",oauth_timestamp="1191242096",oauth_nonce="kllo9940pd9333jh",oauth_signature_method="HMAC-SHA1",oauth_signature="tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D"
String authHeader = req.getHeaders().get("Authorization");
Matcher m = Pattern.compile("oauth_signature=\"(.+?)\"").matcher(authHeader);
assertEquals(m.find(), true);
String encodedSig = m.group(1);
String sig = null;
try {
sig = URLDecoder.decode(encodedSig, "UTF-8");
} catch (UnsupportedEncodingException e) {
fail("bad encoding", e);
}
assertEquals(sig, "tR3+Ty81lMeYAr/Fid0kMTYa/WM=");
assertEquals(req.getUrl(), "http://photos.example.net/photos?file=vacation.jpg&size=original");
}
示例9: recordParam
import org.asynchttpclient.Param; //导入依赖的package包/类
protected void recordParam(final Request httpRequest, final SpanEventRecorder recorder) {
if (paramSampler.isSampling()) {
List<Param> requestParams = httpRequest.getFormParams();
if (requestParams != null && !requestParams.isEmpty()) {
String params = paramsToString(requestParams, config.getParamDumpSize());
recorder.recordAttribute(AnnotationKey.HTTP_PARAM, StringUtils.abbreviate(params, config.getParamDumpSize()));
}
}
}
示例10: getCustomHeaders
import org.asynchttpclient.Param; //导入依赖的package包/类
@Override
public List<Param> getCustomHeaders() {
return customHeaders;
}
示例11: addCustomHeader
import org.asynchttpclient.Param; //导入依赖的package包/类
public void addCustomHeader(String name, String value) {
if (customHeaders == null) {
customHeaders = new ArrayList<Param>(2);
}
customHeaders.add(new Param(name, value));
}
示例12: setCustomHeaders
import org.asynchttpclient.Param; //导入依赖的package包/类
public void setCustomHeaders(List<Param> customHeaders) {
this.customHeaders = customHeaders;
}
示例13: urlEncodeFormParams
import org.asynchttpclient.Param; //导入依赖的package包/类
public static ByteBuffer urlEncodeFormParams(List<Param> params, Charset charset) {
return StringUtils.charSequence2ByteBuffer(urlEncodeFormParams0(params), charset);
}
示例14: testGetWithRequestBuilder
import org.asynchttpclient.Param; //导入依赖的package包/类
@Test(groups = "standalone")
public void testGetWithRequestBuilder() {
ConsumerKey consumer = new ConsumerKey(CONSUMER_KEY, CONSUMER_SECRET);
RequestToken user = new RequestToken(TOKEN_KEY, TOKEN_SECRET);
OAuthSignatureCalculator calc = new StaticOAuthSignatureCalculator(consumer, user, TIMESTAMP, NONCE);
List<Param> queryParams = new ArrayList<Param>();
queryParams.add(new Param("file", "vacation.jpg"));
queryParams.add(new Param("size", "original"));
String url = "http://photos.example.net/photos";
final Request req = get(url)//
.setQueryParams(queryParams)//
.setSignatureCalculator(calc)//
.build();
final List<Param> params = req.getQueryParams();
assertEquals(params.size(), 2);
// From the signature tester, the URL should look like:
// normalized parameters:
// file=vacation.jpg&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_nonce=kllo9940pd9333jh&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1191242096&oauth_token=nnch734d00sl2jdk&oauth_version=1.0&size=original
// signature base string:
// GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal
// signature: tR3+Ty81lMeYAr/Fid0kMTYa/WM=
// Authorization header: OAuth
// realm="",oauth_version="1.0",oauth_consumer_key="dpf43f3p2l4k3l03",oauth_token="nnch734d00sl2jdk",oauth_timestamp="1191242096",oauth_nonce="kllo9940pd9333jh",oauth_signature_method="HMAC-SHA1",oauth_signature="tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D"
String authHeader = req.getHeaders().get("Authorization");
Matcher m = Pattern.compile("oauth_signature=\"(.+?)\"").matcher(authHeader);
assertEquals(m.find(), true);
String encodedSig = m.group(1);
String sig = null;
try {
sig = URLDecoder.decode(encodedSig, "UTF-8");
} catch (UnsupportedEncodingException e) {
fail("bad encoding", e);
}
assertEquals(sig, "tR3+Ty81lMeYAr/Fid0kMTYa/WM=");
assertEquals(req.getUrl(), "http://photos.example.net/photos?file=vacation.jpg&size=original");
}
示例15: calculateSignature
import org.asynchttpclient.Param; //导入依赖的package包/类
/**
* Method for calculating OAuth signature using HMAC/SHA-1 method.
*
* @param method the request methode
* @param uri the request Uri
* @param oauthTimestamp the timestamp
* @param nonce the nonce
* @param formParams the formParams
* @param queryParams the query params
* @return the signature
*/
public String calculateSignature(String method, Uri uri, long oauthTimestamp, String nonce,
List<Param> formParams, List<Param> queryParams) {
StringBuilder sb = signatureBaseString(method, uri, oauthTimestamp, nonce, formParams, queryParams);
ByteBuffer rawBase = StringUtils.charSequence2ByteBuffer(sb, UTF_8);
byte[] rawSignature = mac.digest(rawBase);
// and finally, base64 encoded... phew!
return Base64.encode(rawSignature);
}