Announcement Announcement Module
Collapse
No announcement yet.
Can not detect Proxy of system Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can not detect Proxy of system

    Hello,
    I have a requirement where I need to detect proxy of the system on which web app is deployed and use detected proxy and its port .
    I have found java.net.useSystemProxies , through which we can achieve this. I have used this property and below code
    Code:
    System.setProperty("java.net.useSystemProxies")
    Proxy proxy = (Proxy) ProxySelector.getDefault().select(new URI("http://www.yahoo.com/")).iterator().next();	
    		InetSocketAddress addr = (InetSocketAddress) proxy.address();
    proxyHost  = addr.getHostName();
    			proxyPort  = addr.getPort();
    in standalone java program with main method. On running the standalone java program, the proxy and its port gets detected as expected.
    However when I use the same piece of code in junit and in web app , it doesnt work, it doesnt detect the proxy . It displays as DIRECT connection . Btw I am using spring .
    To set this property for junit and spring container , I pass it using below code
    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>
    When I sysout in junit / in web app , it properly reflects the value which is set in context.xml as shown above .But it doesnt detect the proxy and its port. Its detects as DIRECT connection , where in it should get the proxy existing on system.
    I am struggling very hard to get it . If any one could help me achieving or way to troubleshoot it , will be very helpful.
    thanks in advance
Working...
X