Apache CXF Rest Client Clarity -


my requirement use apache cxf rest client api vendor has provided url http://test.com

method: url: /getdetails header set application/json , parameter z=12345 

and response json:

{   "hasmore": "true",   "results": [     {       "name": "atm: 16th & treemont",       "phone": "(303) 249--‐9117",       "streetaddress": "303 16th st. suite 100"     },     {           "name": "atm2:17th & fremont",       "phone": "(555) 999-98886",       "streetaddress": "304 17th st. suite 200"     }   ] } 

when read documentation client api see link: http://cxf.apache.org/docs/jax-rs-client-api.html#jax-rsclientapi-cxfwebclientapi webclient approach: if go example, describes book() how describe book object requirement?

webclient client = webclient.create("http://books"); client.path("bookstore/books"); client.type("text/xml").accept("text/xml") response r = client.post(new book()); book b = r.readentity(book.class);    

also see usage of proxy: talks bookstore.class ..wont server object? if not able create or have bookstore class or object @ end.

bookstore store = jaxrsclientfactory.create("http://bookstore.com", bookstore.class); // (1) remote call http://bookstore.com/bookstore books books = store.getallbooks(); // (2) no remote call bookresource subresource = store.getbooksubresource(1); // {3} remote call http://bookstore.com/bookstore/1 book b = subresource.getbook(); 

should create object similar book() response? have read each value json response (jettison). approach should follow reqruiement , how should proceed. confused please advice.

my requirement strict use apache cxf rest api.

yes. create plain pojo model on client end similar entity class @ server end same fields needed. json can marshaled directly objects.

let use book model

to retrieve book object id of 1:

webclient client = webclient.create("http://localhost:8084/appname/rest/");  book book = client.path("book/" + 1 ).accept("application/json").get(book.class); 

to retrieve book objects:

webclient client = webclient.create("http://localhost:8084/appname/rest/");   set<book> books = new hashset<book>(client.path("books/all").accept("application/json").getcollection(book.class)); 

post book object:

webclient client = webclient.create("http://localhost:8084/appname/rest/");  book book = new book();  book.setauthor("shiv);  book.setpublisheddate(new date());  client.path("/book-post");  client.post(book); // persist object 

update book object

webclient client = webclient.create("http://localhost:8084/appname/rest/");  book book = client.path("book/" + 1 ).accept("application/json").get(book.class);  book.setauthor("gopal);  book.setpublisheddate(new date());  client.back(true);  client.path("/book-put");  client.put(book);// update book object 

nb

the client.back(true) reverts rest api endpoint address

the client.path(string) appends string value endpoint address


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

mysql - Pass value between different pages (form) with PHP -