Skip to content

Commit

Permalink
fix(deps): update dependency io.micronaut:micronaut-core-bom to v4.3.…
Browse files Browse the repository at this point in the history
…11 (#1071)
  • Loading branch information
renovate[bot] authored and sdelamo committed Apr 7, 2024
1 parent 71ec5de commit 9db76b3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies {

testImplementation(mn.micronaut.http.client)
testImplementation(mn.micronaut.http.server.tck)
testImplementation(mn.micronaut.jackson.databind)
testImplementation(libs.junit.platform.engine)
testImplementation(libs.junit.jupiter.engine)
testImplementation(mnValidation.micronaut.validation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public String getMethod() {

@Override
public String getUri() {
String url = request.getRequestURL().toString();
String url = request.getRequestURI();
if (request.getQueryString() != null) {
url += "?" + request.getQueryString();
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
micronaut-docs = "2.0.0"
micronaut = "4.3.9"
micronaut = "4.3.11"
groovy = "4.0.14"
spock = "2.3-groovy-4.0"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.micronaut.context.ApplicationContext;
import io.micronaut.context.env.Environment;
import io.micronaut.core.annotation.NonNull;
import io.micronaut.core.convert.ConversionService;
import io.micronaut.core.convert.value.MutableConvertibleValues;
import io.micronaut.core.type.Argument;
import io.micronaut.core.util.StringUtils;
Expand All @@ -14,6 +15,7 @@
import io.micronaut.http.HttpStatus;
import io.micronaut.http.client.exceptions.HttpClientResponseException;
import io.micronaut.http.tck.ServerUnderTest;
import io.micronaut.json.JsonMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -27,6 +29,8 @@ public class GcpFunctionHttpServerUnderTest implements ServerUnderTest {
private static final Logger LOG = LoggerFactory.getLogger(GcpFunctionHttpServerUnderTest.class);

private final HttpFunction function;
private final ConversionService conversionService;
private final JsonMapper jsonMapper;

public GcpFunctionHttpServerUnderTest(Map<String, Object> properties) {
properties.put("micronaut.server.context-path", "/");
Expand All @@ -38,11 +42,13 @@ public GcpFunctionHttpServerUnderTest(Map<String, Object> properties) {
.deduceEnvironment(false)
.start()
);
this.conversionService = function.getApplicationContext().getBean(ConversionService.class);
this.jsonMapper = function.getApplicationContext().getBean(JsonMapper.class);
}

@Override
public <I, O> HttpResponse<O> exchange(HttpRequest<I> request, Argument<O> bodyType) {
HttpResponse<O> response = new HttpResponseAdaptor<>(function.invoke(request), bodyType);
HttpResponse<O> response = new HttpResponseAdaptor<>(function.invoke(request), conversionService, jsonMapper, bodyType);
if (response.getStatus().getCode() >= 400) {
LOG.error("Response body: {}", response.getBody(String.class).orElse(null));
throw new HttpClientResponseException("error " + response.getStatus().getReason() + " (" + response.getStatus().getCode() + ")", response);
Expand Down Expand Up @@ -77,10 +83,19 @@ public Optional<Integer> getPort() {
static class HttpResponseAdaptor<O> implements HttpResponse<O> {

final GoogleHttpResponse googleHttpResponse;
private final ConversionService conversionService;
private final JsonMapper jsonMapper;
private final Argument<O> bodyType;

HttpResponseAdaptor(GoogleHttpResponse googleHttpResponse, Argument<O> bodyType) {
HttpResponseAdaptor(
GoogleHttpResponse googleHttpResponse,
ConversionService conversionService,
JsonMapper jsonMapper,
Argument<O> bodyType
) {
this.googleHttpResponse = googleHttpResponse;
this.conversionService = conversionService;
this.jsonMapper = jsonMapper;
this.bodyType = bodyType;
}

Expand Down Expand Up @@ -116,8 +131,16 @@ public MutableConvertibleValues<Object> getAttributes() {
public Optional<O> getBody() {
if (bodyType != null && bodyType.isAssignableFrom(byte[].class)) {
return (Optional<O>) Optional.of(googleHttpResponse.getBodyAsBytes());
} else {
} else if (bodyType == null) {
return (Optional<O>) Optional.of(googleHttpResponse.getBodyAsText());
} else {
return conversionService.convert(googleHttpResponse.getBodyAsText(), bodyType).or(() -> {
try {
return Optional.of(jsonMapper.readValue(googleHttpResponse.getBodyAsBytes(), bodyType));
} catch (IOException e) {
throw new HttpClientResponseException("Error reading body", this);
}
});
}
}
}
Expand Down

0 comments on commit 9db76b3

Please sign in to comment.