How to Configure Rewrite Handling

Goal

Use Datameer in a HTTP configuration behind a reverse proxy or load balancer to offload the SSL traffic or to use wildcard certificates.

Learn

Because Datameer comes with Jetty as embedded webservice, follow the documentation under Proxy / Load Balancer Connection Configuration and Rewrite Handler.

Here are the necessary steps in detail:

1. Enter your Datameer installation directory.
2. Shut down Datameer service using bin/conductor.sh stop.
3. To check the current configuration execute java -jar start.jar --list-config:

$ java -jar start.jar --list-config

Java Environment:
-----------------
 java.home = /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/jre
 java.vm.vendor = Oracle Corporation
 java.vm.version = 24.71-b01
 java.vm.name = Java HotSpot(TM) 64-Bit Server VM
 java.vm.info = mixed mode
 java.runtime.name = Java(TM) SE Runtime Environment
 java.runtime.version = 1.7.0_71-b14
 java.io.tmpdir = /var/folders/mf/kk3d6b7n1sd7py6jt7l5l0980000gn/T/
 user.dir = /Users/<user>/Development/Datameer/Datameer-<version>-<cluster-dist>
 user.language = de
 user.country = DE

Jetty Environment:
-----------------
 jetty.version = 9.2.3.v20140905
 jetty.home = /Users/<user>/Development/Datameer/Datameer-<version>-<cluster-dist>
 jetty.base = /Users/<user>/Development/Datameer/Datameer-<version>-<cluster-dist>

Config Search Order:
--------------------
 <command-line>
 ${jetty.base} -> /Users/<user>/Development/Datameer/Datameer-<version>-<cluster-dist>
 ${jetty.home} -> /Users/<user>/Development/Datameer/Datameer-<version>-<cluster-dist>


JVM Arguments:
--------------
 (no jvm args specified)

System Properties:
------------------
 (no system properties specified)

Properties:
-----------
 http.timeout = 30000
 jetty.dump.start = false
 jetty.dump.stop = false
 jetty.output.buffer.size = 32768
 jetty.port = 8080
 jetty.request.header.size = 8192
 jetty.response.header.size = 8192
 jetty.send.date.header = false
 jetty.send.server.version = false
 jsp-impl = apache
 threads.max = 200
 threads.min = 10
 threads.timeout = 60000

Jetty Server Classpath:
-----------------------
Version Information on 26 entries in the classpath.
Note: order presented here is how they would appear on the classpath.
      changes to the --module=name command line options will be reflected here.
 0:          9.2.3.v20140905 | ${jetty.base}/lib/apache-jsp/org.eclipse.jetty.apache-jsp-9.2.3.v20140905.jar
 1:   3.8.2.v20130121-145325 | ${jetty.base}/lib/apache-jsp/org.eclipse.jetty.orbit.org.eclipse.jdt.core-3.8.2.v20130121.jar
 2:                    8.0.9 | ${jetty.base}/lib/apache-jsp/org.mortbay.jasper.apache-el-8.0.9.M3.jar
 3:                      2.3 | ${jetty.base}/lib/apache-jsp/org.mortbay.jasper.apache-jsp-8.0.9.M3.jar
 4:                    1.2.1 | ${jetty.base}/lib/apache-jstl/org.apache.taglibs.taglibs-standard-impl-1.2.1.jar
 5:                    1.2.1 | ${jetty.base}/lib/apache-jstl/org.apache.taglibs.taglibs-standard-spec-1.2.1.jar
 6:                    3.1.0 | ${jetty.base}/lib/servlet-api-3.1.jar
 7:                 3.1.0.M0 | ${jetty.base}/lib/jetty-schemas-3.1.jar
 8:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-http-9.2.3.v20140905.jar
 9:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-server-9.2.3.v20140905.jar
10:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-xml-9.2.3.v20140905.jar
11:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-util-9.2.3.v20140905.jar
12:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-io-9.2.3.v20140905.jar
13:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-jndi-9.2.3.v20140905.jar
14:      1.4.1.v201005082020 | ${jetty.base}/lib/jndi/javax.mail.glassfish-1.4.1.v201005082020.jar
15:                      1.2 | ${jetty.base}/lib/jndi/javax.transaction-api-1.2.jar
16:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-security-9.2.3.v20140905.jar
17:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-servlet-9.2.3.v20140905.jar
18:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-servlets-9.2.3.v20140905.jar
19:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-webapp-9.2.3.v20140905.jar
20:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-deploy-9.2.3.v20140905.jar
21:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-plus-9.2.3.v20140905.jar
22:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-annotations-9.2.3.v20140905.jar
23:                    5.0.1 | ${jetty.base}/lib/annotations/asm-5.0.1.jar
24:                    5.0.1 | ${jetty.base}/lib/annotations/asm-commons-5.0.1.jar
25:                      1.2 | ${jetty.base}/lib/annotations/javax.annotation-api-1.2.jar

Jetty Active XMLs:
------------------
 ${jetty.base}/etc/jetty.xml
 ${jetty.base}/etc/jetty-http.xml
 ${jetty.base}/etc/jetty-deploy.xml
 ${jetty.base}/etc/jetty-plus.xml
 ${jetty.base}/etc/jetty-annotations.xml

