All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.formkiq.server.config.ApplicationConfig Maven / Gradle / Ivy

There is a newer version: 0.6.1
Show newest version
package com.formkiq.server.config;

import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.ErrorPage;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;

/**
 * ApplicationConfig.
 *
 */
@Configuration
@EnableScheduling
@EnableGlobalMethodSecurity(securedEnabled = true)
public class ApplicationConfig {

    /** URL to handle 404. */
	public static final String API_ERROR_404 = "/api/error/404";
	/** URL to handle 405. */
	public static final String API_ERROR_405 = "/api/error/405";
	/** URL to handle 500. */
	public static final String API_ERROR_500 = "/api/error/500";

	/** Embedded Servlet Container. */
	private static final EmbeddedServletContainerCustomizer CONTAINER =
	        new EmbeddedServletContainerCustomizer() {
        @Override
        public void customize(
                final ConfigurableEmbeddedServletContainer container) {

            ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND,
                    API_ERROR_404);
            ErrorPage error405Page = new ErrorPage(
                    HttpStatus.METHOD_NOT_ALLOWED, API_ERROR_405);
            ErrorPage error500Page = new ErrorPage(
                    HttpStatus.INTERNAL_SERVER_ERROR, API_ERROR_500);

            container.addErrorPages(error404Page, error405Page,
                    error500Page);
        }
    };

	/**
	 * Create Customizer container.
	 * @return EmbeddedServletContainerCustomizer
	 */
	@Bean
	public EmbeddedServletContainerCustomizer containerCustomizer() {
        return CONTAINER;
	}

	/**
	 * Set Dates to use ISO-8601 format.
	 * @return Jackson2ObjectMapperBuilder
	 */
	@Bean
	public Jackson2ObjectMapperBuilder jacksonBuilder() {
	    Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
	    builder.simpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
	    builder.propertyNamingStrategy(PropertyNamingStrategy.LOWER_CASE);
	    builder.serializationInclusion(Include.NON_NULL);
	    return builder;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy