users@javaee-spec.java.net

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

From: Romain Manni-Bucau <rmannibucau_at_gmail.com>
Date: Sun, 21 Jun 2015 13:49:00 +0200

Le 20 juin 2015 23:34, "Arun Gupta" <arun.gupta_at_gmail.com> a écrit :
>
> That does work like @Starup for CDI but still no portable way to
> access host/port. Can you add a link to this blog in the issue?
>

Done

For host port i fear access will never be possible in a reliable way.
Cluster access could be spec-ed.

> Arun
>
> On Fri, Jun 19, 2015 at 11:31 AM, Romain Manni-Bucau
> <rmannibucau_at_gmail.com> wrote:
> >
> > Le 19 juin 2015 16:21, "Arun Gupta" <arun.gupta_at_gmail.com> a écrit :
> >>
> >> >>
> >> >> Currently the registration is happening in @Startup @Singleton.
> >> >> Ideally would like this in a @ApplicationScoped bean but there is no
> >> >> @Startup there.
> >> >>
> >> >
> >> > @Observes @ApplicationScoped startup? or through an extension
> >> > AfterValidation event?
> >>
> >> Sample code?
> >>
> >
> > https://rmannibucau.wordpress.com/2015/03/10/cdi-and-startup/
> >
> >> Arun
> >>
> >> >
> >> >>
> >> >> > (2) How to access the necessary information like host/port for
the
> >> >> > registration.
> >> >> >
> >> >> > JAX-RS typically operates at the level of paths and contexts, not
> >> >> > hosts
> >> >> > and ports. Even though you can get a URI with that info, it is
really
> >> >> > beyond
> >> >> > JAX-RS IMO.
> >> >> >
> >> >>
> >> >> Host/port can be extracted from @UriInfo but that is only after the
> >> >> request has been made.
> >> >
> >> >
> >> > Issue is it can be irrelevant as well (internal calls/public calls
> >> > etc...).
> >> > JAXRS is passive where container is active on this aspect.
> >> >
> >> >>
> >> >>
> >> >> > As for (1), JAX-RS has its own registration phase for resources,
> >> >> > providers and features. You can do this when defining an
Application
> >> >> > subclass and also in any DynamicFeature that is automatically
> >> >> > discovered
> >> >> > (which are processed at deploy time). Neither was designed with
your
> >> >> > use
> >> >> > case in mind, though.
> >> >> >
> >> >>
> >> >> Can host/port information be retrieved in any of those?
> >> >>
> >> >> Arun
> >> >>
> >> >> > — Santiago
> >> >> >
> >> >> >> On Jun 19, 2015, at 7:41 AM, Arun Gupta <arun.gupta_at_gmail.com>
> >> >> >> wrote:
> >> >> >>
> >> >> >> Yes, that would be the ideal and clean solution.
> >> >> >>
> >> >> >> Filed [1] for tracking.
> >> >> >>
> >> >> >> [1] https://java.net/jira/browse/JAVAEE_SPEC-47
> >> >> >>
> >> >> >> Cheers,
> >> >> >> Arun
> >> >> >>
> >> >> >>
> >> >> >> On Fri, Jun 19, 2015 at 6:52 AM, Antonio Goncalves
> >> >> >> <antonio.goncalves_at_gmail.com> wrote:
> >> >> >>> That brings back a topic we've been talking (and avoiding) for
> >> >> >>> quite a
> >> >> >>> long
> >> >> >>> time : EJB services going back to where they should go.
> >> >> >>>
> >> >> >>> Like @Transactional was created in JTA to be used on any beans,
> >> >> >>> @Startup,
> >> >> >>> @Schedule... should follow the same path. @Startup should go to
the
> >> >> >>> Java EE
> >> >> >>> Concurrency spec and be used anywhere.
> >> >> >>>
> >> >> >>> Antonoi
> >> >> >>>
> >> >> >>> On Fri, Jun 19, 2015 at 12:31 PM, Arun Gupta <
arun.gupta_at_gmail.com>
> >> >> >>> wrote:
> >> >> >>>>
> >> >> >>>> Already using ZooKeeper as a service registry [1].
> >> >> >>>>
> >> >> >>>> The key question is how does a REST endpoint advertise itself
to
> >> >> >>>> this
> >> >> >>>> registry. We need a @Startup for a JAX-RS endpoint. Is there an
> >> >> >>>> equivalent?
> >> >> >>>>
> >> >> >>>> [1]
> >> >> >>>>
> >> >> >>>>
> >> >> >>>>
http://blog.arungupta.me/zookeeper-microservice-registration-discovery/
> >> >> >>>>
> >> >> >>>> Arun
> >> >> >>>>
> >> >> >>>> On Fri, Jun 19, 2015 at 11:00 AM, Romain Manni-Bucau
> >> >> >>>> <rmannibucau_at_gmail.com> wrote:
> >> >> >>>>> Maybe I get it wrong but looks like you need a service
registry
> >> >> >>>>> *outside*
> >> >> >>>>> the container itself no?
> >> >> >>>>>
> >> >> >>>>> Then just getting injected a client would make it easy to use.
> >> >> >>>>>
> >> >> >>>>> Le 19 juin 2015 10:19, "Arun Gupta" <arun.gupta_at_gmail.com> a
> >> >> >>>>> écrit :
> >> >> >>>>>>
> >> >> >>>>>> 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
> >> >> >>>>
> >> >> >>>>
> >> >> >>>>
> >> >> >>>> --
> >> >> >>>> http://blog.arungupta.me
> >> >> >>>> http://twitter.com/arungupta
> >> >> >>>
> >> >> >>>
> >> >> >>>
> >> >> >>>
> >> >> >>> --
> >> >> >>> Antonio Goncalves
> >> >> >>> Software architect, Java Champion and Pluralsight author
> >> >> >>>
> >> >> >>> Web site | Twitter | LinkedIn | Pluralsight | Paris JUG | Devoxx
> >> >> >>> France
> >> >> >>
> >> >> >>
> >> >> >>
> >> >> >> --
> >> >> >> http://blog.arungupta.me
> >> >> >> http://twitter.com/arungupta
> >> >> >
> >> >>
> >> >>
> >> >>
> >> >> --
> >> >> http://blog.arungupta.me
> >> >> http://twitter.com/arungupta
> >> >
> >> >
> >>
> >>
> >>
> >> --
> >> http://blog.arungupta.me
> >> http://twitter.com/arungupta
>
>
>
> --
> http://blog.arungupta.me
> http://twitter.com/arungupta