几个java proxy servlet 工具
HTTP-Proxy-Servlet
这个工具使用比较简单,可以通过配置,或者代码的方式 https://github.com/mitre/HTTP-Proxy-Servlet
- servlet 配置方式
<servlet>
<servlet-name>clusterProxy</servlet-name>
<servlet-class>org.mitre.dsmiley.httpproxy.URITemplateProxyServlet</servlet-class>
<init-param>
<param-name>targetUri</param-name>
<param-value>http://{_subHost}.behindfirewall.mycompany.com:{_port}/{_path}</param-value>
</init-param>
<init-param>
<param-name>log</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>clusterProxy</servlet-name>
<url-pattern>/mywebapp/cluster/*</url-pattern>
</servlet-mapping>
- spring boot 代码方式
@Configuration
public class SolrProxyServletConfiguration implements EnvironmentAware {
@Bean
public ServletRegistrationBean servletRegistrationBean(){
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new ProxyServlet(), propertyResolver.getProperty("servlet_url"));
servletRegistrationBean.addInitParameter(ProxyServlet.P_TARGET_URI, propertyResolver.getProperty("target_url"));
servletRegistrationBean.addInitParameter(ProxyServlet.P_LOG, propertyResolver.getProperty("logging_enabled", "false"));
return servletRegistrationBean;
}
private RelaxedPropertyResolver propertyResolver;
@Override
public void setEnvironment(Environment environment) {
this.propertyResolver = new RelaxedPropertyResolver(environment, "proxy.solr.");
}
}
yaml 配置
proxy:
solr:
servlet_url: /solr/*
target_url: http://solrserver:8983/solr
Jetty's ProxyServlet:
这个是最全也是比较复杂的一个实现
https://www.eclipse.org/jetty/documentation/9.4.x/proxy-servlet.html
netflix zuul
spring cloud netflix zuul gateway 使用的技术https://github.com/Netflix/zuul,目前主要包括了两个版本1.x 以及 2差异还是比较大的
zuul 不同filter 阶段处理的方式很不错,比较灵活
charon-spring-boot-starter
功能很全,很方便的一个工具
https://github.com/mkopylec/charon-spring-boot-starter/wiki
- 简单使用
import static com.github.mkopylec.charon.configuration.CharonConfigurer.charonConfiguration;
import static com.github.mkopylec.charon.configuration.RequestMappingConfigurer.requestMapping;
import static com.github.mkopylec.charon.forwarding.interceptors.rewrite.RequestServerNameRewriterConfigurer.requestServerNameRewriter;
@Configuration
class CharonConfiguration {
@Bean
CharonConfigurer charonConfigurer() {
return charonConfiguration()
.set(requestServerNameRewriter().outgoingServers("host1:8080", "host2:8081"))
.add(requestMapping("all requests mapping"));
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)