Ok I am copying the code . I want to fetch the proxies in the system on which my web application will be deployed.So I used java system property that returns proxies on underlying system.
This is the snipped of test-applicationcontext.xml
Code:
<bean id="systemPrereqs"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" value="#{@systemProperties}" />
<property name="targetMethod" value="putAll" />
<property name="arguments">
<!-- The new Properties -->
<util:properties>
<prop key="java.net.useSystemProxies">true</prop>
</util:properties>
</property>
</bean>
and this my code I want to test
Code:
Proxy proxy = (Proxy) ProxySelector.getDefault().select(new URI("http://www.yahoo.com/")).iterator().next();
InetSocketAddress addr = (InetSocketAddress) proxy.address();
if (addr == null) {
System.out.println("No Proxy");
}else {
proxyHost = addr.getHostName();
proxyPort = addr.getPort();
System.out.println("proxy hostname : "
+proxyHost );
System.out.println("proxy port : "
+ proxyPort);
}
So when I ran above java code in a standalone program , I am able to see the proxy host and ports
But in junit they are appearing as null.