0

I have a ProxyServlet (org.mitre.dsmiley.httpproxy) in my code which does some operations and forwards certain url's ending with */xyz to a different application. I have integration tests covering my application( using JerseyTest framework) and want to make the integration-tests pass through the proxy servlet.

Currently my test case deployment configuration is as below:

ServletDeploymentContext.forServlet(new ServletContainer(internalConfigureResourceConfig(resourceConfig))).build()

Now, to test my proxy-servlet, if I change the configuration as below,

ServletDeploymentContext.forServlet(MyProxyServlet.class).build()

I am not able to add the url-pattern servlet-mapping above and the proxy-servlet is being called for all the url's. Can someone tell me how can I add the url-mapping configuration dynamically for the

ServletDeploymentContext.forServlet

I have checked all the methods but unable to do so

  • 1
    Does the servletPath() method work? – Paul Samsotha May 07 '21 at 16:34
  • I tried that earlier but did not work. I checked the source code of `instantiateGrizzlyWebServer()` method and ideally adding servletPath() should add the urlMapping but even if I add some random text like `/sandsand/*` the servlet is being called for all the requests. Not sure if I am doing any wrong – Somtirtha Ghosh May 15 '21 at 15:51
  • I highly suggest using a filter instead of a servlet. A filter better fits the use case. – Paul Samsotha May 15 '21 at 19:50
  • @PaulSamsotha unfortunately I cant. This servlet has some crucial business logic to process data once response comes and moving that is a lot of effort in a large application like ours. Can you please tell if there is any other way to add the urlMapping for this servlet? – Somtirtha Ghosh May 16 '21 at 05:47
  • Not sure if this will do anything but there’s an option to override getBaseUri() in the JerseyTest class – Paul Samsotha May 16 '21 at 07:33

1 Answers1

0

I have understood where I went wrong. When I add below statement, ServletDeploymentContext.forServlet(MyProxyServlet.class).build() I am adding MyProxyServlet as the only "default" servlet and hence even if I add servletPath() as the url-mapping it did not work as that was the only servlet present. So every request was sent to the servlet even if mapping criteria is not satisfied. When I add another servlet with servletPath as /* then all other requests went to other servlet and the required requests came to my MyProxyServlet