RestTemplate throws Could not extract response when spring-security is enabled -
resttemplate fails convert pojo json if spring-security enabled.
following error message thrown---> there unexpected error (type=internal server error, status=500). not extract response: no suitable httpmessageconverter found response type [class java.util.arraylist] , content type [text/html;charset=utf-8]
works if spring-security disabled-->// http.authorizerequests().anyrequest().permitall(); please find spring-security snippet.
http.formlogin() .loginpage("/signin") .loginprocessingurl("/signin/authenticate") .failureurl("/signin?param.error=bad_credentials") .defaultsuccessurl("/howpointsworks") .and().logout() .logouturl("/signout") .deletecookies("jsessionid") .and() .authorizerequests() .antmatchers("/","/favicon.ico") .permitall() .antmatchers("/rest/v1/**", "/twitter/**", "/web/**").hasrole("user") .and() .apply(new springsocialconfigurer());
restful service invoked spring-mvc controller via resttemplate
@requestmapping(value = "/web/contentfeed", method = requestmethod.get) public modelandview showcontentfeedform(principal principal, httpservletrequest request) { resttemplate resttemplate = new resttemplate(); resttemplate.setmessageconverters(getmessageconverters()); string url = "http://localhost:9000/rest/v1/socialmedia"; httpheaders headers = new httpheaders(); headers.setaccept(arrays.aslist(mediatype.application_json)); httpentity<string> entity = new httpentity<string>(headers); responseentity<arraylist> social = resttemplate.getforentity(url, arraylist.class); parameterizedtypereference<list<socialmedia>> responsetype = new parameterizedtypereference<list<socialmedia>>() { }; responseentity<list<socialmedia>> list = resttemplate.exchange(url, httpmethod.get, entity, responsetype); } mv.addobject("list",list); return mv; }
restful endpoint invoked resttemplate
@requestmapping(method = requestmethod.get,produces={"application/json"}) public responseentity<list<socialmedia>> getallsocialmedia() { return new responseentity<list<socialmedia>>(socialmediarepository.findall(), null, httpstatus.ok); }
fails convert socialmedia(pojo)--> json if spring-security enabled. tried setting headers mediatype.all doesnot work.
Comments
Post a Comment