Several java proxy servlet tool

HTTP-Proxy-Servlet

The tool is relatively simple, it can be configured, or code way https://github.com/mitre/HTTP-Proxy-Servlet

  • servlet configuration
<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 code that way
@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 Configuration

proxy:
    solr:
        servlet_url: /solr/*
        target_url: http://solrserver:8983/solr
 
 

Jetty's ProxyServlet:

This is also the most complete realization of a more complex
https://www.eclipse.org/jetty/documentation/9.4.x/proxy-servlet.html

netflix zuul

Technical spring cloud netflix zuul gateway used https://github.com/Netflix/zuul , currently it includes two versions 1.x and 2 the difference is quite big
way different filter stages of processing zuul very good, more flexible

charon-spring-boot-starter

Function is very wide, very convenient a tool
https://github.com/mkopylec/charon-spring-boot-starter/wiki

  • Simple to use
 
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"));
    }
}
 

Guess you like

Origin www.cnblogs.com/rongfengliang/p/11408312.html