本文整理汇总了Java中com.ning.http.client.uri.Uri类的典型用法代码示例。如果您正苦于以下问题:Java Uri类的具体用法?Java Uri怎么用?Java Uri使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Uri类属于com.ning.http.client.uri包,在下文中一共展示了Uri类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCircuitBreaker
import com.ning.http.client.uri.Uri; //导入依赖的package包/类
protected Optional<CircuitBreaker<Response>> getCircuitBreaker(RequestBuilderWrapper requestBuilderWrapper) {
if (requestBuilderWrapper.disableCircuitBreaker)
return Optional.empty();
// Circuit breaking is enabled for this call. So we return the custom one specified or use the default one if a
// custom one is not specified.
if (requestBuilderWrapper.customCircuitBreaker.isPresent())
return requestBuilderWrapper.customCircuitBreaker;
// No custom circuit breaker. Use the default for the given request's host.
Uri uri = Uri.create(requestBuilderWrapper.url);
String host = uri.getHost();
EventLoop nettyEventLoop = requestBuilderWrapper.getCtx() == null
? null
: requestBuilderWrapper.getCtx().channel().eventLoop();
CircuitBreaker<Integer> defaultStatusCodeCircuitBreaker = getDefaultHttpStatusCodeCircuitBreakerForKey(
host, Optional.ofNullable(nettyEventLoop), Optional.ofNullable(nettyEventLoop)
);
return Optional.of(
new CircuitBreakerDelegate<>(
defaultStatusCodeCircuitBreaker, response -> (response == null ? null : response.getStatusCode())
)
);
}
示例2: doExecute
import com.ning.http.client.uri.Uri; //导入依赖的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);
}
示例3: testLogRemoteRequest
import com.ning.http.client.uri.Uri; //导入依赖的package包/类
@Test
public void testLogRemoteRequest() {
Request req = mock(Request.class);
when(req.getUri()).thenReturn(Uri.create("http://test.yahoo.com"));
when(req.getHeaders()).thenReturn(new FluentCaseInsensitiveStringsMap());
Response resp = mock(Response.class);
when(resp.getHeader(anyString())).thenReturn("mock resp header");
when(resp.getHeader("content-length")).thenReturn("100");
String reqStatus = "test_status";
ParsecAsyncProgress progress = new ParsecAsyncProgress();
ParsecClientProfilingLogUtil.logRemoteRequest(req, resp, reqStatus, progress);
ParsecClientProfilingLogUtil.logRemoteRequest(req, null, reqStatus, progress);
}
示例4: verifyRequestBuilderWrapperGeneratedAsExpected
import com.ning.http.client.uri.Uri; //导入依赖的package包/类
private void verifyRequestBuilderWrapperGeneratedAsExpected(
RequestBuilderWrapper rbw, String url, String method, Optional<CircuitBreaker<Response>> customCb,
boolean disableCb
) {
assertThat(rbw.url).isEqualTo(url);
assertThat(rbw.httpMethod).isEqualTo(method);
assertThat(rbw.customCircuitBreaker).isEqualTo(customCb);
assertThat(rbw.disableCircuitBreaker).isEqualTo(disableCb);
Request req = rbw.requestBuilder.build();
assertThat(req.getMethod()).isEqualTo(method);
assertThat(req.getUri()).isEqualTo(Uri.create(url));
assertThat(req.getUrl()).isEqualTo(url);
assertThat(req.getNameResolver()).isEqualTo(MultiIpAwareNameResolver.INSTANCE);
}
示例5: build
import com.ning.http.client.uri.Uri; //导入依赖的package包/类
/**
* Buile new {@link ParsecAsyncHttpRequest} instance.
*
* @return {@link ParsecAsyncHttpRequest}
*/
@SuppressWarnings("PMD.NPathComplexity")
public ParsecAsyncHttpRequest build() {
ningRequestBuilder = new RequestBuilder(method)
.setContentLength(contentLength)
.setFollowRedirects(followRedirect)
.setHeaders(headers)
.setProxyServer(proxyServer)
.setRangeOffset(rangeOffset)
.setRequestTimeout(requestTimeout)
.setVirtualHost(virtualHost)
.setUri(new Uri(
uri.getScheme(),
uri.getUserInfo(),
uri.getHost(),
uri.getPort(),
uri.getPath(),
uri.getRawQuery()
));
if (body != null) {
ningRequestBuilder.setBody(body);
} else if (byteBody != null) {
ningRequestBuilder.setBody(byteBody);
}
if (bodyEncoding != null) {
ningRequestBuilder.setBodyEncoding(bodyEncoding);
}
if (cookies != null && !cookies.isEmpty()) {
for (NewCookie cookie : cookies) {
ningRequestBuilder.addCookie(new Cookie(
cookie.getName(),
cookie.getValue(),
false,
cookie.getDomain(),
cookie.getPath(),
cookie.getMaxAge(),
cookie.isSecure(),
cookie.isHttpOnly()
));
}
}
if (formParams != null) {
ningRequestBuilder.setFormParams(formParams);
}
if (queryParams != null) {
ningRequestBuilder.setQueryParams(queryParams);
}
if (acceptCompression && !headers.containsKey(ACCEPT_ENCODING_HEADER)) {
ningRequestBuilder.addHeader(ACCEPT_ENCODING_HEADER, COMPRESSION_TYPE);
}
for (Part part: bodyParts) {
ningRequestBuilder.addBodyPart(part);
}
return new ParsecAsyncHttpRequest(this);
}