package com.aemreunal.config;

/*
 **************************
 * Copyright (c) 2014     *
 *                        *
 * This code belongs to:  *
 *                        *
 * Ahmet Emre Ünal        *
 * S001974                *
 *                        *
 * aemreunal@gmail.com    *
 * emre.unal@ozu.edu.tr   *
 *                        *
 * aemreunal.com          *
 **************************
 */

import java.util.List;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.hibernate4.Hibernate4Module;

/*
 * http://www.petrikainulainen.net/programming/spring-framework/unit-testing-of-spring-mvc-controllers-configuration/
 */

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = { "com.aemreunal" })
public class MVCConfig extends WebMvcConfigurerAdapter {
    // TODO find out what this class is used for

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        super.addInterceptors(registry);
        // TODO Add security interceptor for HTTP to HTTPS redirect
        // http://docs.spring.io/spring/docs/4.0.0.RELEASE/spring-framework-reference/htmlsingle/#mvc-container-config
        // http://docs.spring.io/autorepo/docs/spring-framework/3.1.x/javadoc-api/org/springframework/web/WebApplicationInitializer.html
//        registry.addInterceptor(new FilterSecurityInterceptor()).addPathPatterns("/secure/*");
//        registry.addInterceptor().addPathPatterns("/secure/*");
    }

    public MappingJackson2HttpMessageConverter jacksonMessageConverter() {
        MappingJackson2HttpMessageConverter messageConverter = new MappingJackson2HttpMessageConverter();

        ObjectMapper mapper = new ObjectMapper();
        //Registering Hibernate4Module to support lazy objects
        mapper.registerModule(new Hibernate4Module());

        messageConverter.setObjectMapper(mapper);
        return messageConverter;
    }

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        //Here we add our custom-configured HttpMessageConverter
        converters.add(jacksonMessageConverter());
        super.configureMessageConverters(converters);
    }
}

@@ -764,86 +764,8 @@
 vc;%0A
-import org.springframework.web.servlet.config.annotation.InterceptorRegistry;%0A
 impo
@@ -838,24 +838,24 @@
 rerAdapter;%0A
+
 import com.f
@@ -1274,17 +1274,19 @@
 sed for%0A
+/*
 %0A
-
     @Ove
@@ -1807,24 +1807,26 @@
 rns(%22/secure
+*/
 /*%22);%0A//    
@@ -1879,22 +1879,304 @@
 %22/secure
+*/
 /*%22);%0A
+    %7D*/%0A%0A    @Override%0A    public void configureMessageConverters(List%3CHttpMessageConverter%3C?%3E%3E converters) %7B%0A        //Here we add our custom-configured HttpMessageConverter%0A        converters.add(jacksonMessageConverter());%0A        super.configureMessageConverters(converters);%0A
     %7D%0A%0A 
@@ -2575,16 +2575,16 @@
 apper);%0A
+
         
@@ -2617,285 +2617,7 @@
    %7D
-%0A%0A    @Override%0A    public void configureMessageConverters(List%3CHttpMessageConverter%3C?%3E%3E converters) %7B%0A        //Here we add our custom-configured HttpMessageConverter%0A        converters.add(jacksonMessageConverter());%0A        super.configureMessageConverters(converters);%0A    %7D
 %0A%7D%0A

Clean up