Skip to content

Commit

Permalink
web - externalize the configuration of dsmiley's proxy servlets
Browse files Browse the repository at this point in the history
  • Loading branch information
pmauduit committed Jul 21, 2021
1 parent 462b2f5 commit dcc7507
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 4 deletions.
5 changes: 5 additions & 0 deletions docker/config/geonetwork/geonetwork.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# TODO: still in a WIP state, to be merged with config-geonetwork-georchestra.properties from the classpath

es.featureproxy.targeturi=http://localhost:9200/gn-features/{_}
kb.url=http://kibana:5601

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.fao.geonet.proxy;

import org.apache.http.client.utils.URIUtils;

import javax.servlet.ServletException;
import java.net.URI;

public class ConfigurableProxyServlet extends org.mitre.dsmiley.httpproxy.ProxyServlet {
@Override
protected void initTarget() throws ServletException {
String propName = getConfigParam(P_TARGET_URI);
targetUri = GeorchestraPropertyResolver.resolveProperty(propName);
// checks this is a valid uri
try {
targetUriObj = new URI(targetUri);
} catch (Exception e) {
throw new ServletException("Trying to process targetUri init parameter: "+e,e);
}
targetHost = URIUtils.extractHost(targetUriObj);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.fao.geonet.proxy;

import javax.servlet.ServletException;

public class ConfigurableUriTemplateProxyServlet extends org.mitre.dsmiley.httpproxy.URITemplateProxyServlet {
@Override
protected void initTarget() throws ServletException {
String propName = getConfigParam(P_TARGET_URI);
targetUriTemplate = GeorchestraPropertyResolver.resolveProperty(propName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.fao.geonet.proxy;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.file.Paths;
import java.util.Properties;

/**
* This class allows to resolve variables from the georchestra.datadir/geonetwork/geonetwork.properties
* file at runtime.
*
* Using servlets from dsmiley.httproxy group does not allow to easily configure them outside of
* the web.xml. This class provides a static method to do so, which is called from the 2 other
* classes from the package which extend the ones from dsmiley's package.
*
* @see {org.fao.geonet.ConfigurableProxyServlet} and {org.fao.geonet.ConfigurableUriTemplateProxyServlet}.
*/
public class GeorchestraPropertyResolver {

public static String resolveProperty(String name) {
File props = Paths.get(System.getProperty("georchestra.datadir"),
"geonetwork", "geonetwork.properties").toFile();
if (! props.exists() || ! props.canRead()) {
throw new RuntimeException("unable to load geonetwork.properties from the geOrchestra datadir");
}
Properties gnProps = new Properties();

try(InputStream fis = new FileInputStream(props)) {
gnProps.load(fis);
} catch (Exception ex) {
throw new RuntimeException("unable to read geonetwork.properties from the geOrchestra datadir");
}
return gnProps.getProperty(name);
}
}
8 changes: 4 additions & 4 deletions web/src/main/webResources/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,10 @@
-->
<servlet>
<servlet-name>ESFeaturesProxy</servlet-name>
<servlet-class>org.mitre.dsmiley.httpproxy.URITemplateProxyServlet</servlet-class>
<servlet-class>org.fao.geonet.proxy.ConfigurableUriTemplateProxyServlet</servlet-class>
<init-param>
<param-name>targetUri</param-name>
<param-value>${es.url}/${es.index.features}/{_}</param-value>
<param-value>es.featureproxy.targeturi</param-value>
</init-param>
<init-param>
<param-name>log</param-name>
Expand All @@ -422,10 +422,10 @@

<servlet>
<servlet-name>HttpDashboardProxy</servlet-name>
<servlet-class>org.mitre.dsmiley.httpproxy.ProxyServlet</servlet-class>
<servlet-class>org.fao.geonet.proxy.ConfigurableProxyServlet</servlet-class>
<init-param>
<param-name>targetUri</param-name>
<param-value>${kb.url}</param-value>
<param-value>kb.url</param-value>
</init-param>
<init-param>
<param-name>log</param-name>
Expand Down

0 comments on commit dcc7507

Please sign in to comment.