package com.coding4people.mosquitoreport.api;

import java.io.IOException;
import java.net.URI;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.CommonProperties;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.jackson.internal.FilteringJacksonJaxbJsonProvider;
import org.glassfish.jersey.jackson.internal.JacksonFilteringFeature;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.jersey.message.filtering.EntityFilteringFeature;
import org.glassfish.jersey.server.ResourceConfig;

import com.coding4people.mosquitoreport.api.buckets.BucketBinder;
import com.coding4people.mosquitoreport.api.controllers.AuthEmailController;
import com.coding4people.mosquitoreport.api.controllers.FocusController;
import com.coding4people.mosquitoreport.api.controllers.PictureController;
import com.coding4people.mosquitoreport.api.controllers.PostFocusController;
import com.coding4people.mosquitoreport.api.controllers.ProfileController;
import com.coding4people.mosquitoreport.api.controllers.SignUpController;
import com.coding4people.mosquitoreport.api.controllers.ThumbsUpController;
import com.coding4people.mosquitoreport.api.exceptionmappers.BadRequestExceptionMapper;
import com.coding4people.mosquitoreport.api.exceptionmappers.ForbiddenExceptionMapper;
import com.coding4people.mosquitoreport.api.exceptionmappers.InternalServerErrorExceptionMapper;
import com.coding4people.mosquitoreport.api.exceptionmappers.JsonMappingExceptionMapper;
import com.coding4people.mosquitoreport.api.exceptionmappers.JsonParseExceptionMapper;
import com.coding4people.mosquitoreport.api.exceptionmappers.NotFoundExceptionMapper;
import com.coding4people.mosquitoreport.api.exceptionmappers.ValidationExceptionMapper;
import com.coding4people.mosquitoreport.api.factories.FactoryBinder;
import com.coding4people.mosquitoreport.api.filters.CORSFilter;
import com.coding4people.mosquitoreport.api.indexers.IndexerBinder;
import com.coding4people.mosquitoreport.api.repositories.RepositoryBinder;

public class Main {
    public static final String BASE_URI = "http://0.0.0.0:9000/";

    public static ResourceConfig createApp() {
        return commonConfig()
                // Controllers
                .register(AuthEmailController.class)
                .register(FocusController.class)
                .register(PictureController.class)
                .register(PostFocusController.class)
                .register(ProfileController.class)
                .register(SignUpController.class)
                .register(ThumbsUpController.class)
                
                // Exception mappers
                .register(BadRequestExceptionMapper.class)
                .register(ForbiddenExceptionMapper.class)
                .register(InternalServerErrorExceptionMapper.class)
                .register(JsonMappingExceptionMapper.class)
                .register(JsonParseExceptionMapper.class)
                .register(NotFoundExceptionMapper.class)
                .register(ValidationExceptionMapper.class)
                
                // Filters
                .register(CORSFilter.class)
                
                // Binders
                .register(new BucketBinder())
                .register(new FactoryBinder())
                .register(new IndexerBinder())
                .register(new RepositoryBinder());
    }
    
    public static ResourceConfig commonConfig() {
        return new ResourceConfig()
                .property(CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true)
                .register(EntityFilteringFeature.class)
                .register(JacksonFilteringFeature.class)
                .register(FilteringJacksonJaxbJsonProvider.class)
                .register(MultiPartFeature.class);
    }

    public static void main(String[] args) throws IOException {
        try {
            final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), createApp());

            Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
                @Override
                public void run() {
                    server.shutdownNow();
                }
            }));

            server.start();

            Thread.currentThread().join();
        } catch (IOException | InterruptedException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

@@ -173,100 +173,87 @@
 ort 
-org.glassfish.grizzly.http.server.HttpServer;%0D%0Aimport org.glassfish.jersey.CommonProperties;
+javax.ws.rs.ext.MessageBodyReader;%0D%0Aimport javax.ws.rs.ext.MessageBodyWriter;%0D%0A
 %0D%0Aim
@@ -275,42 +275,28 @@
 ish.
-jersey.
 grizzly
-2
 .http
+.
 server.
-Grizzly
 Http
@@ -301,23 +301,16 @@
 tpServer
-Factory
 ;%0D%0Aimpor
@@ -336,255 +336,155 @@
 sey.
-jackson.internal.FilteringJacksonJaxbJsonProvider;%0D%0Aimport org.glassfish.jersey.jackson.internal.JacksonFilteringFeature;%0D%0Aimport org.glassfish.jersey.media.multipart.MultiPartFeature;%0D%0Aimport org.glassfish.jersey.message.filtering.EntityFiltering
+CommonProperties;%0D%0Aimport org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;%0D%0Aimport org.glassfish.jersey.media.multipart.MultiPart
 Feat
@@ -2052,16 +2052,82 @@
 Binder;%0D
+%0Aimport com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;%0D
 %0A%0D%0Apubli
@@ -3715,153 +3715,79 @@
 ter(
-EntityFilteringFeature.class)%0D%0A                .register(JacksonFilteringFeature.class)%0D%0A                .register(FilteringJacksonJaxbJsonProvid
+JacksonJaxbJsonProvider.class, MessageBodyReader.class, MessageBodyWrit
 er.c

Fix jackson registers