Skip to content

Commit

Permalink
Merge pull request #32058 from geoand/#32047
Browse files Browse the repository at this point in the history
Allow use of null in REST Client request body
  • Loading branch information
geoand authored Mar 23, 2023
2 parents 286cf2c + 6737655 commit 6121033
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
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

0 comments on commit 6121033

Please sign in to comment.