mulesoft-labs / raml-for-jax-rs

This project is all about two way transformation of JAX-RS-annotated Java code to RAML API description and back.
Other
295 stars 181 forks source link

Support including UriInfo in request methods #46

Closed talios closed 6 years ago

talios commented 9 years ago

Is there anyway currently to support the generation of JAX-RS methods that include @Context UriInfo uriInfo as an argument from within a RAML document?

This is needed to that I can call uriInfo.getAbsolutePath() to get the path of the current request so inclusion in custom representation generation.

Is this currently supported by raml-for-jax-rs?

petrochenko-pavel-a commented 9 years ago

Currently it is not supported, but it is pretty simple to add as an option. But you probably do not want to add it to all your methods, so we have to think about how to mark methods that needs which needs context parameters. I am thinking about providing extra file with configuration/annotations for your raml or about specially named traits to mark. Actually first option looks better for me as more generic.

Do you have any other ideas about possible implementation?

Regards, Pavel.

ddossot commented 9 years ago

The intention was in fact that you would use class variables for these extra contextual fields. No need to add them into the methods.

petrochenko-pavel-a commented 9 years ago

Smart idea. Together with security it probably needed to be added to something like FAQ section in the documentation. But still i think we may support it with coming of metadata in RAML 1.0(if it will be there)

Regards, Pavel 06 Мар 2015 г. 15:53 пользователь "David Dossot" notifications@github.com написал:

The intention was in fact that you would use class variables for these extra contextual fields. No need to add them into the methods.

— Reply to this email directly or view it on GitHub https://github.com/mulesoft/raml-for-jax-rs/issues/46#issuecomment-77570803 .

talios commented 9 years ago

@ddossot class variables? That sounds rather non-thread safe, unles they're ThreadLocals? For the record, I actually kinda do want it on every method, as I'm wanting to return a HAL document/representation using my HalBuilder library, and want to include the self link back to the calling URI.

Tho this probably really calls out for more control on supporting return types, currently the project supports JSON Schema using and the pojo generator. Maybe I want to just configure/extend the project with my own form of generator that can work with my HalBuilder library ( and its JAX-RS extension ).

ddossot commented 9 years ago

The JAX-RS container is mandated to take care of the thread safety of these annotated fields. Depending on the instantiation policy of the resource, it will either use actual instances or thread-local bound values.

So just add:

@Context
private UriInfo uriInfo;

in your resource implementation and you will be good.

talios commented 9 years ago

Oh cool. +1 will give that a shot.