1

I have a working web-application that I built, successfully deployed to Heroku, and is functioning well. However, I'm trying to tune the server/servlet config, and that's when I realized that I don't know what my application is actually doing.

For glassfish, this is the config that's needed.

However, for Jetty, this is the config that's needed.

I realized I have no idea which of the above my application is actually using, so I started digging in my code and found the following:

The main method being called by Heroku is instantiating the following Jetty server/webappcontext.

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;

However, the jetty config seems to rely on a number of files (such as etc/jetty.xml, webapps folder or war files) which my project does not have at all.

In addition, my web.xml file defines the following servlet:

<servlet>
    <servlet-name>Jersey Web Application</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>

The fact that my application is defining a Jetty server but Glassfish servlet concerned me quite a bit. In an effort to standardize everything around Jetty, I tried adding the jetty servlet to my pom.xml dependencies and changed the above to:

<servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>

However, this change caused my application to break. It still compiles successfully and all my jerset-test based integration tests still succeed locally. But when I actually run the server, none of the routes work.

Some questions:

  1. Is it a ill-advised to use a Jetty server along with a Glassfish servlet (container)?

  2. If yes, what servlet (container?) should I replace Glassfish with, and what do I need to do to get the new Jetty servlet working?

  3. If no, what config should I be using for my current setup? Should I be implementing the Glassfish config or the Jersey config?

I've spent many hours trying to read through various documentations, tutorials and stack-overflow threads, but they all either assume prior knowledge about servlets, JavaEE and related topics (none of which I'm familiar with), or they are oriented towards building brand new hello-world apps from scratch (as opposed to porting an existing working app over, which is what I'm trying to do). Any explanations you could give, without assuming prior knowledge, relevant to the context described above, would be much appreciated.


Edit: I think I'm starting to understand now that a Servlet is the code that generates the response for a request, and the ServletContainer is what provides the infrastructure for the Servlet. I've never had to deal with Servlets directly in building my web-app. Here's an example of what a route looks like in my app:

@Path(Ping.REST_PREFIX)
public class Ping {
    static final String REST_PREFIX = "/ping";

    @GET
    public static Response get(@DefaultValue("getPing") @QueryParam("param") String param) {
        return Response.ok().entity(param).build();
    }

    @Path("/pong")
    @GET
    public static Response getPong(@DefaultValue("getPong") @QueryParam("param") String param) {
        return Response.ok().entity(param).build();
    }
}

How can I port code like the above into a Jetty ServletContainer, without rewriting vast sections of my application?

RvPr
  • 1,074
  • 1
  • 9
  • 26

1 Answers1

1

You are not using a "Glassfish Servlet Container", you are using a "Jersey Servlet Container".

Jersey is the project you are using.

Glassfish was the umbrella organization (sometimes called "a forge") that helps manage/maintain the Jersey project (along with dozens of other projects).

Difference com.sun.jersey and org.glassfish.jersey

The Jersey project can now be found at the java.net organization.

https://jersey.java.net/

Community
  • 1
  • 1
Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136