-
Jul 7th, 2012, 08:12 AM
#1
How to consume spring security enabled REST webservice in Android Spring RestTemplate
Hi Guys,
I created a rest webservice using spring, then later I added a spring authentication module. I would say it is working great as each time I access the REST URL my request ib being intercepted prompting me for username and password.
Now, I would like to consume the REST webservice in android (authentication spring enabled) using the Spring RestTemplate. My question now is how do I consume the webservice in android given that it has authentication security?
Could someone help me guys have a code snippet on how to pass the username and password in RestTemplate, or could anyone give me a way to do it.
Thank you
Lightyear
-
Jul 7th, 2012, 10:41 PM
#2
Guys,
To be more specific here's what I was dong but still was not able to run RestTemplate without being challenged for authentication:
HttpClient client = new HttpClient();
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("your_user","your_pass word");
client.getState().setCredentials(new AuthScope("thehost", 9090, AuthScope.ANY_REALM), credentials);
CommonsClientHttpRequestFactory commons = new CommonsClientHttpRequestFactory(client);
RestTemplate template = new RestTemplate(commons);
JobList results = template.getForObject(
"http://thehost:9090/foo/job/history?order=desc&limit=5&status=completed"
,JobList.class);
Any idea on how to call a secured (spring authentication) webservice using rest template?
-
Jul 8th, 2012, 09:48 PM
#3
You will need to set HttpClient to do Preemptive Authentication. See the 4.x documentation or the 3.x documentation.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules