Add jetty servlet into dropwizard

fengye87 picture fengye87 · Apr 23, 2014 · Viewed 7.8k times · Source

I need to add jetty servlet into my already existing server implemented using dropwizard framework.

To be more specific:

  1. I have a restful resource Foo mapped to url "localhost:8080/foo" with CRUD operations.
  2. Now I need a jetty servlet mapped to url "localhost:8080/bar" and handles all requests to this url (mainly GET and POST).

I could not get a clue how to do this after some googlings. Could someone please give me a direction or a snippet? Thanks!

Answer

condit picture condit · Apr 23, 2014

If you're using Dropwizard 0.6.2 you should be able to do something like this in your run method:

ServletBuilder builder = environment.addServlet(myServlet, "/bar");

If you're using Dropwizard 0.7.0 try this:

environment.getApplicationContext().addServlet("org.example.MyServlet", "/bar");