0

I am integrating hoverfly as proxy server for my spring boot application. This application calls other REST APIs and I want to capture the request and response and later use that in simulate mode for further calls through hoverfly.

I am able to implement through below code and its working fine

Proxy proxy= new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8500));
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setProxy(proxy);
restTemplate.setRequestFactory(requestFactory);

But I am unable to run it with following JVM argument passed from command line at run time: -Dhttp.proxyHos127.0.0.1 -Dhttp.proxyPort=8500 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=8500 -Dhttps.proxySet=true -Dhttp.proxySet=true

When I use these parameters, no proxy host is set and all requests are goes to actual server.

As I read on many forums that proxy configuration is possible through JVM argument. So, I am trying to use proxy server without changing any code.

Please suggest if its possible.

Kapil
  • 108
  • 1
  • 12
  • you are passing these arguments from command line fine. But how are you reading it in your code? where is that piece of code? – pvpkiran Aug 21 '18 at 15:22
  • @pvpkiran thanks for quick reply. Actually thats my concerns, is it possible to set proxy server from command line or yml file only? – Kapil Aug 21 '18 at 15:24
  • of course it is possible. use `@Value` or `@ConfigurationProperties` – pvpkiran Aug 22 '18 at 09:15
  • @pvpkiran, Like I mentioned in description, I am able to do it through code by setting proxy host and port in requestFactory. But I want to know that is it mandatory to set host and port in requestFactory or just passing them from command line is enough. Because many forums were telling that its possible by JVM arguments only. Please suggest. – Kapil Aug 22 '18 at 11:35
  • by passing them from command line doesn't do anything, If from code you dont read it and set it to requestFactory. Other option is, you have to set system environmental variable for proxy host and password. Then, you don't have to pass anything to your program and doesnt need to do any thing in code. – pvpkiran Aug 22 '18 at 11:37
  • Ok, I was looking if spring itself have something to set proxy host and port internally after reading from argument. So, in any case we need to set these in requestFactory right? – Kapil Aug 22 '18 at 11:40

0 Answers0