users@javaee-spec.java.net

[javaee-spec users] Re: Eagerly getting host/port of a JAX-RS endpoint

From: Arun Gupta <arun.gupta_at_gmail.com>
Date: Fri, 19 Jun 2015 10:18:33 +0100

Currently, I'm using @Startup @Singleton EJB [1] for registering the
REST endpoint but the host/port are statically defined. This endpoint
could be deployed on a PaaS or a Docker container or somewhere else
where the host/port could be different every time.

Ideally, I'd love something like:

@Path("catalog")
@Startup
public class CatalogItemREST {

  @PostConstruct
  public void init() {
    // get Host
    // get Port
    // register the service
  }
}


[1] https://github.com/arun-gupta/microservices/blob/master/microservice/catalog/src/main/java/org/javaee7/wildfly/samples/everest/catalog/CatalogService.java

[2] https://github.com/arun-gupta/microservices/blob/master/microservice/catalog/src/main/java/org/javaee7/wildfly/samples/everest/catalog/CatalogItemREST.java

Thoughts?

Cheers
Arun

On Fri, Jun 19, 2015 at 1:10 AM, Romain Manni-Bucau
<rmannibucau_at_gmail.com> wrote:
> @Arun: can you precise the kind of API you expect (pseudo code is fine)?
> Typically I think to these common cases:
> - host is 0.0.0.0
> - you have N connectors (so how do you select)
> - you are behind a proxy (httpd/ngnix)
>
> Romain
>
> Le 18 juin 2015 23:52, "Arun Gupta" <arun.gupta_at_gmail.com> a écrit :
>>
>> If multiple WARs with JAX-RS REST endpoints are deployed, how are URIs
>> of these endpoints advertised?
>>
>> Tried using @Startup @Singleton but there is no standard/non-standard
>> way to access host/port there.
>>
>> @PostConstruct for JAX-RS endpoint is not called until the endpoint is
>> invoked once.
>>
>> @Context UriInfo is only available after the endpoint has been invoked.
>>
>> There is a bit of discussion at:
>>
>> https://twitter.com/arungupta/status/611493850092322816
>>
>> Any suggestions?
>>
>> Cheers
>> Arun
>>
>> --
>> http://blog.arungupta.me
>> http://twitter.com/arungupta



-- 
http://blog.arungupta.me
http://twitter.com/arungupta