-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
web - externalize the configuration of dsmiley's proxy servlets
- Loading branch information
Showing
5 changed files
with
77 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
21 changes: 21 additions & 0 deletions
21
web/src/main/java/org/fao/geonet/proxy/ConfigurableProxyServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
web/src/main/java/org/fao/geonet/proxy/ConfigurableUriTemplateProxyServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
web/src/main/java/org/fao/geonet/proxy/GeorchestraPropertyResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters