Hello,
Here's my REST Dao definition and custom request factory providing HttpClient with credentials:
For some reason, when I access REST resource with this RestTemplate as rest().getForObject() I always get 406 - http://goo.gl/xwicCode:<bean name="artifactoryDAO" class="com.clearforest.wd40.governor.dao.ArtifactoryDAO"> <constructor-arg name = "rest"> <bean class="org.springframework.web.client.RestTemplate"> <property name = "requestFactory"> <bean class = "com.clearforest.wd40.governor.dao.ArtifactoryCommonsClientHttpRequestFactory"> <constructor-arg name = "user" value = "..."/> <constructor-arg name = "password" value = "..."/> </bean> </property> </bean> </constructor-arg> </bean> public class ArtifactoryCommonsClientHttpRequestFactory extends CommonsClientHttpRequestFactory { private final String user; private String user () { return user; } private final String password; private String password () { return password; } public ArtifactoryCommonsClientHttpRequestFactory ( String user, String password ) { this.user = user; this.password = password; } @Override public HttpClient getHttpClient () { HttpClient client = super.getHttpClient(); if ( user() != null ) { client.getState().setCredentials( AuthScope.ANY, new UsernamePasswordCredentials( user(), password())); } return client; } }
But this code works Ok:
It seems as if using RestTemplate doesn't send the credentials. I've debugged the RestTemplate instance and made sure it contains HttpClient with a state holding the right credentials. I'm yet to sniff the HTTP traffic to see what exactly is sent over the network.Code:String request = "..."; GetMethod getMethod = new GetMethod( request ); HttpClient httpClient = new HttpClient(); httpClient.getState().setCredentials( AuthScope.ANY, new org.apache.commons.httpclient.UsernamePasswordCredentials( "...", "..." )); httpClient.executeMethod( getMethod ); String s = getMethod.getResponseBodyAsString();
My question is: is there anybody else experiencing similar issues when sending credentials with RestTemplate? I guess I'll have more information after sniffing but thought I'll ask it here as well.
Thank you!


Reply With Quote
