0

I've recently read an article regarding Dropwizard performance: https://nbsoftsolutions.com/blog/turning-dropwizard-performance-up-to-eleven.html

i've tried to convert a demo code i have to this configuration but without success. i'm having problems regarding getting attributes from request this is my code (main application):

    environment.getObjectMapper();
    final MyResource resource = new MyResource();
    ServletContextHandler handler = new ServletContextHandler();
    handler.setContextPath("/test/{test}");
    final TestGetJsonServlet servlet = new TestGetJsonServlet(environment.getObjectMapper().getFactory());
    environment.getApplicationContext().addServlet(new ServletHolder(servlet), "/test/*");
    final FilterHolder holder = new FilterHolder(SimpleFilter.class);
    environment.getApplicationContext().addFilter(holder, "/test*", EnumSet.allOf(DispatcherType.class));
    environment.jersey().register(resource);
    environment.jersey().register(JerseyFilter.class);

How do I configure it correctly to read also attributes?

Another small question is regarding filters. I want a filter for the specific servlet, how do I make it in the configuration? or even more specific, let's say I have doGet and doPost in my servlet, I want the filter to work only on the doPost, what do I need to change in my application's run method.

thanks for your help!

cello
  • 5,356
  • 3
  • 23
  • 28
Itzik Lavon
  • 39
  • 1
  • 4
  • The blog post example you are taking about doesn't use Jersey - but you are in your code snippet - did you mean to register a resource class (`MyResource`) also? Can't you edit the post to show only the code you are asking about? – Phil Jul 08 '17 at 15:32
  • I don't understand your question about servlet attributes. What are you trying to do? Attributes are available in the servlet context or on individual request objects. Can you explain more and share more code about your specific servlet and how you want to use attributes? – Phil Jul 08 '17 at 15:34
  • Hi, thanks for your comment, i wanted to check the blog results, so i've registered one JERSEY resource, and the rest i tried doing with http servlets, my form of http request is like this: http://localhost:8080/test/tst. as the tst should be just an attrubiute(i want to be able to put any string over there). I've tried to register a servlet to the environment that receives an attribute in request, without any success. in JERSEY if i define the path as "/test/{test}" and extract pathparam then i will get the attribute i want, i want the same for http servlet. i hope that this is clearer thanks – Itzik Lavon Jul 08 '17 at 19:36
  • Possible duplicate of [Any way to get the path parameters in httpservlet request](https://stackoverflow.com/questions/22199830/any-way-to-get-the-path-parameters-in-httpservlet-request) – Phil Jul 10 '17 at 02:57
  • Ah that does help: these other posts imply that it isn't possible unless you parse the path yourself: https://stackoverflow.com/questions/22199830/any-way-to-get-the-path-parameters-in-httpservlet-request https://stackoverflow.com/questions/8715474/servlet-and-path-parameters-like-xyz-value-test-how-to-map-in-web-xml Let me know if those don't answer your question. – Phil Jul 10 '17 at 02:58

0 Answers0