Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow use of null in REST Client request body #32058

Merged
merged 1 commit into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.quarkus.rest.client.reactive;

import java.net.URI;

import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;

import org.assertj.core.api.Assertions;
import org.eclipse.microprofile.rest.client.RestClientBuilder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;
import io.quarkus.test.common.http.TestHTTPResource;

public class NullBodyTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar.addClasses(Client.class));

@TestHTTPResource
URI baseUri;

@Test
void withBody() {
Client client = RestClientBuilder.newBuilder().baseUri(baseUri).build(Client.class);

Assertions.assertThatThrownBy(() -> client.call("test")).hasMessageContaining("404");
}

@Test
void withoutBody() {
Client client = RestClientBuilder.newBuilder().baseUri(baseUri).build(Client.class);

Assertions.assertThatThrownBy(() -> client.call(null)).hasMessageContaining("404");
}

public interface Client {

@Path("/")
@POST
void call(String body);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ public ClientRequestContextImpl getOrCreateClientRequestContext() {
public Buffer writeEntity(Entity<?> entity, MultivaluedMap<String, String> headerMap, WriterInterceptor[] interceptors)
throws IOException {
Object entityObject = entity.getEntity();
if (entityObject == null) {
return AsyncInvokerImpl.EMPTY_BUFFER;
}

Class<?> entityClass;
Type entityType;
if (entityObject instanceof GenericEntity) {
Expand Down