Paul Sandoz wrote:
> Later today i will respond with a plug for the client API :-) to
> contrast with the Apache API. Just making some tweaks to form stuff to
> make it easier to use on the client side.
>
Better late than never...
Client c = Client.create();
WebResource r = c.resource("
http://localhost:8081/rest/profiles");
Profile pro = new Profile();
pro.setFirstName("Scooby");
pro.setLastName("Doo");
JAXBContext jaxbContext = JAXBContext.newInstance(Profile.class);
Marshaller marshaller = jaxbContext.createMarshaller();
StringWriter writer = new StringWriter();
marshaller.marshal(pro, writer);
Form f = new Form();
f.add("p", writer.toString());
f.add("x", "sooby_at_doo.com");
// This assumes that the status must be 200 otherwise an
// exception is thrown
String response = r.path("test").post(String.class, f);
// Obtain the response status, meta-data and, entity
ClientResponse cr = r.path("test").post(ClientResponse.class, f);
int status = cr.getStatus();
response = cr.getEntity(String.class);
You can see how it is easy to reuse WebResource. Notice that i created
the resource from the URI "
http://localhost:8081/rest/profiles", but i
can append paths before making an invocation on the uniform interface.
If/when we get form beans we can do this:
Profile pro = new Profile();
pro.setFirstName("Scooby");
pro.setLastName("Doo");
FormBean fb = new FormBean(p, "sooby_at_doo.com");
String response = r.path("test").post(String.class, fb);
The client API reuses the same message body readers/writer
infrastructure as on the server side (and also the IoC related stuff too).
I want too hook things up so one could inject a Client or a WebResource
instance onto resource classes so that the server side can easily and
efficiently make requests to other services (we can use Grizzly to make
things scale efficiently for both server and client requests).
Paul.
--
| ? + ? = To question
----------------\
Paul Sandoz
x38109
+33-4-76188109