Hi,
I tried also the "lib/" folder, but same problem.
About the configuration for classpath yes it should be correct because I
have the "bin/gateway.cfg" file containing:
#Created from jar:file:/knox-runtime/bin/gateway.jar!/META-INF/launcher.cfg
#Thu Mar 14 10:10:31 GMT 2019
GATEWAY_HOME=${launcher.dir}/..
log4j.configuration=${GATEWAY_HOME}/conf/${launcher.name}-log4j.properties
main.class=org.apache.knox.gateway.GatewayServer
class.path=../conf;../lib/*.jar;../dep/*.jar;../ext;../ext/*.jar
so it should load the ".jar" files in those folders.
Is there anything I can do to debug this?
FYI I'm using this Docker image [1] to run Knox and after adding files
to "ext/" or "lib/" I use this script [2] to restart Knox and it seems
to restart well, but still not seeing my classes in classpath.
Thanks
[1] https://github.com/moresandeep/knox-dev-docker
[2]
https://github.com/moresandeep/knox-dev-docker/blob/master/build/gateway.sh
On 15/03/19 14:56, Sandeep Moré wrote:
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
<[email protected] <mailto:[email protected]>> 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
<[email protected] <mailto:[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