Java Code Examples for com.linecorp.armeria.client.WebClient#builder()

The following examples show how to use com.linecorp.armeria.client.WebClient#builder() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArmeriaClientHttpConnector.java    From armeria with Apache License 2.0 6 votes vote down vote up
private ArmeriaClientHttpRequest createRequest(HttpMethod method, URI uri) {
    final String scheme = uri.getScheme();
    final String authority = uri.getRawAuthority();
    final String path = uri.getRawPath();
    final String query = uri.getRawQuery();

    checkArgument(!Strings.isNullOrEmpty(authority), "URI is not absolute: %s", uri);
    checkArgument(!Strings.isNullOrEmpty(path), "path is undefined: %s", uri);

    final URI baseUri = URI.create(Strings.isNullOrEmpty(scheme) ? authority : scheme + "://" + authority);
    final WebClientBuilder builder = WebClient.builder(baseUri);
    configurators.forEach(c -> c.configure(builder));

    final String pathAndQuery = Strings.isNullOrEmpty(query) ? path : path + '?' + query;

    return new ArmeriaClientHttpRequest(builder.build(), method, pathAndQuery, uri, factoryWrapper);
}
 
Example 2
Source File: ContentPreviewerTest.java    From armeria with Apache License 2.0 6 votes vote down vote up
MyHttpClient(String uri, int maxLength) {
    final WebClientBuilder builder = WebClient.builder(serverExtension.httpUri().resolve(uri));

    final ContentPreviewerFactory factory = contentPreviewerFactory(maxLength);

    client = builder.decorator(ContentPreviewingClient.newDecorator(factory))
                    .decorator(LoggingClient.builder()
                                            .requestLogLevel(LogLevel.INFO)
                                            .successfulResponseLogLevel(LogLevel.INFO)
                                            .newDecorator())
                    .decorator((delegate, ctx, req) -> {
                        if (waitingFuture != null) {
                            ctx.log().whenComplete().thenAccept(waitingFuture::complete);
                        }
                        return delegate.execute(ctx, req);
                    }).build();
}