Showing posts with label wink. Show all posts
Showing posts with label wink. Show all posts

Tuesday, March 2, 2010

Apache Wink - Dynamic Resources

Quite often people ask me what is so different about Apache Wink, and why another JAX-RS framework. Usually I answer that Apache Wink started in HP long before there was any REST open-source framework. It was developed internally for two years before joining Apache.

This may be interesting from historical point of view, but then people ask: so why should we use it now? Are there any unique features?
And the answer here is: yes, there are some unique features beyond the JAX-RS spec and this post will describe one of the most cool features (IMO) that Wink contains:

Dynamic Resources


The idea of Dynamic Resource is quite similar to Template pattern and it's simple: many resource classes have more or less the same logic. However, they manipulate different entities, so obviously they have different URLs.

Consider the following example: a resource that simply a facade to the database - it allows the CRUD operation and it uses Hibernate as the persistence layer.

So basically the template class will look something like this:

public class CrudResource {

private Session session;
@Context
private UriInfo uriInfo;

private Class clazz;

@GET
public Object getEntity(@PathParam("id") String id) {
return session.get(clazz, id);
}

@POST
public Response createEntity(Object newEntity) {
session.save(newEntity);
String id = newEntity.getId(); // this line will not compile, but the idea is that id is assigned by hibernate
URI location = uriInfo.getAbsolutePathBuilder().segment(String.valueOf(id)).build();
return Response.created(location).build();
}

@PUT
public void updateEntity(Object entity) {
session.update(entity);
}

@DELETE
public void delete(@PathParam("id") String id) {
session.delete(session.get(clazz, id));
}

}

Notice: This class doesn't contain the full logic, like transaction management, and won't even compile. It should provide the idea how to implement the "template" style resource and not how to really work with Hibernate or even Wink.

So as you can see, this class can basically perform the CRUD operations on any entity. It would be a pity, if for each entity, we'll need to extend this class just to assign a different path. And here come the Dynamic Resources. They allow to skip the @Path annotation and implement the DynamicResource interface instead (or extend from the AbstractDynamicResource class).

So now our resource will look something like this:
public class CrudResource extends AbstractDynamicResource  {
...
}

Now it's possible to create multiple instances of this class and assign it a different paths and other members (like 'clazz', which should hold the value of actual class).

Notice: Dynamic Resources can be returned only by Application.getSingletons() method. Thus these resources are actually singletons and must be coded accordingly (for example think about synchronization issues).

Spring Integration


Wink contains the Spring Integration extension. I won't describe its features here, but only want to mention the usage of Dynamic Resources with Spring.
First, Dynamic Resource can be defined and registered via Spring Context, thus you can create new resources using the same class, while updating the configuration only. Pretty nice feature, when you think about it.
Second, Dynamic Resources benefit from different scopes. Meaning, they may not be singletons anymore.

Thursday, November 12, 2009

Wink 1.0-incubating Release

So finally Wink 1.0 is released. This release contains quite a lot of fixes (including many performance fixes) and also some features.
For the complete list of issues, see the release notes.

Thursday, August 27, 2009

Wink 0.1-incubating Release

After almost 4 weeks of delay, I'm happy to announce that Apache Wink 0.1-incubating was released.
Don't let the version name to mislead you, it's actually the second major version of the REST framework that is developed internally by HP team for the last two years.
After this framework was chosen to become an initial code base for the Apache Wink project, the version became "0.1-incubating", but actually it ought to be "2.0". So it's mature enough to be used by any production application.

This release contains the client and server sides with some extensions:
Client: Apache Http Client
Server: Spring, WebDAV

The Server side is JAX-RS (JSR-311) 1.0 compliant and passed the relevant TCK tests.

Download Apache Wink

Feel free to ask any questions at Apache Wink User mailing list. Or at the comments to this post.

Enjoy!

Wednesday, August 12, 2009

Apache Wink on Google App Engine

Today I tried to run the Apache Wink on the Google App Engine. It worked quite seamlessly. I only needed to add a slf4j-jdk14 bridge for logging and it just worked.
The only disappointment is about the lack of support of JAXB by the Google App Engine.
JAXB is used quite widely by the Apache Wink and is required by the JAX-RS (JSR-311) spec. We have based some of important functionality on JAXB: for example Atom and Json support is based on JAXB. So these providers won't work. But everything else I tried till now, works quite fine.

Thursday, July 30, 2009

Apache Wink Site

I'm glad to announce that Apache Wink has finally an official site.

It would be great if you share this information, so the search engines would be able to increase the site's rating.

Here are some links to Apache Wink's site: Apache Wink JAXRS implementation JAX-RS implementation JAX RS implementation JSR-311 implementation JSR 311 implementation JSR311 JSR 311 JSR-311 JAX-RS JAXRS JAX RS

Tuesday, July 7, 2009

Wink is in the Air

So Wink is in the air! Well, almost...
Till now it was accepted as Apache Incubator project and HP's implementation was selected as the code base, which were the great news for our team :)
During the previous week a lot of small bugs were found and fixed to make the code JAX-RS (JSR 311) compliant and even more, so basically I think that Wink is ready for 0.1 release. Hopefully we'll succeed to release it till the end of July.

Tuesday, April 28, 2009

Wink

And here comes a Wink proposal.
The discussion has started and I hope that the project is going to be approved in the following few weeks.