Access EJB from JAX-RS - rest

While Developing a Java EE Web app, I would like to know simple ways to access an stateless EJB object through Rest.
This project needs no Dynamic Web from Java, as Client side is fully javascript deployed, so communication is done only with Ajax calls.
As I've read one way would be to create 2 EJB one for functionality other to represent Web Service.
Is there a way to avoid the Web Service part? (avoid completely the WAR) Maybe with DI?
Java EE 6, EJB 3.1, Eclipse desired. I also believe the right application server would be Glassfish instead of Jboss, due to it's compatibility with EJB 3.0
No interesting in using JAX-WS

With EJB 3.1 you can actually publish a session bean as a JAX-RS web service, if you package your (properly annotated) session bean inside a WAR.
So, the simplest solution I can think of would be to create a WAR (a dynamic web app if you're using Eclipse) and create a JAX-RS annotated stateless session bean inside the web app. You don't need any EJB projects at all.

Not really. In Java EE 6 you can directly publish a Session Bean as a JAX-WS web service, but not as a JAX-RS web service. You're pretty much stuck with creating a WAR that hosts that JAX-RS services that front the EJBs themselves.

Related

Tomcat restful web service database (JPA) with Netbeans does not work

I have been able to create Restful web services with JAX-RS for Tomcat. Using the Netbeans Restful web service from patterns wizard.
But I am not able to create Restfull web servicer from database with Netbeans wizard.
It miss some libraries. I add openJPA and Java EE web api 6 (over the added by the wizard). But it continues not working.
I added javaEE-TomEE 8.0 but did not work, either!
Does anybody know what have I to add to Tomcat to get JPA-Database Restful service working?
Moving to GlassFish is not an answer valid... I want to keep on Tomcat (adding the minimal)
I have made some advances...
With EclipseLink(JPA 2.0) I was able to connect MySQL in a desktop application...
Then I switched to Apache OpenJPA and I was no able to get an EntityManagerFactory...
So it seems I choose a library incomplete...
I imagine, in Tomcat, I have to choose other library than OpenJPA.

Provide SOAP Interface with payara micro

payara micro doesn't provide a JAX-WS stack out of the box. Does anyone know about a way to serve SOAP Interfaces with payara micro?
Payara Micro doesn't provide SOAP functionality out of the box yet. The only option currently is to use a library that can help you, such as Apache CXF or Metro. You can either bundle the library into your app or bundle it into a custom Payara Micro JAR with the --addJars and --outputUberJar options.
It's essentially the same thing you would need to do with plain servlet containers like Tomcat, Jetty; or with Java EE Web Profile-only containers like TomEE, because none of them contains the SOAP functionality out of the box.

Is it possible to have Web & JPA & EJB in 1 project in Eclipse?

I just finished a tutorial which was done in NetBeans. The tutorial created only 1 project which was a Web Application Project under Java Web category. The tutorial has 1 entity using JPA annotations, 1 Stateless Session EJB using JPA annotations, 1 Servlet calling the EJB, and 1 JSP calling the Servlet. So basically this 1 project has all 3 items: Web & JPA & EJB.
How can I have such a project in Eclipse?
When I work on Eclipse I get confused about how many projects I would need for a web application which uses JPA and EJB.
Should I create 3 projects 1 each for Web & JPA & EJB? OR
Should I create 2 projects 1 each for Web & EJB and include JPA in both?
Just create the "Dynamic Web Project" right away with a minimum version of 3.0.
Since Java EE 6 ("Web Profile") you indeed don't necessarily need to create a separate project for EJBs. You can then use a subset of the EJB API in the WAR, also known as "EJB Lite". You can then easily create a single no-interface EJB class with just a state annotation (Stateless, #Stateful or #Singleton) and you're already there.
You don't need the EJB facet for a "Dynamic Web Project". EJB Lite is basically already covered by the "Dynamic Web Project". There's not much IDE magic (wizards, code generators, etc) needed for EJBs anyway. You only need to make sure that the version is set to a minimum of 3.0 (from Servlet 3.0; part of Java EE 6), and that you set the target runtime to a real Java EE application server (even if it's only "Web Profile"), such as WildFly, TomEE, GlassFish, Liberty, etc and thus not a barebones servlet container like Tomcat or Jetty. This way the EJB annotations will be readily available in the project.
You don't even necessarily need to enable the JPA facet. You'll only miss the JPA-related wizards and code-generators under the project options. But you can just write all JPA-related code all by yourself and still get it to deploy. After all, an IDE is just like notepad, but then with millions of features trying to make you more comfortable while writing code. The project facets basically enable/disable the available project options/wizards/code-generators.

OSGi bundles as SOAP web services in a plugin architecture

I would like to expose OSGi bundles as SOAP web services or in other words publish web service endpoints which are provided by OSGi bundles.
The architectural model/idea is that there is a host web application which is a normal war file deployed on JBoss (5.1.0 GA) offering a SOAP web service interface (JAX-WS).This host application starts the OSGi framework embedded (via ServletContextListener - currently Equinox) and loads a number of OSGi bundles which function as plugins.
The plugin bundles have a dependency to the host application as part of the request processing is delegated to them via internally defined interfaces.At the same time the plugin bundles should also be able to contribute an own public SOAP web service interface (endpoint implementations and the respective WSDL files to be published and made available by the application server).
The first approach we followed was that the host web application deploys a dispatcher/proxy servlet which delegates the processing to the relevant endpoints provided by the OSGi bundles.
There is the servlet bridge solution in OSGi/Equinox (BridgeServlet/HTTPServiceServlet) which enables the programmatic registration of servlets (for ex. in BundleActivators of the plugin bundles) using the HTTP Service specification.
The problem is that I have SOAP-based web service endpoints and would need to be able to wrap them in a javax.servlet.Servlet implementation.
That's usually an interna of the WS stack implementations of Java EE 5 servers which follow the servlet–based web services approach (endpoints defined as servlets in web.xml) and internally use to install native endpoint servlets for web service endpoints.
I did not find such a public endpoint servlet implementation which could be registered with the HTTP Service (maybe something similar like com.sun.jersey.spi.container.servlet.ServletContainer which can be used to publish REST-based services for JAX-RS applications in OSGi)
I am a little surprised that I did not find as much about registering SOAP-based WS endpoints with the OSGi HTTP Service or may be I do not see the obvious.
I have found something similar, JAX-WS-Commons/Spring (spring support for configuring JAX-WS, http://jax-ws-commons.java.net/spring/), which internally uses the class WSServletDelegate of the JAX-WS RI (metro) to process web requests for the endpoints.
But I am not sure about it, it seems kind of deprecated and I need to provide the metro WS stack jars to JBoss (or in the war file) in order to make it work on JBoss 5.1.0 GA.
Another approach seems to be distributed OSGI, which allows to publish OSGi services for remote access.
However, I could not find clear information about how to provide these services as web services on JBoss.
Other realisation aspects are:
we are bound to JBoss 5.1.0 GA and changes to the JBoss configuration should be as minimal as possible (in order to have minimal constraints to the setup of our customers)
All web services are developed contract-first which means that the original WSDL's are to be used by the providing container.
the plugin components should be as simple as possible concerning dependencies or technologies (in order to have minimal requirements to the skill of the plugin developers)
we use Spring 3 and Gemini Blueprint.
Finally, there are some ambiguities and unclear aspects and unfortunately I could not find reports on projects with similar requirements.
So, I would be eager to hear some suggestions or comments of the experts.
Maybe there are options I don't see, or maybe somebody has realised similar projects before and likes to share experiences.
Thanks a lot.
I am not an expert but another approach I have seen is to put the whole app server with an application into the OSGi container. It is an option in Sling launchpad http://sling.apache.org/documentation/the-sling-engine/architecture.html#launchpad
HTH

Is it possible to expose an EJB project as a RESTful WS?

I have implemented a RESTful web service using jersey and deployed it on Tomcat, I have used DAO classes to manipulate database operations, entities to wrap database records. and did the processing in separate package. I want to make this system distributed using EJB. First of all would it be easy to do this change. or i need to rewrite things from scratch. Second, I still need to have the REST WS, so would it be possible to expose the EJB as a REST WS and how? would the REST WS be in the same EJB project or in a different one?
You can definitely do it as an EJB and REST WS. Upgrade your Tomcat install to TomEE Plus, then just add #Stateless or #Singleton to the existing REST service.
You won't need Jersey in there anymore as the Java EE version of Tomcat (TomEE) includes CXF for JAX-RS support.
This example is not well documented, but shows a functional application that combines both EJB and JAX-RS.
http://tomee.apache.org/examples-trunk/rest-on-ejb/README.html