0

I am developing a simple application that exposes a RESTful interface via Jersey + grizzly2 (from maven archetype). Now I want to add a module to the application that will also start a normal web server that will serve webpages. I would assume that Grizzly2 could be used for that too since RESTful endpoints are HTTP enpoints as well. However it seems grizzly2 does not support Velocity templates which is my preference for this module.

So can you please suggest should I go with Jetty or some other web server? What could be the negative consequences of having 2 different embedded web servers in one application?

Alex
  • 459
  • 4
  • 16
  • Just curious, but what makes you say it's not supported? – Paul Samsotha Jul 18 '16 at 14:54
  • when I type in "grizzly2 velocity" in google it returns only 16k results most of which look like references to some repos. Hence my assumption is that it's either not supported or it is unpractical to such a degree that no one bothered to implement/document it. – Alex Jul 18 '16 at 15:12
  • Ive never used velocity, but briefly looking at the documentation, it looks like the processing engine can be run as a servlet. Grizzly can definitely run as a servlet container, so I don't see why it wouldn't work. You could even run it on the same instance as you jersey app, but you can't use the factory method jersey provides to create the server as it only supports creating on servlet so you just need to use the core grizzly APIs to create the server. – Paul Samsotha Jul 18 '16 at 15:24
  • Take a look at the source for [`GrizzlyWebContainerFactory`](https://github.com/jersey/jersey/blob/master/containers/grizzly2-servlet/src/main/java/org/glassfish/jersey/grizzly2/servlet/GrizzlyWebContainerFactory.java#L244). You create servlet with `SerlvetRegistration`s – Paul Samsotha Jul 18 '16 at 15:28
  • Thank you. I will give it a shot at a later development stage. For now I chose to run Java Spark alongside jersey+grizzly2. I've used Java Spark in my previous projects and it's extremely easy to setup and run. For now it should do. I will consider switching to a single web server when performance will come into play. – Alex Jul 19 '16 at 06:16
  • You may possibly want to try out an Undertow stack as shown [here](https://www.stubbornjava.com/guides/embedded-java-web-server). The tutorial shows an example of using the Undertow lightweight http server with a Handlebars templating engine, so in principle, you should be able to have it running with velocity as well. Although, from [here](https://stackoverflow.com/questions/1459426/velocity-vs-freemarker) you can see that Velocity is no longer continued, so you may want to think of a new rendering engine (perhaps apache freemarker) – dragos.triteanu Jul 03 '18 at 20:53

0 Answers0