/** * Create a new {@link HttpClient}. Note that this method should only be used outside of the context of an application. Within Micronaut use * {@link javax.inject.Inject} to inject a client instead * * @param url The base URL * @return The client */ static RxHttpClient create(URL url) { return new DefaultHttpClient(url); } }
/** * Perform an HTTP request for the given request object emitting the full HTTP response from returned * {@link Publisher}. * * @param request The {@link HttpRequest} to execute * @param <I> The request body type * @return A {@link Publisher} that emits the full {@link HttpResponse} object */ default <I> Publisher<HttpResponse<ByteBuffer>> exchange(HttpRequest<I> request) { return exchange(request, ByteBuffer.class); }
/** * Perform an HTTP request for the given request object emitting the full HTTP response from returned * {@link org.reactivestreams.Publisher} and converting the response body to the specified type. * * @param request The {@link HttpRequest} to execute * @param <I> The request body type * @return A string result or null if a 404 is returned * @throws HttpClientResponseException if an error status is returned */ default <I> String retrieve(HttpRequest<I> request) { return retrieve(request, String.class); }
/** * @param url The URL * @param configuration The {@link HttpClientConfiguration} object */ public DefaultHttpClient(URL url, HttpClientConfiguration configuration) { this( LoadBalancer.fixed(url), configuration, null, new DefaultThreadFactory(MultithreadEventLoopGroup.class), createSslBuilder(), createDefaultMediaTypeRegistry(), AnnotationMetadataResolver.DEFAULT ); }
@Override public HttpClient start() { if (!isRunning()) { this.group = createEventLoopGroup(configuration, threadFactory); } return this; }
/** * Perform an HTTP request for the given request object emitting the full HTTP response from returned * {@link org.reactivestreams.Publisher}. * * @param request The {@link HttpRequest} to execute * @param <I> The request body type * @param <O> The response body type * @return The full {@link HttpResponse} object */ default <I, O> HttpResponse<O> exchange(HttpRequest<I> request) { return exchange(request, (Argument<O>) null); }
@Override public <T> MutableHttpRequest<T> post(String uri, T body) { HttpMethod method = HttpMethod.POST; return buildRequest(uri, body, method); }
/** * Perform an HTTP request for the given request object emitting the full HTTP response from returned * {@link Publisher} and converting the response body to the specified type. * * @param request The {@link HttpRequest} to execute * @param <I> The request body type * @return A {@link Publisher} that emits String result */ default <I> Publisher<String> retrieve(HttpRequest<I> request) { return retrieve(request, String.class); }
@Override public String toString() { return getMethod() + " " + uri; } }
/** * Default constructor. */ public DefaultHttpClientConfiguration() { this.connectionPoolConfiguration = new DefaultConnectionPoolConfiguration(); }
@SuppressWarnings("unchecked") @Override public <I> Flowable<Map<String, Object>> jsonStream(io.micronaut.http.HttpRequest<I> request) { Flowable flowable = jsonStream(request, Map.class); return flowable; }
@Override public <T> MutableHttpRequest<T> create(HttpMethod httpMethod, String uri) { return new NettyClientHttpRequest<>(httpMethod, uri); }
/** * @param url The URL * @param configuration The {@link HttpClientConfiguration} object * @param contextPath The base URI to prepend to request uris */ public DefaultHttpClient(URL url, HttpClientConfiguration configuration, String contextPath) { this( LoadBalancer.fixed(url), configuration, contextPath, new DefaultThreadFactory(MultithreadEventLoopGroup.class), createSslBuilder(), createDefaultMediaTypeRegistry(), AnnotationMetadataResolver.DEFAULT ); }
/** * Create a new {@link HttpClient}. Note that this method should only be used outside of the context of a * Micronaut application. Within Micronaut use {@link javax.inject.Inject} to inject a client instead. * * @param url The base URL * @return The client */ static HttpClient create(URL url) { return new DefaultHttpClient(url); } }
@Override public <T> MutableHttpRequest<T> put(String uri, T body) { return buildRequest(uri, body, HttpMethod.PUT); }
@Override default Flowable<String> retrieve(String uri) { return (Flowable<String>) HttpClient.super.retrieve(uri); }
/** * Create a new {@link HttpClient}. Note that this method should only be used outside of the context of an application. Within Micronaut use * {@link javax.inject.Inject} to inject a client instead * * @param url The base URL * @return The client */ static RxStreamingHttpClient create(URL url) { return new DefaultHttpClient(url); } }
@Override public <T> MutableHttpRequest<T> delete(String uri, T body) { return buildRequest(uri, body, HttpMethod.DELETE); }
/** * Perform an HTTP request for the given request object emitting the full HTTP response from returned * {@link Publisher} and converting the response body to the specified type. * * @param request The {@link HttpRequest} to execute * @param bodyType The body type * @param <I> The request body type * @param <O> The response body type * @return A {@link Publisher} that emits a result of the given type */ default <I, O> Publisher<O> retrieve(HttpRequest<I> request, Argument<O> bodyType) { return retrieve(request, bodyType, DEFAULT_ERROR_TYPE); }