Make rest template builder optional
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
<artifactId>spring-cloud-function-gateway</artifactId>
|
<artifactId>spring-cloud-function-gateway</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>spring-cloud-function-gateway</name>
|
<name>spring-cloud-function-gateway</name>
|
||||||
<description>Spring Cloud Function Web Support</description>
|
<description>Spring Cloud Function Gateway Support</description>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
@@ -14,10 +14,6 @@
|
|||||||
<version>1.0.0.BUILD-SNAPSHOT</version>
|
<version>1.0.0.BUILD-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<spring-cloud-function.version>1.0.0.BUILD-SNAPSHOT</spring-cloud-function.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2015 the original author or authors.
|
* Copyright 2016-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package org.springframework.cloud.function.gateway.config;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
@@ -49,39 +50,40 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
|
|||||||
@EnableConfigurationProperties(ProxyProperties.class)
|
@EnableConfigurationProperties(ProxyProperties.class)
|
||||||
public class ProxyResponseAutoConfiguration extends WebMvcConfigurerAdapter {
|
public class ProxyResponseAutoConfiguration extends WebMvcConfigurerAdapter {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApplicationContext context;
|
private ApplicationContext context;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
public ProxyExchangeArgumentResolver proxyExchangeBuilderArgumentResolver(
|
public ProxyExchangeArgumentResolver proxyExchangeBuilderArgumentResolver(
|
||||||
RestTemplateBuilder builder, ProxyProperties proxy) {
|
Optional<RestTemplateBuilder> optional, ProxyProperties proxy) {
|
||||||
RestTemplate template = builder.build();
|
RestTemplateBuilder builder = optional.orElse(new RestTemplateBuilder());
|
||||||
template.setErrorHandler(new NoOpResponseErrorHandler());
|
RestTemplate template = builder.build();
|
||||||
template.getMessageConverters().add(new ByteArrayHttpMessageConverter() {
|
template.setErrorHandler(new NoOpResponseErrorHandler());
|
||||||
@Override
|
template.getMessageConverters().add(new ByteArrayHttpMessageConverter() {
|
||||||
public boolean supports(Class<?> clazz) {
|
@Override
|
||||||
return true;
|
public boolean supports(Class<?> clazz) {
|
||||||
}
|
return true;
|
||||||
});
|
}
|
||||||
ProxyExchangeArgumentResolver resolver = new ProxyExchangeArgumentResolver(
|
});
|
||||||
template);
|
ProxyExchangeArgumentResolver resolver = new ProxyExchangeArgumentResolver(
|
||||||
resolver.setHeaders(proxy.convertHeaders());
|
template);
|
||||||
resolver.setSensitive(proxy.getSensitive()); // can be null
|
resolver.setHeaders(proxy.convertHeaders());
|
||||||
return resolver;
|
resolver.setSensitive(proxy.getSensitive()); // can be null
|
||||||
}
|
return resolver;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addArgumentResolvers(
|
public void addArgumentResolvers(
|
||||||
List<HandlerMethodArgumentResolver> argumentResolvers) {
|
List<HandlerMethodArgumentResolver> argumentResolvers) {
|
||||||
argumentResolvers.add(context.getBean(ProxyExchangeArgumentResolver.class));
|
argumentResolvers.add(context.getBean(ProxyExchangeArgumentResolver.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class NoOpResponseErrorHandler extends DefaultResponseErrorHandler {
|
private static class NoOpResponseErrorHandler extends DefaultResponseErrorHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleError(ClientHttpResponse response) throws IOException {
|
public void handleError(ClientHttpResponse response) throws IOException {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user