Webapp start and stop listener using jax-rs - jax-rs

I am using jax-rs for restful service. And I am trying to find out how I can use a contextlistener for webapp ? I am specifically using jax-rs 2.0 . Any suggestions on how to go about it , would be helpful. Thank you.

I'm not sure what linkage problem you have with servlet.jar. It should actually be in your classpath already, since JAX-RS uses it, too.
Also, if you use a framework such as Hibernate (or another JPA implementation for your MySQL database access), you may want to rely on the events that they trigger after insert/update/delete operations: see https://docs.jboss.org/hibernate/orm/4.0/manual/en-US/html/events.html for example.
Just my 2c.

Related

Wildfly migrate authentication to Elytron

I am trying to migrate wildfly authentication to elytron and got almost everything to work as i want except for one problem.
We are using quartz scheduler to run jobs. These jobs are not bound to a caller principle. Using
SecurityContextAssociation.pushRunAsIdentity(new RunAsIdentity("My_Role", "My_User"));
i was able propagate a princple to following EJB calls. This is not working anymore, the principle is always "anonymous". Is there a way to do the same with Elytron?
Maybe you can use some variation of following:
SecurityIdentity si = SecurityDomain.getCurrent().getCurrentSecurityIdentity();
si.createRunAsIdentity(...);
The current identity needs to have permissions for it to succeed, so if you'll get unauthorized exception you should add RunAsPrincipal permissions to that user: https://developer.jboss.org/people/fjuma/blog/2018/06/01/configuring-permissions-using-elytron-in-wildfly-13

How can I configure JAX-RS endpoints programmaticaly?

I'm trying to get rid of XML in my project.
I already tried to add this:
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(CustomerService.class);
sf.setAddress("http://localhost:9000/");
sf.create();
to my Activator class, but my bundle wont start with this.
So, how usually people configuring endpoints?
(Sorry, no code, just some high level insights from my experience/projects)
I use jersey and its integration into the OSGi environment. I.e. org.glassfish.jersey.servlet.ServletContainer to which I register all jax-rs resources. This way, I can use whatever HTTP server implementation is available (for example, jetty) and configure it via the OSGi system environment properties.
For simplicity, I re-register annotated OSGi (declarative) services as singleton resources/endpoints into that ServletContainer.
Maybe, CXF has also a similar approach.

How to use a CXF ResourceComparator with Openliberty

is it possible to use a CXF ResourceComparator in OpenLiberty or WASLiberty?
http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Customselectionbetweenmultipleresourcesoroperations
Must the cxf dependencies be supplied in the WEB-INF/lib or is enough to modify the apiVisibility of the app? And how can be declared to CXF? with a cxf.xml?
TIA
PacoG
There are multiple ways to use CXF in OpenLiberty/WebSphere Liberty:
* You can use the built-in jaxrs-2.0 feature, or
* You can package the CXF modules you need with your app (or in a shared library associated with your app)
If you use the first approach (jaxrs-2.0 feature), then you will only have the JAX-RS 2.0 APIs available - which does not include CXF ResourceComparators. There are a few IBM-specific APIs that go above and beyond the spec (for example, integration with CDI, security, attachment processing, etc.) - you can find more information on those APIs at:
https://www.ibm.com/support/knowledgecenter/en/SSEQTP_8.5.5/com.ibm.websphere.wlp.doc/ae/twlp_dep_jaxrs.html
If you use the second approach, then you have the full feature set of the CXF modules in your application, but they will not be fully integrated with other Liberty features like the jaxrs-2.0 feature is. For usage instructions, I would suggest the Apache CXF documentation - like the page you referenced in the initial question.
Hope this helps, Andy

Is restlet + simple combination suitable for production environment?

I have a processing application which accepts REST requests and doesn't include a GUI such as a web front-end. Processing is light but the number of requests is quite high (more than 10,000 requests in a second).
I wonder if Restlet + Simple combination is appropriate for this scenario or do I have to use a Java EE edition?
Does anyone have experience with Restlet + Simple combination?
In Restlet, you have the concept of server connectors. This means that you could choose the appropriate connector for your need in a JSE environment (edition jse). It's clear that the default connector isn't suitable for production (it was even not present within org.restlet in the last version 2.3). So you can choose to use the Jetty extension (simply put the extension org.restlet.ext.jetty in your classpath - no impact in your application code) to use it as transport. We use successfully this approach in production (with load balancy in front of this) for one of our application.
If you don't want to handle load balancing, ... by yourself, you could prefer to use an application server to let it handle this.
Hope it helps you,
Thierry

Adding custom operations to Admin console in jboss 7.1.1

I want to expose custom operations using jboss console. Like in jboss 4.2, we were using xmbeans to create our own interface & then invoke operations.
I found sample (https://docs.jboss.org/author/display/AS7/Example+subsystem) related to creating custom subsystem but that can be accessed using CLI only.However If its possible to expose the same set of operations and attributes in the web (admin) console?
If not, is there any plan for it?
Thanks for your help.
Best Regards,
Divya Garg