Last posts were about making a RESTFul service and run it on Jersey with an embedded Jetty.
This time I will set up a more Java EE like solution with the same REST Resource, but instead run it on an embedded Glassfish (actually, I will go for Payara). I will take the same model as before. Next part I will also add a JSF 2.2 client to use the RESTful service.
I will create this as a maven multi module with a parent project and two subprojects. One will be a web-project and the other will be a "runner" for the embedded Glassfish. I will not use maven to run, but will create a class that will run the embedded Glassfish with the war-file from the other project.
As it is pretty easy I use NetBeans to create maven projects for me.
The structure will be like this:
- embgf
- task-web
- gf-runner
- pack-dist
task-web
To start with, instead of having to set up a Servlet on "/api" path, we will create a configuration class that extends JAX_RSs Application.
And this will be the class for the Task service.
The service will be available at [http://localhost:2001/task-web/api/tasks] (depending what you use as port and contextRoot)
Just to have some Tasks to start with since we have a simple cache in a HashMap, we create a startup bean to create some.
The service will be available at [http://localhost:2001/task-web/api/tasks] (depending what you use as port and contextRoot)
Just to have some Tasks to start with since we have a simple cache in a HashMap, we create a startup bean to create some.
gf-runner
Embedded Payara
Trying to follow [http://www.payara.co.uk/using_payara_embedded_and_payara_micro_with_mav] I ran in to some issues. The dependency on that page does not really work, it end up with the following message:There is a bug-report on this. But to get on, I will download the jar and do a "quickie" and add it as a system dependency and get on.
The code to get up and running with the war-file from task-web on an embedded Payara is just a few lines:
pack-dist
As I am a bit lazy and want to avoid copy jars manually I created a pom-project just to copy dependencies. The needed jar file will end up in the root folders under ./dist/, I also added a bat file to start the embedded Payara with the following content:I also tried the jersey-client from the previous post with s slight modification for the context-path and it still works. (or you can start the payara with "/" as context path)
In next part I will add a JSF client on top of this service to show some nice stuff in Java EE 7 and JSF 2.2.
[The full project can be found at: https://bitbucket.org/pejomstd/embedded-gf-payara]
No comments:
Post a Comment