It should have picked it up, going through the gateway.sh file, I don't see any place where ext folder is added to class path, can you open a BUG for this ?
as a workaround for this you can copy your jar into the lib folder and Knox should pick it up on the startup. Hopefully, this should help ! Best, Sandepe On Fri, Mar 15, 2019 at 5:37 AM Matteo Alessandroni <skylar...@apache.org> wrote: > Hi Sandeep, > > thank you for your answer! > Ok so I tried to change my project and adding a simple class like this: > > package com.test.ext; > > import java.io.IOException; > import java.net.URI; > import java.net.URISyntaxException; > import javax.servlet.http.HttpServletRequest; > import javax.servlet.http.HttpServletResponse; > import org.apache.knox.gateway.config.Configure; > import org.apache.knox.gateway.config.Default; > import org.apache.knox.gateway.dispatch.AbstractGatewayDispatch; > import org.slf4j.Logger; > import org.slf4j.LoggerFactory; > > public class MyDispatch extends AbstractGatewayDispatch { > > private static final Logger LOG = > LoggerFactory.getLogger(MyDispatch.class); > > @Override > public void destroy() { > LOG.debug("******* destroy()"); > } > > @Configure > protected void customMethod(@Default("Test") String test) { > LOG.debug("******* @Configure customMethod(): {}", test); > } > > @Override > public void doGet(URI url, HttpServletRequest request, > HttpServletResponse response) > throws IOException, URISyntaxException { > > LOG.debug("******* doGet() request: {}, {}", request.getMethod(), > new URI(request.getRequestURI())); > > super.doGet(url, request, response); > } > > } > > made the ".jar" and put in the "ext" folder. > Executed the REST request again: > > curl -i -k -u admin:admin-password -X GET ' > https://localhost:8443/gateway/sandbox/webhdfs/v1/?op=LISTSTATUS' > > and I expected to see some logs, e.g. from the "doGet()" method (I'm not > sure about the "@Configure" method, when should a method with that > annotation be executed?), but it seems it does not see the class. > So I tried to configure my topology to use the dispatch (as written on > [1]): > > <service> > <role>WEBHDFS</role> > <url>http://hadoop-namenode:50070/webhdfs</url> > > <dispatch> > <classname>com.test.ext.MyDispatch</classname> > <use-two-way-ssl>false</use-two-way-ssl> > </dispatch> > </service> > > and after saving logs say: > > ERROR knox.gateway (GatewayFilter.java:doFilter(170)) - Gateway processing > failed: javax.servlet.ServletException: > org.apache.shiro.subject.ExecutionException: > java.security.PrivilegedActionException: javax.servlet.ServletException: > javax.servlet.ServletException: java.lang.ClassNotFoundException: > com.test.ext.MyDispatch > javax.servlet.ServletException: > org.apache.shiro.subject.ExecutionException: > java.security.PrivilegedActionException: javax.servlet.ServletException: > javax.servlet.ServletException: *java.lang.ClassNotFoundException: > com.test.ext.MyDispatch* > > so it's not seeing my class. > What am I missing? > > Thank you! > > Matteo > > > [1] https://knox.apache.org/books/knox-1-3-0/dev-guide.html#service.xml > > > On 14/03/19 20:47, Sandeep Moré wrote: > > 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 <skylar...@apache.org> > 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 >> >> >> >