Hello Matteo, I don't think this is a right way to add filters to Knox, if you want to add some custom logic between your Knox and the backend you can write custom dispatch [1] you can add this new jar in the ext folder and it should be picked up by Knox on start-up.
[1] https://knox.apache.org/books/knox-1-3-0/dev-guide.html#Custom+Dispatch+Dependency+Injection On Thu, Mar 14, 2019 at 12:52 PM Matteo Alessandroni <[email protected]> wrote: > Hi, > > I'm trying to add a filter on a Knox instance so that I'll be able to add > a custom logic to (every / specific) REST requests to Knox. > I thought to use the "Class Path" feature [1], so I created a Maven Java > project, generated a ".jar" file and placed it in the "$GATEWAY_HOME/ext" > folder > Then, I thought it was necessary to link my custom class [2] on the > "gateway.xml" files of the resources I wanted, e.g. > > ./data/deployments/sandbox.topo.16977ef2478/%2F/WEB-INF/gateway.xml > > added: > > <filter> > <role>rewrite</role> > <name>url-rewrite</name> > <class>com.test.knox.MyUrlRewriteServletFilter</class> > </filter> > > then I made a REST request to Knox: > > curl -i -k -u admin:admin-password -X GET ' > https://localhost:8443/gateway/sandbox/webhdfs/v1/?op=LISTSTATUS' > > but my filter is not called at all (I cannot see the log) and I'm not sure > whether it's because the class is not loaded or the filter is placed in the > wrong place or whatever. > > On [4] you can see the project I have built. > > So my questions are: > > - what am I doing wrong or missing? > - is there a better way to do that? I just need to add a logic when > executing REST requests to Knox and make another REST call to an external > service I need. > > > Thank you! > Regards, > Matteo > > [1] https://knox.apache.org/books/knox-1-2-0/dev-guide.html#Class+Path > [2] > https://github.com/mat-ale/apache-knox-filter/blob/master/src/main/java/com/plainid/ext/MyUrlRewriteServletFilter.java > [3] > [4] https://github.com/mat-ale/apache-knox-filter > > >
