Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring an HTTP proxy in a Spring web app

I have been searching around for a proper way to configure an HTTP proxy in a Spring web application. Unfortunately, each time the results I get are about AOP proxies and not HTTP proxies.

Basically, one module of my application is running a webservice client configure in the Spring XML file with JAX-WS, giving something like :

<bean id="heartBeatWebservice" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">  
    <property name="serviceInterface" value="the.web.service.interface"/>  
    <property name="wsdlDocumentUrl" value="http://thehost:theport/theservicename.wsdl"/>  
    <property name="serviceName" value="TheServiceName"/>  
    <property name="namespaceUri" value="http://the.namespace/"/>  
    <property name="portName" value="TheWebServicePortName"/>  
</bean>

But my app has to run behind an HTTP proxy for being able to call the web service, and I must acknowledge that I don't know how to do it properly within the Spring context.

I tried in some main class that I wrote to try out this code at first :

System.setProperty("http.proxyHost", "my.proxy.addr");  
System.setProperty("http.proxyPort", "8080");  

Unfortunately, it didn't work as expected. I assume there is a nice way to configure an HTTP proxy in a Spring context but can't find out how ...

Can you give me a hint ?

like image 570
Anthony Richir Avatar asked May 06 '11 07:05

Anthony Richir


People also ask

How do I add a proxy to Spring Tool Suite?

Just click on Connections tab and LAN Settings button. Check Use a proxy server for your LAN (...) box and provide proxy details. Then go to Spring Tool Suite window and click on Window >> Preferences >> General >> Network Connections and choose Native from the Active Provider drop down list.

How does proxy work in spring?

Spring AOP uses either JDK dynamic proxies or CGLIB to create the proxy for a given target object. (JDK dynamic proxies are preferred whenever you have a choice). If the target object to be proxied implements at least one interface then a JDK dynamic proxy will be used.

How do I configure proxy settings for Java?

Configure Proxies through the Java Control PanelIn the Java Control Panel, under the General tab, click on Network Settings. Select the Use Browser Settings checkbox. Click OK to save your changes. Close all browser windows.

What is proxy server in spring boot?

Proxy servers act as intermediaries between client applications and other servers. In an enterprise setting, we often use them to help provide control over the content that users consume, usually across network boundaries.


1 Answers

There isn't any Spring-specific HTTP proxy configuration required. It should use the standard Java HTTP proxy settings, so you're going along the right lines. Can you try running the main class using -Dhttp.proxyHost=my.proxy.host -Dhttp.proxyPort=8080 rather than using System.setProperty?

like image 93
artbristol Avatar answered Sep 22 '22 23:09

artbristol