com.yelstream.topp.standard.smallrye.config.net.URIConfig Maven / Gradle / Ivy
package com.yelstream.topp.standard.smallrye.config.net;
import io.smallrye.config.WithName;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Optional;
import java.util.function.Supplier;
interface URIConfig { //TO-DO: Purpose; is this any good at all?
@WithName("uri")
Optional uri();
@WithName("host")
Optional host();
@WithName("port")
Optional port();
default URL createURL(Supplier defaultURLSupplier) {
URI uri=createURI(()->{
URL url=defaultURLSupplier.get();
try {
return url.toURI();
} catch (URISyntaxException ex) {
throw new IllegalArgumentException(String.format("Failure to create URI; URL cannot be converted to an URI, URL is %s!",url),ex);
}
});
try {
return uri.toURL();
} catch (MalformedURLException ex) {
throw new IllegalArgumentException(String.format("Failure to create URL; URI cannot be converted to an URL, URI is %s!",uri),ex);
}
}
default URI createURI(Supplier defaultURISupplier) {
/*
UriBuilder builder=UriBuilder.fromUri(uri().orElse(defaultURISupplier.get()));
serverConfig.host().ifPresent(builder::host);
serverConfig.port().ifPresent(builder::port);
*/
return null;
}
}