Skip to content

Commit

Permalink
Merge branch 'main' into #23127
Browse files Browse the repository at this point in the history
  • Loading branch information
troosan authored Sep 12, 2024
2 parents 110a2e4 + 74ef7b3 commit 533041a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
2 changes: 1 addition & 1 deletion bom/dev-ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<description>Dependency management for dev-ui. Importable by third party extension developers.</description>

<properties>
<vaadin.version>24.4.7</vaadin.version>
<vaadin.version>24.4.8</vaadin.version>
<lit.version>3.2.0</lit.version>
<lit-element.version>4.1.0</lit-element.version>
<lit-html.version>3.2.0</lit-html.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -26,6 +27,7 @@

import io.quarkus.mongodb.runtime.MongodbConfig;
import io.quarkus.runtime.annotations.RegisterForReflection;
import io.smallrye.mutiny.Uni;
import io.vertx.core.dns.DnsClientOptions;
import io.vertx.mutiny.core.Vertx;
import io.vertx.mutiny.core.dns.SrvRecord;
Expand Down Expand Up @@ -130,12 +132,21 @@ private List<String> resolveSrvRequest(final String srvHost) {
if (SRV_CACHE.containsKey(srvHost)) {
srvRecords = SRV_CACHE.get(srvHost);
} else {
srvRecords = dnsClient.resolveSRV(srvHost).invoke(new Consumer<>() {
@Override
public void accept(List<SrvRecord> srvRecords) {
SRV_CACHE.put(srvHost, srvRecords);
}
}).await().atMost(timeout);
srvRecords = Uni.createFrom().<List<SrvRecord>> deferred(
new Supplier<>() {
@Override
public Uni<? extends List<SrvRecord>> get() {
return dnsClient.resolveSRV(srvHost);
}
})
.onFailure().retry().withBackOff(Duration.ofSeconds(1)).atMost(3)
.invoke(new Consumer<>() {
@Override
public void accept(List<SrvRecord> srvRecords) {
SRV_CACHE.put(srvHost, srvRecords);
}
})
.await().atMost(timeout);
}

if (srvRecords.isEmpty()) {
Expand Down Expand Up @@ -167,12 +178,22 @@ public List<String> resolveTxtRequest(final String host) {
try {
Duration timeout = config.getOptionalValue(DNS_LOOKUP_TIMEOUT, Duration.class)
.orElse(Duration.ofSeconds(5));
return dnsClient.resolveTXT(host).invoke(new Consumer<>() {
@Override
public void accept(List<String> strings) {
TXT_CACHE.put(host, strings);
}
}).await().atMost(timeout);

return Uni.createFrom().<List<String>> deferred(
new Supplier<>() {
@Override
public Uni<? extends List<String>> get() {
return dnsClient.resolveTXT(host);
}
})
.onFailure().retry().withBackOff(Duration.ofSeconds(1)).atMost(3)
.invoke(new Consumer<>() {
@Override
public void accept(List<String> strings) {
TXT_CACHE.put(host, strings);
}
})
.await().atMost(timeout);
} catch (Throwable e) {
throw new MongoConfigurationException("Unable to look up TXT record for host " + host, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

Expand All @@ -20,7 +21,6 @@
import jakarta.xml.bind.UnmarshalException;
import jakarta.xml.bind.Unmarshaller;

import org.jboss.resteasy.reactive.common.util.StreamUtil;
import org.jboss.resteasy.reactive.server.spi.ResteasyReactiveResourceInfo;
import org.jboss.resteasy.reactive.server.spi.ServerMessageBodyReader;
import org.jboss.resteasy.reactive.server.spi.ServerRequestContext;
Expand Down Expand Up @@ -93,14 +93,16 @@ private Unmarshaller getUnmarshall(Class<Object> type) throws JAXBException {
}

private Object doReadFrom(Class<Object> type, Type genericType, InputStream entityStream) throws IOException {
if (isInputStreamEmpty(entityStream)) {
PushbackInputStream pushbackEntityStream = new PushbackInputStream(entityStream);
if (isStreamEmpty(pushbackEntityStream)) {
return null;
}

return unmarshal(entityStream, type);
return unmarshal(pushbackEntityStream, type);
}

private boolean isInputStreamEmpty(InputStream entityStream) throws IOException {
return StreamUtil.isEmpty(entityStream) || entityStream.available() == 0;
private boolean isStreamEmpty(PushbackInputStream pushbackStream) throws IOException {
int firstByte = pushbackStream.read();
pushbackStream.unread(firstByte);
return firstByte == -1;
}
}

0 comments on commit 533041a

Please sign in to comment.