com.processpuzzle.fitnesse.connect.testbed.application.TestbedApplicationConfiguration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fitnesse-connect-testbed-backend Show documentation
Show all versions of fitnesse-connect-testbed-backend Show documentation
Test server for integration tests
package com.processpuzzle.fitnesse.connect.testbed.application;
import java.lang.reflect.Method;
import java.util.List;
import javax.xml.transform.Source;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.web.WebMvcRegistrationsAdapter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.ResourceHttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
import org.springframework.http.converter.xml.SourceHttpMessageConverter;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
@Configuration
public class TestbedApplicationConfiguration extends WebMvcConfigurerAdapter {
private static final String SPRING_HATEOAS_OBJECT_MAPPER = "_halObjectMapper";
@Autowired @Qualifier( SPRING_HATEOAS_OBJECT_MAPPER ) private ObjectMapper springHateoasObjectMapper;
@Autowired private Jackson2ObjectMapperBuilder springBootObjectMapperBuilder;
@Override public void addViewControllers( ViewControllerRegistry registry ) {
registry.addViewController( "/" ).setViewName( "home" );
registry.addViewController( "/home" ).setViewName( "home" );
registry.addViewController( "/login" ).setViewName( "login" );
registry.addViewController( "/hello" ).setViewName( "hello" );
registry.addViewController( "/api/files" ).setViewName( "uploadForm" );
}
@Bean public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials( true );
config.addAllowedOrigin( "*" );
config.addAllowedHeader( "*" );
config.addAllowedMethod( "*" );
source.registerCorsConfiguration( "/**", config );
CorsFilter bean = new CorsFilter( source );
return bean;
}
@Override public void configureMessageConverters( List> converters ) {
StringHttpMessageConverter stringConverter = new StringHttpMessageConverter();
stringConverter.setWriteAcceptCharset( false );
converters.add( new ByteArrayHttpMessageConverter() );
converters.add( stringConverter );
converters.add( new ResourceHttpMessageConverter() );
converters.add( new SourceHttpMessageConverter