/*
 * Copyright 2015 the original author or 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 org.springframework.cloud.dataflow.admin.config;

import static org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType.HAL;

import java.util.List;

import org.springframework.boot.actuate.metrics.repository.MetricRepository;
import org.springframework.boot.actuate.metrics.repository.redis.RedisMetricRepository;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.dataflow.admin.completion.TapOnChannelExpansionStrategy;
import org.springframework.cloud.dataflow.admin.repository.InMemoryStreamDefinitionRepository;
import org.springframework.cloud.dataflow.admin.repository.InMemoryTaskDefinitionRepository;
import org.springframework.cloud.dataflow.admin.repository.StreamDefinitionRepository;
import org.springframework.cloud.dataflow.admin.repository.TaskDefinitionRepository;
import org.springframework.cloud.dataflow.artifact.registry.ArtifactRegistry;
import org.springframework.cloud.dataflow.artifact.registry.RedisArtifactRegistry;
import org.springframework.cloud.dataflow.completion.CompletionConfiguration;
import org.springframework.cloud.dataflow.completion.RecoveryStrategy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.web.config.EnableSpringDataWebSupport;
import org.springframework.hateoas.config.EnableHypermediaSupport;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * Configuration for admin application context. This includes support
 * for the REST API framework configuration.
 *
 * @author Mark Fisher
 * @author Marius Bogoevici
 * @author Patrick Peralta
 * @author Thomas Risberg
 * @author Janne Valkealahti
 */
@Configuration
@EnableHypermediaSupport(type = HAL)
@EnableSpringDataWebSupport
@Import(CompletionConfiguration.class)
@EnableConfigurationProperties(AdminProperties.class)
public class AdminConfiguration {

	@Bean
	public MetricRepository metricRepository(RedisConnectionFactory redisConnectionFactory) {
		return new RedisMetricRepository(redisConnectionFactory);
	}

	@Bean
	public StreamDefinitionRepository streamDefinitionRepository() {
		return new InMemoryStreamDefinitionRepository();
	}

	@Bean
	public TaskDefinitionRepository taskDefinitionRepository() {
		return new InMemoryTaskDefinitionRepository();
	}

	@Bean
	public ArtifactRegistry artifactRegistry(RedisConnectionFactory redisConnectionFactory) {
		return new RedisArtifactRegistry(redisConnectionFactory);
	}

	@Bean
	public ArtifactRegistryPopulator artifactRegistryPopulator(ArtifactRegistry artifactRegistry) {
		return new ArtifactRegistryPopulator(artifactRegistry);
	}

	@Bean
	public WebMvcConfigurer configurer() {
		return new WebMvcConfigurerAdapter() {

			@Override
			public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
				// the REST API produces JSON only; adding this converter
				// prevents the registration of the default converters
				converters.add(new MappingJackson2HttpMessageConverter());
			}

			@Override
			public void configurePathMatch(PathMatchConfigurer configurer) {
				configurer.setUseSuffixPatternMatch(false);
			}
		};
	}

	@Bean
	public RecoveryStrategy tapOnChannelExpansionStrategy() {
		return new TapOnChannelExpansionStrategy();
	}

}

@@ -779,20 +779,22 @@
 va.util.
-List
+Arrays
 ;%0A%0Aimpor
@@ -945,32 +945,105 @@
 tricRepository;%0A
+import org.springframework.boot.autoconfigure.web.HttpMessageConverters;%0A
 import org.sprin
@@ -3856,168 +3856,77 @@
 lic 
-WebMvcConfigurer configurer() %7B%0A%09%09return new WebMvcConfigurerAdap
+HttpMessageConverters messageConver
 ter
+s
 () %7B%0A
-%0A
 %09%09
-%09@Override%0A%09%09%09public void configureMessageConverters(List%3CHttpMessageConverter%3C?%3E%3E c
+return new HttpMessageC
 onve
@@ -3934,19 +3934,17 @@
 ters
-) %7B
+(
 %0A%09%09%09%09// 
 the 
@@ -3943,110 +3943,88 @@
 %09// 
-the REST API produces JSON only; adding this converter%0A%09%09%09%09// prevents the registration of the default
+Prevent default converters%0A%09%09%09%09false,%0A%09%09%09%09// Have Jackson2 converter as the sole
  con
@@ -4033,28 +4033,51 @@
 rter
-s
 %0A%09%09%09%09
-converters.add
+Arrays.%3CHttpMessageConverter%3C?%3E%3EasList
 (new
@@ -4115,22 +4115,110 @@
 erter())
+)
 ;%0A%09
-%09%09%7D
+%7D%0A%0A%09@Bean%0A%09public WebMvcConfigurer configurer() %7B%0A%09%09return new WebMvcConfigurerAdapter() %7B
 %0A%0A%09%09%09@Ov

Remove all default http converters, leaving Jackson2 as the sole converter