A questiion on Cafe.init() to build baseUri
Emily-Jiang opened this issue · 1 comments
Emily-Jiang commented
I see you tried to work out the uri via InetAddress. I am wondering how it will function in Kubernetes. MicroProfile Rest Client offers a good service binding approach, which allows you to override the backend url under a different environment. Can you take a look at this guide to see whether you can use MicroProfile Rest Client. You can define an interface with getAllCoffees() and then annotated with @RegisterRestClient
. In your Coffee.java, you can inject that via @Inject @RestClient AInterface
.
@PostConstruct
private void init() {
try {
HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext()
.getRequest();
InetAddress inetAddress = InetAddress.getByName(request.getServerName());
baseUri = FacesContext.getCurrentInstance().getExternalContext().getRequestScheme() + "://"
+ inetAddress.getHostName() + ":"
+ FacesContext.getCurrentInstance().getExternalContext().getRequestServerPort()
+ "/javaee-cafe/rest/coffees";
this.client = ClientBuilder.newBuilder().hostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
}).build();
this.getAllCoffees();
} catch (IllegalArgumentException | NullPointerException | WebApplicationException | UnknownHostException ex) {
logger.severe("Processing of HTTP response failed.");
ex.printStackTrace();
}
}
edburns commented
This is a worthwhile research area, but not something I think that we want to complete before the blog post. I'll leave this open, but we won't work on it just yet.