I have recently become aware of Confluence's servlet-filter module. However, after trying to get it to work, I have run into a dead end. I am getting my information here:
Here is what I tried. I annotated my atlassian-plugin.xml file like so:
<servlet-filter name="My Test Filter" key="OURAPP" class="com.test.filters.HelloWorldFilter" location="after-encoding" weight="100"> <description>Forwards you to a test "Hello, world!" page.</description> <url-pattern>/helloworld</url-pattern> <dispatcher>REQUEST</dispatcher </servlet-filter>
Then, I created a standard Java servlet (extends HttpServlet, etc.) at com/test/filters called HelloWorldFilter.java. In the "doGet()" method, I simply have a System.out.println() line that reads "IN THE FILTER". However, when I go to the following URLs, I always get the "Page Not Found" error page:
http://127.0.0.1:8090/helloworld
http://127.0.0.1:8090/OURAPP/helloworld
http://127.0.0.1:8090/plugins/OURAPP/helloworld
http://127.0.0.1:8090/rest/helloworld
http://127.0.0.1:8090/rest/OURAPP/helloworld
http://127.0.0.1:8090/OURAPP/rest/helloworld
We have a custom Confluence plugin, lets call it OURAPP, that is serving up data not only through the browser GUI, but also through Confluence's REST capabilities. I am trying to create a filter that manages valid and invalid requests alike. We can access the REST at:
http://127.0.0.1:8090/rest/reststuff/v1/some_function_here
Like I said in the beginning, I have run into a dead end here, and cannot figure out how to get this to work. Can anybody offer up any suggestions or example code of how to get this working?
Thanks, and have a great day.
Community moderators have prevented the ability to post new answers.
Brian, I think you are mixing servlets and servlet filters!
In your example, you created a filter that maps to the "/helloworld" pattern. Fine, but there is no servlet that would respond to that URL, that's why you get a 404 (page not found). You should either create both a servlet-filter and a servlet (both declared in the plugin descriptor) and filter the same URL with the servlet-filter and handle the same URL by the servlet.
Ultimately, this is not what you want.
If you know the REST URL of your app, why don't you use that URL in the servlet-filter's configuration? (Tip: you can use wildcards.)
@Ferenc Kiss [Midori] What we have are a bunch of REST endpoints (e.g., /getalleuropeancars, /getalljapanesecars, /getallamericancars). We want to send an error message should anybody hit the service with PUT, DELETE, etc. We don't want every class to have the same error checking. Is a servlet filter what we are looking for? It seems we are talking apples and oranges (servlet filters and REST APIs).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.