/**
 * Copyright (C) 2013  Christian Autermann, Jan Alexander Wirwahn,
 *                     Arne De Wall, Dustin Demuth, Saqib Rasheed
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package io.car.server.rest;

import com.google.common.collect.ImmutableMap;
import com.sun.jersey.api.core.PackagesResourceConfig;
import com.sun.jersey.api.core.ResourceConfig;
import com.sun.jersey.api.json.JSONConfiguration;
import com.sun.jersey.core.util.FeaturesAndProperties;
import com.sun.jersey.guice.JerseyServletModule;
import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;

import io.car.server.rest.auth.AuthenticationFilter;
import io.car.server.rest.auth.AuthenticationResourceFilterFactory;

/**
 * @author Christian Autermann <c.autermann@52north.org>
 */
public class RESTModule extends JerseyServletModule {

    @Override
    protected void configureServlets() {
        serve("/schema/*").with(SchemaServlet.class);
        serve("/rest*").with(GuiceContainer.class, ImmutableMap.<String, String>builder()
                .put(PackagesResourceConfig.PROPERTY_PACKAGES,
                     getClass().getPackage().getName())
                .put(ResourceConfig.FEATURE_DISABLE_WADL,
                     String.valueOf(true))
                .put(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS,
                     AuthenticationFilter.class.getName())
                .put(ResourceConfig.PROPERTY_RESOURCE_FILTER_FACTORIES,
                     AuthenticationResourceFilterFactory.class.getName())
                .put(FeaturesAndProperties.FEATURE_FORMATTED,
                     String.valueOf(true))
                .put(JSONConfiguration.FEATURE_POJO_MAPPING,
                     String.valueOf(false))
                .build());
    }
}

@@ -880,16 +880,86 @@
 bleMap;%0A
+import com.sun.jersey.api.container.filter.GZIPContentEncodingFilter;%0A
 import c
@@ -1513,16 +1513,138 @@
 Module %7B
+%0A    public static final String FALSE = String.valueOf(false);%0A    public static final String TRUE = String.valueOf(true);
 %0A%0A    @O
@@ -2012,16 +2012,22 @@
 LE_WADL,
+ TRUE)
 %0A       
@@ -2039,32 +2039,185 @@
     
-     String.valueOf(true
+.put(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS,%0A                     classList(AuthenticationFilter.class,%0A                               GZIPContentEncodingFilter.class
 ))%0A 
@@ -2264,37 +2264,38 @@
 RTY_CONTAINER_RE
-QUEST
+SPONSE
 _FILTERS,%0A      
@@ -2309,30 +2309,45 @@
         
-Authentication
+classList(GZIPContentEncoding
 Filter.c
@@ -2346,33 +2346,24 @@
 Filter.class
-.getName(
 ))%0A         
@@ -2446,16 +2446,26 @@
         
+classList(
 Authenti
@@ -2497,25 +2497,16 @@
 ry.class
-.getName(
 ))%0A     
@@ -2565,50 +2565,13 @@
 TED,
-%0A                     String.valueOf(true)
+ TRUE
 )%0A  
@@ -2628,16 +2628,23 @@
 MAPPING,
+ FALSE)
 %0A       
@@ -2656,35 +2656,262 @@
     
-     String.valueOf(false))
+.build());%0A    %7D%0A%0A    private String classList(Class%3C?%3E clazz, Class%3C?%3E... classes) %7B%0A        StringBuilder sb = new StringBuilder();%0A        sb.append(clazz.getName());%0A        for (Class%3C?%3E c : classes) %7B%0A            sb.append(%22,%22).append(c.getName());
 %0A   
@@ -2911,32 +2911,34 @@
 ));%0A        
+%7D%0A
         
 .build());%0A 
@@ -2921,31 +2921,42 @@
   %7D%0A        
-.build()
+return sb.toString(
 );%0A    %7D%0A%7D%0A

support for gzip content encoding