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 <[email protected]>
Sent: Tuesday, April 18, 2023 6:55 AM
To: [email protected]
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 
<[email protected]<mailto:[email protected]>>

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 | [email protected]<mailto:[email protected]>

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.

Reply via email to