4. In the section called Jetty Active XMLs (which doesn't contain the jetty-rewrite.xml per default), include the rewrite module via java -jar start.jar --add-to-start=rewrite.

$ java -jar start.jar --add-to-start=rewrite
INFO: rewrite         initialised in ${jetty.base}/start.ini (appended)
INFO: server          initialised in ${jetty.base}/start.ini
INFO: server          enabled in     ${jetty.base}/start.ini

5. Execute java -jar start.jar --list-config to verify if the module is loaded.

$ java -jar start.jar --list-config

Java Environment:
-----------------
 java.home = /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/jre
 java.vm.vendor = Oracle Corporation
 java.vm.version = 24.71-b01
 java.vm.name = Java HotSpot(TM) 64-Bit Server VM
 java.vm.info = mixed mode
 java.runtime.name = Java(TM) SE Runtime Environment
 java.runtime.version = 1.7.0_71-b14
 java.io.tmpdir = /var/folders/mf/kk3d6b7n1sd7py6jt7l5l0980000gn/T/
 user.dir = /Users/<user>/Development/Datameer/Datameer-<version>-<cluster-dist>
 user.language = de
 user.country = DE

Jetty Environment:
-----------------
 jetty.version = 9.2.3.v20140905
 jetty.home = /Users/<user>/Development/Datameer/Datameer-<version>-<cluster-dist>
 jetty.base = /Users/<user>/Development/Datameer/Datameer-<version>-<cluster-dist>

Config Search Order:
--------------------
 <command-line>
 ${jetty.base} -> /Users/<user>/Development/Datameer/Datameer-<version>-<cluster-dist>
 ${jetty.home} -> /Users/<user>/Development/Datameer/Datameer-<version>-<cluster-dist>


JVM Arguments:
--------------
 (no jvm args specified)

System Properties:
------------------
 (no system properties specified)

Properties:
-----------
 http.timeout = 30000
 jetty.dump.start = false
 jetty.dump.stop = false
 jetty.output.buffer.size = 32768
 jetty.port = 8080
 jetty.request.header.size = 8192
 jetty.response.header.size = 8192
 jetty.send.date.header = false
 jetty.send.server.version = false
 jsp-impl = apache
 threads.max = 200
 threads.min = 10
 threads.timeout = 60000

Jetty Server Classpath:
-----------------------
Version Information on 27 entries in the classpath.
Note: order presented here is how they would appear on the classpath.
      changes to the --module=name command line options will be reflected here.
 0:          9.2.3.v20140905 | ${jetty.base}/lib/apache-jsp/org.eclipse.jetty.apache-jsp-9.2.3.v20140905.jar
 1:   3.8.2.v20130121-145325 | ${jetty.base}/lib/apache-jsp/org.eclipse.jetty.orbit.org.eclipse.jdt.core-3.8.2.v20130121.jar
 2:                    8.0.9 | ${jetty.base}/lib/apache-jsp/org.mortbay.jasper.apache-el-8.0.9.M3.jar
 3:                      2.3 | ${jetty.base}/lib/apache-jsp/org.mortbay.jasper.apache-jsp-8.0.9.M3.jar
 4:                    1.2.1 | ${jetty.base}/lib/apache-jstl/org.apache.taglibs.taglibs-standard-impl-1.2.1.jar
 5:                    1.2.1 | ${jetty.base}/lib/apache-jstl/org.apache.taglibs.taglibs-standard-spec-1.2.1.jar
 6:                    3.1.0 | ${jetty.base}/lib/servlet-api-3.1.jar
 7:                 3.1.0.M0 | ${jetty.base}/lib/jetty-schemas-3.1.jar
 8:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-http-9.2.3.v20140905.jar
 9:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-server-9.2.3.v20140905.jar
10:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-xml-9.2.3.v20140905.jar
11:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-util-9.2.3.v20140905.jar
12:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-io-9.2.3.v20140905.jar
13:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-jndi-9.2.3.v20140905.jar
14:      1.4.1.v201005082020 | ${jetty.base}/lib/jndi/javax.mail.glassfish-1.4.1.v201005082020.jar
15:                      1.2 | ${jetty.base}/lib/jndi/javax.transaction-api-1.2.jar
16:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-rewrite-9.2.3.v20140905.jar
17:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-security-9.2.3.v20140905.jar
18:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-servlet-9.2.3.v20140905.jar
19:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-servlets-9.2.3.v20140905.jar
20:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-webapp-9.2.3.v20140905.jar
21:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-deploy-9.2.3.v20140905.jar
22:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-plus-9.2.3.v20140905.jar
23:          9.2.3.v20140905 | ${jetty.base}/lib/jetty-annotations-9.2.3.v20140905.jar
24:                    5.0.1 | ${jetty.base}/lib/annotations/asm-5.0.1.jar
25:                    5.0.1 | ${jetty.base}/lib/annotations/asm-commons-5.0.1.jar
26:                      1.2 | ${jetty.base}/lib/annotations/javax.annotation-api-1.2.jar

Jetty Active XMLs:
------------------
 ${jetty.base}/etc/jetty.xml
 ${jetty.base}/etc/jetty-http.xml
 ${jetty.base}/etc/jetty-rewrite.xml
 ${jetty.base}/etc/jetty-deploy.xml
 ${jetty.base}/etc/jetty-plus.xml
 ${jetty.base}/etc/jetty-annotations.xml

6. Edit the file etc/jetty.xml and uncomment the ForwardedRequestCustomizer.
7. Edit etc/jetty-rewrite.xml and add the following rewrite rule:

<Ref refid="Rewrite">
      <Call name="addRule">
        <Arg>
          <New class="org.eclipse.jetty.rewrite.handler.ForwardedSchemeHeaderRule">
            <Set name="header">X-Forwarded-Proto</Set>
            <Set name="headerValue">https</Set>
            <Set name="scheme">https</Set>
          </New>
        </Arg>
      </Call>
 </Ref>

8. Edit conf/default.properties and define the port to redirect the call to in port.mapping.https.
9. Start Datameer service by using bin/conductor.sh start.
10. Test the correct redirection using curl --verbose --header "X-Forwarded-Proto: https" 'http://localhost:8080'.

* Adding handle: conn: 0x7ffd42003a00
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7ffd42003a00) send_pipe: 1, recv_pipe: 0
* About to connect() to localhost port 8080 (#0)
*   Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.30.0
> Host: localhost:8080
> Accept: */*
> X-Forwarded-Proto: https
>
< HTTP/1.1 302 Found
< X-Frame-Options: SAMEORIGIN
< Set-Cookie: DAPSESSIONID=<id>;Path=/;Secure;HttpOnly
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
< Location: https://localhost:8443/login
< Content-Length: 0
<
* Connection #0 to host localhost left intact

Further Information

You will find further information under Managing Startup Modules.