package com.aemreunal.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

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

/*
 * 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/*");
    }
}

@@ -24,16 +24,39 @@
 onfig;%0A%0A
+import java.util.List;%0A
 import o
@@ -169,16 +169,164 @@
 ration;%0A
+import org.springframework.http.converter.HttpMessageConverter;%0Aimport org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;%0A
 import o
@@ -1045,16 +1045,135 @@
 ion/%0A */
+%0Aimport com.fasterxml.jackson.databind.ObjectMapper;%0Aimport com.fasterxml.jackson.datatype.hibernate4.Hibernate4Module;
 %0A%0A@Confi
@@ -1964,11 +1964,730 @@
 );%0A    %7D
+%0A%0A    public MappingJackson2HttpMessageConverter jacksonMessageConverter() %7B%0A        MappingJackson2HttpMessageConverter messageConverter = new MappingJackson2HttpMessageConverter();%0A%0A        ObjectMapper mapper = new ObjectMapper();%0A        //Registering Hibernate4Module to support lazy objects%0A        mapper.registerModule(new Hibernate4Module());%0A%0A        messageConverter.setObjectMapper(mapper);%0A        return messageConverter;%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%7D%0A

Add Jackson Hibernate message converter