I am developing a web application using JSF 2.3. I need to create a Servlet which makes an HTTP connection to an URL and get a JSON object and process it. There are many third party APIs available for this sake, but I am more interested in using HttpClient which comes default in JDK11 onwards.
But the problem I face here is, I cannot use HttpClient without modularizing i.e. defining it as a requirement in module-info.java for my application. And, if I define module-info.java I can't get servlet classes reference resolved in my code. javax.* dependencies and other third party dependencies are not resolved. All the required libraries are present. So my question is
Q1. How can I use HttPClient in a Java web application with servlets, and JSF framework?
Q2. How do I resolve third party dependencies in a moduler java application?
I am using Payara server 5, JDK-11, RHEL 7.9
OpenShift offers the possibility to develop Spring based applications using JBoss EAP6. I am considering migrating a Spring application developed/deployed on Tomcat 7.
I have little experience with JBoss. Am I going to go through many troubles if I migrate my application? If yes which? Are Tomcat 7 and JBoss EAP6 compatible?
It depends entirely on your application.
The servlet container in JBoss 6 is based on Tomcat 6. If you are using any new features in Tomcat 7 (e.g. extensions in the Servlet 3.0 or JSP 2.2 spec), these will not run on JBoss 6.
The general response will be yes, JBoss will provide all the standard elments Tomcat does. But it is always possible to make it not compatible (using directly some tomcat class, JBoss Web use a different name space and there is no 1:1 corespondances).
I most cases you will need to make some litle addaptation (add some configuraiton and properties, change datasource name...).
JBoss AS7 documentation contains some Spring integration elements.
Some elments provided by default in JBoss may give you some trouble (like JPA), but if you have full controle on the application source, you should be able to get it working without lot of efforts.
Without inside on your application it will be difficult to give concreate effort estimate.
Java EE 6 provides a way to activate JAX-RS Application on startup.
The problem is I am (and certainly many of us are still) using web server not compliant to Java EE/Servlet 3.0 so that if we tried to use load-on-startup servlet mapping on a JAX-RS Application, the web server (at least that is the case for jetty) would croak
"class is not a servlet"
and hence refuse to load the Application.
The gist of the matter is - to load the contextresolver, the only way which can be done only is through the jax-rs Application subclass.
The method to activate Application subclass should work similarly both on Jetty and Tomcat/JBoss because I am using jetty for development (due to GWT - what else?) and Tomcat/JBoss for production. I wish to avoid writing different loaders for jetty and tomcat.
There are exist already implemented start up servlets and context listeners in jax-rs providers like cxf or resteasy, just read docs carefully
I've been going off of http://www.oracle.com/technetwork/articles/javase/index-137171.html and downloaded the files but I'm a little lost since I've never done this before.
I've installed Tomcat and Eclipse Java EE IDE but I don't know what kind of project to use to create a webservice and how to load and compile the code to the service.
Am I going about this the right way in using eclipse?
That article is old. Since then, the Java standards committee created a new API named JAX-RS (The REST counterpart to JAX-WS). Like JAX-WS, this is meant to standardize REST web service layers.
Its reference implementation is Jersey, which supports JAX-RS 0.8, 1.0, and 1.1.
I understand that Apache CXF has support for JAX-RS 0.8, but it is unclear about 1.0/1.1 support.
JBoss has RESTEasy. However, it is not immediately clear which versions of JAX-RS are supported by RESTEasy.
Another popular JAX-RS framework is Restlet. Unfortunately, I can't open their site from here to say which versions of JAX-RS they support.
Here is an REST (JAX-RS) example I put together. You will probably find part 4 the most helpful:
Part 1 - The Database
Part 2 - Mapping the Database to JPA Entities
Part 3 - Mapping JPA entities to XML (using JAXB)
Part 4 - The RESTful Service
Part 5 - The Client
If all you're creating is a lightweight RESTful service you can also look at GlassFish which provides a simple http server for REST.
You'll create a web project to deploy a web service of any kind. It'll be packaged in a WAR and deployed on Tomcat.
I read a lot about GlassFish application server that it supports the whole Java EE 6 specification. But which does Tomcat support?
I know that Tomcat is a JSP/Servlet container, but I see articles in web about "JSF and Tomcat", "Hibernate and Tomcat" and many more.
Can tomcat play with these technologies: EJB, JSF, JPA, Hibernate, Spring, etc..?
Tomcat as being a barebones servletcontainer provides indeed only JSP, Servlet, EL and WS APIs out the box. You can however just provide JSF, JSTL, CDI, JPA, Hibernate, Spring, etc yourself along with the web application in flavor of JAR file(s) in the /WEB-INF/lib folder and some configuration files where necessary.
EJB is only a story apart since you can't just add "some JARs" to get that to work, but in fact yes, you can put an EJB container on top of Tomcat too if you modify the server core. That's also basically what TomEE has done. You might as well consider it if your intent is to go Java EE.
See also:
What exactly is Java EE?
I read a lot about GlassFish application server that it supports the whole Java EE 6 specification. But which does Tomcat support?
Tomcat (which is not the RI of the Servlet spec anymore since Java EE 5) doesn't support any of the Java EE 6 APIs out of the box. In its latest version, Tomcat 6 ships with:
Servlet 2.5
JSP 2.1/EL 2.1
While the "web" part of GlassFish implements:
Java Servlet 3.0
JavaServer Faces 2.0
JavaServer Pages 2.2/Expression Language 2.2
Standard Tag Library for JavaServer Pages (JSTL) 1.2
Can tomcat play with these technologies: EJB, JSF, JPA, Hibernate, Spring, etc..?
You can use some of them by packaging them inside your application (this article has a nice summary):
EJB 3.1: no, there is no standalone EJB 3.1 container at the time of writing this (and if you consider using EJB, use a real Java EE server, Tomcat with a standalone EJB container is not an equivalent, especially from a Transaction Manager point of view).
JSF 2.0 and EL 2.2: yes, possible with some pain
CDI 1.0: yes, possible
Bean validation 1.0: yes possible with JSF 2.0 and JPA
JPA 2.0: yes, possible but you'll have to obtain the EntityManager yourself and to manage transaction yourself (or to use a third party container like Spring).
But let me insist: whatever you'll add to Tomcat, you won't get an equivalent of a Java EE 6 container, even if we just compare with a Web Profile implementation (like GlassFish v3 Web Profile): no EJB 3.1 Lite, no JTA 1.1, no descriptor-less applications, etc.
If you have the choice, my suggestion would to use GlassFish v3 Web Profile and to embrace Java EE 6.
Tomcat is not an EJB container, therefore you should use full blown JavaEE 6 server for that (such as Glassfish, Websphere, Weblogic, etc.).
Tomcat can use Spring/Hibernate as this only requires relevant jars and configs/context definitions. Same applies for JSF.
JPA is an abstract spec, and Hibernate (along others) is an implementation of this spec, therefore the answer is "yes, it can be implemented on Tomcat".
I found the table on the tomcat page helpful.
Page: http://tomcat.apache.org/whichversion.html
Tomcat supports depending on it's version:
JSTL 1.0 : Servlet 2.3 : JSP 1,2 (tomcat 4)
JSTL 1.1 : Servlet 2.4 : JSP 2.0 (tomcat 5)
JSTL 1.2 : Servlet 2.5 : JSP 2.1 (tomcat 6)
That tomcat offers no EJB support by default has already be answered.
EasyBeans covers this issue.
To include JSF 1.2 in tomcat6 there is a tutorial
EDIT:
Unfortunately there is no single dependency(/compatibility) matrix out there.
JPA is an API, which is implemented by i.g. Hibernate. It should not be hard to find out which versions match. And yes they can be used with Tomcat (besides) Spring.