java - Rest client Templat finding list customer -
- in spring 4.2.1-release
- use resttemplate access rest
- create this
@bean @scope("prototype") @autowired public resttemplate resttemplate( @qualifier("httpcomponentsclienthttprequestfactory") httpcomponentsclienthttprequestfactory httpcomponentsclienthttprequestfactory, @qualifier("mappingjackson2httpmessageconverter") mappingjackson2httpmessageconverter mappingjackson2httpmessageconverter) { final resttemplate resttemplate = new resttemplate(httpcomponentsclienthttprequestfactory); list<httpmessageconverter<?>> messageconverters = new arraylist<httpmessageconverter<?>>(); messageconverters.add(new formhttpmessageconverter()); messageconverters.add(new stringhttpmessageconverter()); messageconverters.add(mappingjackson2httpmessageconverter); resttemplate.setmessageconverters(messageconverters); return resttemplate; } when use after injec in junit test
httpheaders requestentity = new httpheaders(); requestentity.setaccept(collections.singletonlist(new mediatype("application","json"))); httpentity<?> entity = new httpentity<customer>(requestentity); responseentity<customer> responseentity = resttemplate.exchange(urifound.touri(), httpmethod.get, entity, customer.class); list<customer> customers = (list<customer>) responseentity.getbody(); list return null, when use rest soapui client return
{ "totalitems": 4, "items": [{ "id": "4052bf1857789c1a", "email": "test@test.com" }, { "id": "4052bf1957789c1a", "email": "test2@test.com" }, { "id": "4052bf2257789c1a", "email": "test3@test.com" }, { "id": "4052bf2157789c1a", "email": "test4@test.com" }] } tips on how meet rest way?
Comments
Post a Comment