I have a spring-boot
app, that I can make an HTTP
request to, and which will send another HTTP
request to some other resource on the internet.
@RestController
@SpringBootApplication
public class BookApplication {
@RequestMapping(value = "/available")
public String available() throws Exception {
String url = "https://www.google.com";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("User-Agent", "Mozilla/5.0");
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
StringBuffer response = new StringBuffer();
String inputLine;
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
return "Spring in Action";
}
public static void main(String[] args) {
SpringApplication.run(BookApplication.class, args);
}
}
And I also have another spring-boot
app that is a Zuul
proxy.
@EnableZuulProxy
@SpringBootApplication
public class GatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args);
}
@Bean
public SimpleFilter simpleFilter() {
return new SimpleFilter();
}
}
SimpleFilter class is:
public class SimpleFilter extends ZuulFilter {
private static Logger log = LoggerFactory.getLogger(SimpleFilter.class);
@Override
public String filterType() {
return "pre";
}
@Override
public int filterOrder() {
return 1;
}
@Override
public boolean shouldFilter() {
return true;
}
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest request = ctx.getRequest();
log.info(String.format("%s request to %s", request.getMethod(), request.getRequestURL().toString()));
return null;
}
}
And application.properties for Zuul
proxy app:
zuul.routes.books.url=http://localhost:8090
ribbon.eureka.enabled=false
server.port=8080
Basically, everything is from this tutorial tutorial
So I'm wondering if there is a chance to proxy the request to "https://www.google.com" that's done by /available
resource in the BookApplication
?
There's no way to do it. Zuul is just not meant for that kind of things.