You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by tim clapp <vi...@yahoo.com.INVALID> on 2023/04/18 02:27:54 UTC
programmatic rest
I'd like to create a restful endpoint, in the fashion described here https://tomee.apache.org/tomee-8.0/examples/simple-rest.html, in a programmatic way that is idiomatic to TomEE.
For example, instead of annotating a method like this below, to bind the method to an http endpoint, I'd like to be able to programmatically create the binding....
@PUT
@Path("orders/invoice/{id}")
@Produces({MediaType.APPLICATION_XML})
@Lock(LockType.READ)
public Response DoSomething()
{ ... }
Is such a thing possible ?
How do I tie into the underlying objects TomEE manages so that I can "register" a new http endpoint in the same sort of fashion as I do above via annotations ?
-----------------------package com.bigfancy;
@Startup
@Singleton
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
@Lock(LockType.READ)
public class PublicAPI {
private static final Logger LOG = LogManager.getLogger(PublicAPI.class);
private static final Marker GMARKER = MarkerManager.getMarker("public-api");
@Context UriInfo uriInfo;
@Context HttpHeaders httpHeaders;
@Context Request request;
@Context SecurityContext securityContext;
@Context Providers providers;
@Context HttpServletRequest httpServletRequest;
@Resource SessionContext sessionContext;
public PublicAPI() {
super();
LOG.info("constructing public api");
}
@PostConstruct
public void init() {
// instead of defining the orders(..) method below....
// programmatically create the binding here...
}
@Destroy
public void destroy() {
LOG.info("destroying public api");
}
@POST
@Path("orders/invoice/{id}")
@Consumes({MediaType.WILDCARD})
@Produces({MediaType.WILDCARD})
public Response orders(
@HeaderParam("xyz")
@Required(true)
final String xyz
)
{
return null
}
}
RE: programmatic rest
Posted by "Shultz, Dmitry" <Dm...@kaltire.com>.
Totally agree with Jonathan.
If I have to do anythig like that I would look at this https://camel.apache.org/manual/rest-dsl.html
Dmitry
From: Jonathan S. Fisher <ex...@gmail.com>
Sent: Tuesday, April 18, 2023 6:55 AM
To: users@tomee.apache.org
Subject: Re: programmatic rest
Without diving deep into CXF and TomEE code, you can't programmatically add a new endpoint, but you really don't have to either. I would also advise against this, as you're be coding against a custom implementation that likely will break your
ZjQcmQRYFpfptBannerStart
This Message Is From an External Sender
ZjQcmQRYFpfptBannerEnd
Without diving deep into CXF and TomEE code, you can't programmatically add
a new endpoint, but you really don't have to either. I would also advise
against this, as you're be coding against a custom implementation that
likely will break your upgrade path.
If I were given this task, the most efficient, the fastest executing, and
safest way would be to use @PathParam, @QueryParam, @MatrixParam,
@CookieParam, @FormParam, or @HeaderParam with wildcard matches.
See here:
https://urldefense.com/v3/__https://docs.oracle.com/javaee/7/api/javax/ws/rs/package-summary.html__;!!LdWlNaMnLCM!bbgboiGckvNZ1gS3Ay31zjuigvAaLY8vpoDNOERuMfDdFM_x_q2zEv2BjDOVDIkmZZXLankfDi1Hwk6znO5mKQ$<https://urldefense.com/v3/__https:/docs.oracle.com/javaee/7/api/javax/ws/rs/package-summary.html__;!!LdWlNaMnLCM!bbgboiGckvNZ1gS3Ay31zjuigvAaLY8vpoDNOERuMfDdFM_x_q2zEv2BjDOVDIkmZZXLankfDi1Hwk6znO5mKQ$>
and here: https://urldefense.com/v3/__https://mkyong.com/tutorials/jax-rs-tutorials/__;!!LdWlNaMnLCM!bbgboiGckvNZ1gS3Ay31zjuigvAaLY8vpoDNOERuMfDdFM_x_q2zEv2BjDOVDIkmZZXLankfDi1Hwk4HD1WBXA$<https://urldefense.com/v3/__https:/mkyong.com/tutorials/jax-rs-tutorials/__;!!LdWlNaMnLCM!bbgboiGckvNZ1gS3Ay31zjuigvAaLY8vpoDNOERuMfDdFM_x_q2zEv2BjDOVDIkmZZXLankfDi1Hwk4HD1WBXA$>
cheers,
-Jonathan
On Mon, Apr 17, 2023 at 9:28 PM tim clapp <vi...@yahoo.com.invalid>>
wrote:
>
> I'd like to create a restful endpoint, in the fashion described here
> https://urldefense.com/v3/__https://tomee.apache.org/tomee-8.0/examples/simple-rest.html__;!!LdWlNaMnLCM!bbgboiGckvNZ1gS3Ay31zjuigvAaLY8vpoDNOERuMfDdFM_x_q2zEv2BjDOVDIkmZZXLankfDi1Hwk4qG2JJZg$<https://urldefense.com/v3/__https:/tomee.apache.org/tomee-8.0/examples/simple-rest.html__;!!LdWlNaMnLCM!bbgboiGckvNZ1gS3Ay31zjuigvAaLY8vpoDNOERuMfDdFM_x_q2zEv2BjDOVDIkmZZXLankfDi1Hwk4qG2JJZg$>, in a
> programmatic way that is idiomatic to TomEE.
>
> For example, instead of annotating a method like this below, to bind the
> method to an http endpoint, I'd like to be able to programmatically create
> the binding....
>
> @PUT
> @Path("orders/invoice/{id}")
> @Produces({MediaType.APPLICATION_XML})
> @Lock(LockType.READ)
> public Response DoSomething()
> { ... }
>
>
> Is such a thing possible ?
>
> How do I tie into the underlying objects TomEE manages so that I can
> "register" a new http endpoint in the same sort of fashion as I do above
> via annotations ?
>
>
> -----------------------package com.bigfancy;
>
>
> @Startup
> @Singleton
> @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
> @Lock(LockType.READ)
> public class PublicAPI {
> private static final Logger LOG =
> LogManager.getLogger(PublicAPI.class);
> private static final Marker GMARKER =
> MarkerManager.getMarker("public-api");
>
> @Context UriInfo uriInfo;
> @Context HttpHeaders httpHeaders;
> @Context Request request;
> @Context SecurityContext securityContext;
> @Context Providers providers;
> @Context HttpServletRequest httpServletRequest;
> @Resource SessionContext sessionContext;
>
>
>
>
> public PublicAPI() {
> super();
> LOG.info("constructing public api");
> }
>
>
> @PostConstruct
> public void init() {
> // instead of defining the orders(..) method below....
> // programmatically create the binding here...
> }
>
> @Destroy
> public void destroy() {
> LOG.info("destroying public api");
> }
>
> @POST
> @Path("orders/invoice/{id}")
> @Consumes({MediaType.WILDCARD})
> @Produces({MediaType.WILDCARD})
> public Response orders(
> @HeaderParam("xyz")
> @Required(true)
> final String xyz
> )
> {
> return null
> }
> }
>
--
Jonathan | exabrial@gmail.com<ma...@gmail.com>
Pessimists, see a jar as half empty. Optimists, in contrast, see it as half
full.
Engineers, of course, understand the glass is twice as big as it needs to
be.
Re: programmatic rest
Posted by "Jonathan S. Fisher" <ex...@gmail.com>.
Without diving deep into CXF and TomEE code, you can't programmatically add
a new endpoint, but you really don't have to either. I would also advise
against this, as you're be coding against a custom implementation that
likely will break your upgrade path.
If I were given this task, the most efficient, the fastest executing, and
safest way would be to use @PathParam, @QueryParam, @MatrixParam,
@CookieParam, @FormParam, or @HeaderParam with wildcard matches.
See here:
https://docs.oracle.com/javaee/7/api/javax/ws/rs/package-summary.html
and here: https://mkyong.com/tutorials/jax-rs-tutorials/
cheers,
-Jonathan
On Mon, Apr 17, 2023 at 9:28 PM tim clapp <vi...@yahoo.com.invalid>
wrote:
>
> I'd like to create a restful endpoint, in the fashion described here
> https://tomee.apache.org/tomee-8.0/examples/simple-rest.html, in a
> programmatic way that is idiomatic to TomEE.
>
> For example, instead of annotating a method like this below, to bind the
> method to an http endpoint, I'd like to be able to programmatically create
> the binding....
>
> @PUT
> @Path("orders/invoice/{id}")
> @Produces({MediaType.APPLICATION_XML})
> @Lock(LockType.READ)
> public Response DoSomething()
> { ... }
>
>
> Is such a thing possible ?
>
> How do I tie into the underlying objects TomEE manages so that I can
> "register" a new http endpoint in the same sort of fashion as I do above
> via annotations ?
>
>
> -----------------------package com.bigfancy;
>
>
> @Startup
> @Singleton
> @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
> @Lock(LockType.READ)
> public class PublicAPI {
> private static final Logger LOG =
> LogManager.getLogger(PublicAPI.class);
> private static final Marker GMARKER =
> MarkerManager.getMarker("public-api");
>
> @Context UriInfo uriInfo;
> @Context HttpHeaders httpHeaders;
> @Context Request request;
> @Context SecurityContext securityContext;
> @Context Providers providers;
> @Context HttpServletRequest httpServletRequest;
> @Resource SessionContext sessionContext;
>
>
>
>
> public PublicAPI() {
> super();
> LOG.info("constructing public api");
> }
>
>
> @PostConstruct
> public void init() {
> // instead of defining the orders(..) method below....
> // programmatically create the binding here...
> }
>
> @Destroy
> public void destroy() {
> LOG.info("destroying public api");
> }
>
> @POST
> @Path("orders/invoice/{id}")
> @Consumes({MediaType.WILDCARD})
> @Produces({MediaType.WILDCARD})
> public Response orders(
> @HeaderParam("xyz")
> @Required(true)
> final String xyz
> )
> {
> return null
> }
> }
>
--
Jonathan | exabrial@gmail.com
Pessimists, see a jar as half empty. Optimists, in contrast, see it as half
full.
Engineers, of course, understand the glass is twice as big as it needs to
be.