com.vilt.minium.app.MiniumAppWebConfig Maven / Gradle / Ivy
/*
* Copyright (C) 2013 The Minium Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.vilt.minium.app;
import java.io.IOException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.http.MediaType;
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.filter.CharacterEncodingFilter;
import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
import com.vilt.minium.app.json.ConsoleObjectMapper;
import com.vilt.minium.prefs.AppPreferences;
import com.vilt.minium.prefs.WebConsolePreferences;
@Configuration
@Import(MiniumConfig.class)
@EnableAutoConfiguration
@ComponentScan
public class MiniumAppWebConfig {
@Autowired
private AppPreferences appPreferences;
@Bean
public CharacterEncodingFilter characterEncodingFilter() {
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
characterEncodingFilter.setEncoding(Charsets.UTF_8.name());
characterEncodingFilter.setForceEncoding(true);
return characterEncodingFilter;
}
@Bean
public ByteArrayHttpMessageConverter byteArrayConverter() {
ByteArrayHttpMessageConverter converter = new ByteArrayHttpMessageConverter();
converter.setSupportedMediaTypes(Lists.newArrayList(MediaType.IMAGE_JPEG, MediaType.IMAGE_PNG, MediaType.IMAGE_GIF));
return converter;
}
@Bean
public MappingJackson2HttpMessageConverter mappingJacksonConverter() {
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setObjectMapper(new ConsoleObjectMapper());
return converter;
}
@Bean
public EmbeddedBrowser embeddedBrowser() throws IOException {
EmbeddedBrowser browser = new EmbeddedBrowser(appPreferences.getBaseDir(), WebConsolePreferences.from(appPreferences));
return browser;
}
@Bean
public TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory() throws IOException {
WebConsolePreferences prefs = WebConsolePreferences.from(appPreferences);
return new TomcatEmbeddedServletContainerFactory(prefs.getPort());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy