package io.quarkus.resteasy.runtime.standalone;

import java.util.Objects;

import org.jboss.logging.Logger;

import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.net.SocketAddress;

final class LazyHostSupplier {
    private static final Logger logger = Logger.getLogger(LazyHostSupplier.class.getName());

    private final HttpServerRequest request;
    private String remoteHost = null;
    private boolean initialized = false;

    public LazyHostSupplier(final HttpServerRequest request) {
        Objects.requireNonNull(request);
        this.request = request;
    }

    public String getRemoteHost() {
        if (initialized) {
            return this.remoteHost;
        } else {
            SocketAddress socketAddress = null;
            try {
                socketAddress = request.remoteAddress();
            } catch (NullPointerException npe) {
                // ideally there shouldn't be an exception for this call.
                // This is just to workaround a current issue in vertx
                // https://github.com/quarkusio/quarkus/issues/5247
                // https://github.com/eclipse-vertx/vert.x/issues/3181
                // TODO: remove this workaround once vertx issue is resolved
                logger.debug("Ignoring exception that occurred when obtaining remote address of request " + request, npe);
            }
            // client address may not be available with VirtualHttp;
            this.remoteHost = socketAddress != null ? socketAddress.host() : null;
            initialized = true;
            return this.remoteHost;
        }
    }
}

@@ -73,42 +73,8 @@
 s;%0A%0A
-import org.jboss.logging.Logger;%0A%0A
 impo
@@ -189,101 +189,8 @@
 er %7B
-%0A    private static final Logger logger = Logger.getLogger(LazyHostSupplier.class.getName());
 %0A%0A  
@@ -617,635 +617,32 @@
 s = 
-null;%0A            try %7B%0A                socketAddress = request.remoteAddress();%0A            %7D catch (NullPointerException npe) %7B%0A                // ideally there shouldn't be an exception for this call.%0A                // This is just to workaround a current issue in vertx%0A                // https://github.com/quarkusio/quarkus/issues/5247%0A                // https://github.com/eclipse-vertx/vert.x/issues/3181%0A                // TODO: remove this workaround once vertx issue is resolved%0A                logger.debug(%22Ignoring exception that occurred when obtaining remote address of request %22 + request, npe);%0A            %7D
+request.remoteAddress();
 %0A   

Revert "Work around an issue in vertx where getting remote/client SocketAddress of the request leads to a NPE"