我有两个web服务器A和C。由于规则、策略等原因,A无法与C' (C直接通信,requires requests to have special security headers anda`不支持)
我想创建一个在Java语言中称为B的“代理”,以促进A和B之间的通信,但我在概念上遇到了问题。
创建代理时,是否必须更改所有服务上的硬编码URL才能通过代理?然后,我想您必须以某种方式将目的地作为查询参数进行传递,例如
http://proxy.com/?destination=mydestination.com这就是代理的工作方式吗?
(我发现了一些类似的问题,但它们并没有解决我遇到的基本问题,即How packets reaches Destination throgh proxy servers?)
发布于 2016-12-20 23:40:16
不要从头开始编写自己的代理,这将是重做,有大量的代理实现
Spring框架
(Netflex/Zuul) https://github.com/Netflix/zuul / https://spring.io/guides/gs/routing-and-filtering/的
标准Servlet
如果您对如何构建自己的代理感兴趣,这里有一个使用spring框架的简单示例(Servlet实现与spring实现相差不远)。
@RestController
public class ProxyController {
/**
* request handler for all the requests on the registered context intended to be proxied
*
* @param request
* @return
*/
@RequestMapping("/**")
public String defaultGateway(HttpServletRequest request) {
// edit the original request headers,body etc
String originalPath = request.getRequestURI();
// then fire another HTTP request using the same URI
return "ProxiedResult"; // return back the result you get from
}
}上面的例子是一个关于如何实现HTTP代理或它是如何工作的起点,有许多东西需要涵盖,例如安全性
https://stackoverflow.com/questions/41245116
复制相似问题