/** * 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); }
/** * <p>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.</p> * <p> * <p>This method will send a {@code Content-Length} header and except a content length header the response and * is designed for simple non-streaming exchanges of data</p> * <p> * <p>By default the exchange {@code Content-Type} is application/json, unless otherwise specified in the passed * {@link HttpRequest}</p> * * @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 The full {@link HttpResponse} object */ default <I, O> HttpResponse<O> exchange(HttpRequest<I> request, Argument<O> bodyType) { return exchange(request, bodyType, HttpClient.DEFAULT_ERROR_TYPE); }
/** * Perform a GET request for the given request object emitting the full HTTP response from returned * {@link org.reactivestreams.Publisher}. * * @param uri The URI of the GET request * @param <O> The response body type * @return The full {@link HttpResponse} object */ default <O> HttpResponse<O> exchange(String uri) { return exchange(HttpRequest.GET(uri), (Argument<O>) null); }
/** * 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 bodyType The body type * @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, Class<O> bodyType) { return exchange(request, Argument.of(bodyType)); }
/** * Perform a GET request for the given request object emitting the full HTTP response from returned * {@link org.reactivestreams.Publisher}. * * @param uri The URI of the GET request * @param <O> The response body type * @param bodyType The body type * @return The full {@link HttpResponse} object */ default <O> HttpResponse<O> exchange(String uri, Class<O> bodyType) { return exchange(HttpRequest.GET(uri), Argument.of(bodyType)); }
/** * Perform a GET request for the given request object emitting the full HTTP response from returned * {@link org.reactivestreams.Publisher}. * * @param uri The URI of the GET request * @param <O> The response body type * @param <E> The error type * @param bodyType The body type * @param errorType The error type * @return The full {@link HttpResponse} object */ default <O, E> HttpResponse<O> exchange(String uri, Class<O> bodyType, Class<E> errorType) { return exchange(HttpRequest.GET(uri), Argument.of(bodyType), Argument.of(errorType)); } }
/** * 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 bodyType The body type * @param errorType The error type * @param <I> The request body type * @param <O> The response body type * @param <E> The error type * @return A result of the given type or null the URI returns a 404 * @throws HttpClientResponseException if an error status is returned */ @SuppressWarnings("unchecked") default <I, O, E> O retrieve(HttpRequest<I> request, Argument<O> bodyType, Argument<E> errorType) { HttpResponse<O> response = exchange(request, bodyType, errorType); if (HttpStatus.class.isAssignableFrom(bodyType.getType())) { return (O) response.getStatus(); } else { return response .getBody() .orElseThrow(() -> new HttpClientResponseException( "Empty body", response )); } }
/** * 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); }
/** * 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); }
/** * <p>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.</p> * <p> * <p>This method will send a {@code Content-Length} header and except a content length header the response and * is designed for simple non-streaming exchanges of data</p> * <p> * <p>By default the exchange {@code Content-Type} is application/json, unless otherwise specified in the passed * {@link HttpRequest}</p> * * @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 The full {@link HttpResponse} object */ default <I, O> HttpResponse<O> exchange(HttpRequest<I> request, Argument<O> bodyType) { return exchange(request, bodyType, HttpClient.DEFAULT_ERROR_TYPE); }
/** * <p>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.</p> * <p> * <p>This method will send a {@code Content-Length} header and except a content length header the response and * is designed for simple non-streaming exchanges of data</p> * <p> * <p>By default the exchange {@code Content-Type} is application/json, unless otherwise specified in the passed * {@link HttpRequest}</p> * * @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 The full {@link HttpResponse} object */ default <I, O> HttpResponse<O> exchange(HttpRequest<I> request, Argument<O> bodyType) { return exchange(request, bodyType, HttpClient.DEFAULT_ERROR_TYPE); }
/** * Perform a GET request for the given request object emitting the full HTTP response from returned * {@link org.reactivestreams.Publisher}. * * @param uri The URI of the GET request * @param <O> The response body type * @return The full {@link HttpResponse} object */ default <O> HttpResponse<O> exchange(String uri) { return exchange(HttpRequest.GET(uri), (Argument<O>) null); }
/** * Perform a GET request for the given request object emitting the full HTTP response from returned * {@link org.reactivestreams.Publisher}. * * @param uri The URI of the GET request * @param <O> The response body type * @return The full {@link HttpResponse} object */ default <O> HttpResponse<O> exchange(String uri) { return exchange(HttpRequest.GET(uri), (Argument<O>) null); }
/** * 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 bodyType The body type * @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, Class<O> bodyType) { return exchange(request, Argument.of(bodyType)); }
/** * 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 bodyType The body type * @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, Class<O> bodyType) { return exchange(request, Argument.of(bodyType)); }
/** * Perform a GET request for the given request object emitting the full HTTP response from returned * {@link org.reactivestreams.Publisher}. * * @param uri The URI of the GET request * @param <O> The response body type * @param bodyType The body type * @return The full {@link HttpResponse} object */ default <O> HttpResponse<O> exchange(String uri, Class<O> bodyType) { return exchange(HttpRequest.GET(uri), Argument.of(bodyType)); }
/** * Perform a GET request for the given request object emitting the full HTTP response from returned * {@link org.reactivestreams.Publisher}. * * @param uri The URI of the GET request * @param <O> The response body type * @param bodyType The body type * @return The full {@link HttpResponse} object */ default <O> HttpResponse<O> exchange(String uri, Class<O> bodyType) { return exchange(HttpRequest.GET(uri), Argument.of(bodyType)); } }
/** * Perform a GET request for the given request object emitting the full HTTP response from returned * {@link org.reactivestreams.Publisher}. * * @param uri The URI of the GET request * @param <O> The response body type * @param <E> The error type * @param bodyType The body type * @param errorType The error type * @return The full {@link HttpResponse} object */ default <O, E> HttpResponse<O> exchange(String uri, Class<O> bodyType, Class<E> errorType) { return exchange(HttpRequest.GET(uri), Argument.of(bodyType), Argument.of(errorType)); } }
@Test @Ignore public void testMailSend() throws Exception { //String requestBody = "{\"cc\": [\"sergio.delamo@softamo.com\"],\"recipient\": \"sergio.delamo@softamo.com\", \"subject\": \"Interested in Pet\", \"replyTo\": \"sergio.delamo@softamo.com\", \"htmlBody\": \"Body html\", \"bcc\": [\"sergio.delamo@softamo.com\"]}"; String requestBody = "{\"recipient\": \"sergio.delamo@softamo.com\"}"; HttpResponse rsp = client.toBlocking().exchange(HttpRequest.POST("/v1/mail/send",requestBody)); assertEquals(200, rsp.getStatus().getCode()); } }