Announcement Announcement Module
Collapse
No announcement yet.
WebServiceTemplate with proxy authentication Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • WebServiceTemplate with proxy authentication

    I've revised my example -

    I am attempting to wire a WebServiceTemplate bean with a MessageSender which, in turn, is wired with proxy authentication. The following configuration fails with a 407 error:

    ApplicationContext:
    Code:
        <bean id="smsMessageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>
    
    	<bean id="myHostConfig" class="com.bogus.sms.HostConfiguration">  
    	    <property name="proxyHostPlusPort" value="10.75.20.134:8080" />   
    	</bean>  
            <!-- ref: myHostConfig from http://onebyteatatime.wordpress.com/2009/04/08/spring-web-service-call-using-proxy-per-connection/# -->
    
    	<bean id="httpClient" class="org.apache.commons.httpclient.HttpClient">  
    	    <constructor-arg>
    	    	<bean class="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager"/>
    	    </constructor-arg>
    		<property name="hostConfiguration" ref="myHostConfig" />   
    	</bean>  
        
    	<bean id="smsWebServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
    	    <constructor-arg ref="smsMessageFactory"/>
    	    <property name="messageSender">
    	        <bean class="org.springframework.ws.transport.http.CommonsHttpMessageSender">
    				<constructor-arg ref="httpClient"/>  
    	            <property name="credentials"> 
    	                <bean class="org.apache.commons.httpclient.NTCredentials">
    	                    <constructor-arg  index="0" value="username"/>
    	                    <constructor-arg  index="1" value="pw"/>
    	                    <constructor-arg  index="2" value="localhost"/>
    	                    <constructor-arg  index="3" value="MYDOMAIN"/>
    	                </bean>
    	            </property>
    	            <property name="authScope">
    	            	<bean class="org.apache.commons.httpclient.auth.AuthScope">
    						<constructor-arg  index="0"><null/></constructor-arg>
    	                    <constructor-arg  index="1" value="8080"/>
    	            	</bean>
    	            </property>
    	        </bean>
    	    </property>
            <property name="defaultUri" value="http://www.bogus.com"/>
    	</bean>
    Java:
    Code:
    public class SmsMessageSender extends WebServiceGatewaySupport {	
    	public void send(...) {	
    	   String MESSAGE = "...";
               StreamSource source = new StreamSource(new StringReader(MESSAGE));
               StreamResult result = new StreamResult(System.out);
               WebServiceTemplate webServiceTemplate = getWebServiceTemplate();
               webServiceTemplate.sendSourceAndReceiveToResult(source, result);		
    	}
    Stack trace:
    Code:
    org.springframework.ws.client.WebServiceTransportException: Proxy Authentication Required ( The ISA Server requires authorization to fulfill the request. Access to the Web Proxy filter is denied.  ) [407]
    	at org.springframework.ws.client.core.WebServiceTemplate.handleError(WebServiceTemplate.java:627)
    	at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:551)
    	at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:502)
    	at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:457)
    	at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceiveToResult(WebServiceTemplate.java:403)
    	at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceiveToResult(WebServiceTemplate.java:394)
    	at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceiveToResult(WebServiceTemplate.java:384)
    	at ...SmsMessageSender.send(SmsMessageSender.java:26)

    If I set the ProxyCredentials on the State in the java code, it works fine:

    ApplicationContext:
    Code:
    	<bean id="smsWebServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
    	    <constructor-arg ref="smsMessageFactory"/>
                <property name="defaultUri" value="http://www.bogus.com"/>
    	</bean>
    Java:
    Code:
    public class SmsMessageSender extends WebServiceGatewaySupport {	
    	public void send(...) {	
    	   String MESSAGE = "...";
               StreamSource source = new StreamSource(new StringReader(MESSAGE));
               StreamResult result = new StreamResult(System.out);
    
    
               WebServiceTemplate webServiceTemplate = getWebServiceTemplate();
    
               /* HttpClient bean is injected  in this version. 
                * Set the proxy credentials on HttpCLient State manually.   
                *  Is it possible to wire the WebServiceTemplate in a way to do this for me?
                */ 
    	   _httpClient.getState().setProxyCredentials(
    		           new AuthScope(null, 8080),
    		           new NTCredentials("username", "pw","localhost", "MYDOMAIN" )
    		           );		
    
               WebServiceMessageSender messageSender = new CommonsHttpMessageSender(_httpClient);
    
    
               webServiceTemplate.sendSourceAndReceiveToResult(source, result);		
    	}
    Is it possible to wire the WebServiceTemplate in a way that is will have the proxy credentials without setting them in the java code
    or am misunderstanding the use of the credentials and authScope properties of the org.springframework.ws.transport.http.CommonsHttpM essageSender?

    Any advice is appreciated. Thank you for your time.
    Last edited by mack; May 14th, 2009, 09:52 AM. Reason: updated example and question

  • #2
    Hi, have you tried to use VM arguments: -Dhttp.proxyHost=mydomain.com -Dhttp.proxyPort=3128 ?

    Comment

    Working...
    X