Utility Servlets
This page describes some of the utility servlets that are available in deegree 2.
Contents
1. RedirectServlet
The redirect servlet can be used to redirect requests based on string matching/replacement. If a rule matches, the matching part will be replaced by some other string, and the result is used as new location. Let's have a look at an example configuration:
<?xml version="1.0"?>
<web-app>
<display-name>redirection</display-name>
<description>redirection</description>
<servlet>
<servlet-name>redirect</servlet-name>
<servlet-class>org.deegree.enterprise.servlet.RedirectServlet</servlet-class>
<init-param>
<param-name>defaultLocation</param-name>
<param-value>http://www.deegree.org</param-value>
</init-param>
<init-param>
<param-name>rule1</param-name>
<param-value>geoportal.myorg.com,realserver.myorg.com</param-value>
</init-param>
<init-param>
<param-name>rule2</param-name>
<param-value>172.16.0.3:8080,realserver.myorg.com</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>redirect</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
If no rule matches, the page http://www.deegree.org will be shown. The following requests:
http://geoportal.myorg.com/services?request=GetCapabilities&service=WMS and http://172.16.0.3:8080/services?request=GetCapabilities&service=WMS
will both be redirected to
http://realserver.myorg.com/services?request=GetCapabilities&service=WMS
Please note that simple String-matching is used. That means that a request like
http://redirection.deegree.org/query?site=geoportal.myorg.com
will be redirected to
http://redirection.deegree.org/query?site=realserver.myorg.com
Using a log4j logging level of debug will output all redirections that take place.
2. OWSSwitch servlet
The OWSSwitch servlet can be used to redirect between services based on rules on request parameters. As opposed to the redirect servlet, only the base service address is exchanged. The rules are also more expressive, as they can express constraints based on simple operators such as <, >, = etc.
Again, you can number your rules. Rules are sorted based on their name, not on the number, so rule2 would come after rule10 (if you have more than 10 rules, name them rule01, rule02 etc.).
The default address is used, if no rule matches.
Let's have a look at a rule. WIDTH >= 1000 http://localhost:8080/demowms/services means, that requests with a KVP parameter of WIDTH which is greater or equal than 1000 will redirect to http://localhost:8080/demowms/services.
Valid operators are >, >=, <, <= and =. Please note that = operates on string equality, while the others operate on numbers. So you cannot check for a numeric equality, 500.0 will not be equal to 500.
Here's a complete example on how to configure the servlet:
<?xml version="1.0"?>
<web-app>
<display-name>owsswitch</display-name>
<description>owsswitch</description>
<servlet>
<servlet-name>owsswitch</servlet-name>
<servlet-class>org.deegree.enterprise.servlet.OWSSwitch</servlet-class>
<init-param>
<param-name>defaultaddress</param-name>
<param-value>http://testing.deegree.org/deegree-wms/services</param-value>
</init-param>
<init-param>
<param-name>rule1</param-name>
<param-value>LAYERS = cite:BasicPolygons http://demo.deegree.org/deegree-wms/services</param-value>
</init-param>
<init-param>
<param-name>rule2</param-name>
<param-value>WIDTH >= 1000 http://localhost:8080/demowms/services</param-value>
</init-param>
<init-param>
<param-name>rule3</param-name>
<param-value>HEIGHT >= 1000 http://localhost:8080/demowms/services</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>owsswitch</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
The configuration redirects to testing.deegree.org. If only the cite:BasicPolygons layer is requested, demo.deegree.org will be used. If WIDTH or HEIGHT are 1000 or greater, localhost:8080 will be used.
To run the servlet, you'll need the deegree2.jar, the commons-logging.jar and the log4j-1.2.9.jar in your WEB-INF/lib folder.