From 6d736fe38934b4320e892244425cdb1010151efd Mon Sep 17 00:00:00 2001 From: huangfeng Date: Wed, 17 Jan 2024 10:24:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0prod-api=E5=AF=B9?= =?UTF-8?q?=E5=A4=96=E8=BD=AC=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 5 +++ .../config/SolrProxyServletConfiguration.java | 36 +++++++++++++++++++ src/main/resources/application-dev.yml | 5 +++ src/main/resources/application-prod.yml | 5 +++ 4 files changed, 51 insertions(+) create mode 100644 src/main/java/com/xydl/cac/config/SolrProxyServletConfiguration.java diff --git a/pom.xml b/pom.xml index 5f8836f..3a36075 100644 --- a/pom.xml +++ b/pom.xml @@ -142,6 +142,11 @@ querydsl-apt ${querydsl.version} + + org.mitre.dsmiley.httpproxy + smiley-http-proxy-servlet + 1.12.1 + diff --git a/src/main/java/com/xydl/cac/config/SolrProxyServletConfiguration.java b/src/main/java/com/xydl/cac/config/SolrProxyServletConfiguration.java new file mode 100644 index 0000000..d108b19 --- /dev/null +++ b/src/main/java/com/xydl/cac/config/SolrProxyServletConfiguration.java @@ -0,0 +1,36 @@ +package com.xydl.cac.config; + +import org.mitre.dsmiley.httpproxy.ProxyServlet; +import org.springframework.boot.context.properties.bind.BindResult; +import org.springframework.boot.context.properties.bind.Binder; +import org.springframework.boot.context.properties.source.ConfigurationPropertySources; +import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.context.EnvironmentAware; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; + +import java.util.Properties; + +@Configuration +public class SolrProxyServletConfiguration implements EnvironmentAware { + + @Bean + public ServletRegistrationBean servletRegistrationBean() { + Properties properties = (Properties) bindResult.get(); + ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new ProxyServlet(), properties.getProperty("servlet_url")); + servletRegistrationBean.addInitParameter(ProxyServlet.P_TARGET_URI, properties.getProperty("target_url")); + servletRegistrationBean.addInitParameter(ProxyServlet.P_LOG, properties.getProperty("logging_enabled", "false")); + return servletRegistrationBean; + } + + private BindResult bindResult; + + @Override + public void setEnvironment(Environment environment) { + Iterable sources = ConfigurationPropertySources.get(environment); + Binder binder = new Binder(sources); + BindResult bindResult = binder.bind("proxy.solr", Properties.class); + this.bindResult = bindResult; + } +} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 9168668..3d58c6a 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -24,3 +24,8 @@ spring: multipart: max-file-size: 100MB max-request-size: 100MB + +proxy: + solr: + servlet_url: /prod-api/* + target_url: http://127.0.0.1:8082/ diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 7053936..788ac02 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -24,3 +24,8 @@ spring: multipart: max-file-size: 100MB max-request-size: 100MB + +proxy: + solr: + servlet_url: /prod-api/* + target_url: http://127.0.0.1:8082/