Using Abdera and the Jersey Client API
Marc recently published a short
tutorial on how to use Apache Abdera with Apache
Abdera with our reference implementation of JAX-RS, Jersey. His code is server side, i.e.
it explains using Jersey and Abdera for creating RESTful web services with
Atom payload[1]. In this article I will give an example on how the
Jersey client API can be used to consume such a service with realitve ease.
It is hopefully known that Jersey contains a very simple, yet effective
HTTP client API. Core to it is the heavy use of the builder pattern for
creating and configuring requests. For our example, I start with creating the
client:
Client c = Client.create();
WebResource r = c.resource(new URI(someLocation));
We can now get the InputStream from the WebResource to read the Atom feed
into an Abdera Feed:
InputStream is = (InputStream) r.get(InputStream.class);
Document<Feed> doc = Abdera.getNewParser().parse(is);
Feed feed = doc.getRoot();
for (Entry entry : feed.getEntries()) {
doSomething(entry);
}
Now let's say we want to post an entry to the resource in Marc's article.
In this case we would also have to use his AbderaSupport class, which
implementes the proper MessageBodyReader
and MessageBodyWriter
interfaces for the Abdera objects. On the server side providing these
interfaces is enough, but on the client side we need to configure the Jersey
client. The following code helps doing this:
public static class AbderaClientConfig extends DefaultClientConfig {
@Override
public Set<Class<?>> getProviderClasses() {
Set<Class<?>> classes = new HashSet<Class<?>>();
classes.add(AbderaSupport.class);
return classes;
}
}
Thus completing our sample app:
ClientConfig cf = new AbderaClientConfig();
Client c = Client.create(cf);
WebResource r = c.resource(new URI(someLocation));
Entry entry = AbderaSupport.getAbdera().newEntry();
entry.setTitle(...);
entry.setContent(...);
ClientResponse cr = r.type(MediaType.APPLICATION_XML).put(ClientResponse.class, entry);
Done.
tags:
Jersey Apache Abdera Atom JAX-RS [1] Tim pointed
out that this style should properly called "AtomPub", and not APP,
AtomPub/Sub or similar.
Posted at
06:43PM Jul 18, 2008
by beuchelt in General |
VRM Workshop 2008
This week's VRM Workshop at the Berkman Center in Cambridge, MA was quite interesting. It helped me quite a bit to sort out how Identity Management and VRM intersect, but also differ in some respect. To put it in a nutshell, I believe that the biggest difference between the two is that they are essentially two different ways of looking at the same problem. "Traditional" identity management has been focusing largely on the varies subjects (and objects), their characterization, and how they can be mapped to digital artifacts. VRM seems to be taking a more procedural approach by focusing more on the processes and interactions of these subjects, objects, and digital artifacts. In this sense, VRM and identity management are very much complimentary.
You can find more information about Doc Searls ideas about VRM on the Berkman wiki and on his blog.
vrm2008
Posted at
01:15PM Jul 18, 2008
by beuchelt in General |
OpenSocial and Liberty
OpenSocial and Liberty People Services are really tackling the same problem - only from two opposing sites. While the LAP PS has established a solid foundation for secure identity management, OpenSocial has started out to define an API for allowing social networking (but also other) software from different source to be run in one (or more than one) container. Ideally, these container abstract away the underlying platform and thus enable application portability. This becomes quite useful, since facebook, MySpace, Orkut, etc. have extremely similar types of applications (friends/relationships, photo sharing, contact management, and many more). Having these applications being portable across different allows application developers to focus more on added functionality and less on platform plumbing.
Liberty - on the other hand - has created the necessary infrastructure to enable individuals to set preferences and share information about themselves with other in a secure and privacy preserving way. The protocols used in ID-WSF and people service (and not APIs) can enable containers to communicate with others based on user's policies and requests.
libertyalliance opensocial
Posted at
01:09PM Jul 18, 2008
by beuchelt in General |