mhadley's Blog
WADL-JSON ?
In a recent message to the GData Python Client Library Contributors mailing list, Joe Gregorio outlines a new discovery capability for GData APIs. E.g. here's a document that describes the Buzz API. Look familiar ? To me it looks very much like a JSON version of WADL.
Joe goes on to describe the benefits of this approach and notes that it "allows very lightweight client libraries" and "the actual code for the client is very small". Maybe its time to revisit that Do We Need WADL post ? After all, the criticism levelled at WADL applies equally to this JSON variant.
- Login or register to post comments
- Printer-friendly version
- mhadley's blog
- 2390 reads
Bumper Crop of WADL Tools
Last week saw the release of three new WADL frameworks:
- Python
- WADLLib
- C#
- WADL#
- Ruby
- Ruby client for the Web Application Description Language
Earlier I had committed, but failed to blog about, changes to wadl2java that enable the latest version to read both the current and prior versions of WADL files. This is driven by an XSLT stylesheet filter that updates the previous version to the latest version while leaving the current version intact.
- Login or register to post comments
- Printer-friendly version
- mhadley's blog
- 2596 reads
Comments
jQuery WADL plugin
by bouiaw - 2010-05-17 03:28
In RESThub (http://bitbucket.org/ilabs/resthub/), we have developed a jQuery WADL plugin that generate automatically a WADL test console. It is available at http://bitbucket.org/ilabs/resthub/src/tip/resthub-apps/roundtable/src/m... More documentation to come ...Time for a Change
This week is my last at Oracle, next week I'll be starting a new job with Mitre.
I started looking around for a "Plan B" prior to the Sun acquisition closing in February, mainly due to uncertainty about whether I'd be offerred a position with Oracle. A friend introduced me to an excellent opportunity at Mitre and, after a couple of rounds of interviews and a lot of thought, Plan B morphed into Plan A.
I've enjoyed my short stint with Oracle, it was great to be able to work on Jersey again after 18 months or so doing other things and hopefully the declarative hyperlinking extensions and WADL generation improvements I've been working on will have legs after I leave. I don't know yet whether my new role will afford the opportunity to contribute further to Jersey and/or JAX-RS but I'll be working on the application of open services technologies to national problems so its possible.
I plan to continue blogging here when I can, so stay tuned for the next chapter.
- Login or register to post comments
- Printer-friendly version
- mhadley's blog
- 2840 reads
Comments
Not again!
by cowwoc - 2010-04-30 11:01
Nothing upsets me more than reading about projects I love losing key personnel... Good luck at your new job. I just wish I could clone you :)Best of luck!
by edburns - 2010-06-09 06:38
From what I recall, Mitre is not an IT provider company, more of an engineering company, right?
Congrats
by herkules - 2010-04-30 10:21
Congrats Marc, Mitre looks like a company covering cool topics!
Good luck!
Best of luck
by garypcole - 2010-04-30 08:39
You're aces in my book, Marc. Enjoyed working with you, hope to work with you again.Good luck!
by mmatula - 2010-04-28 02:34
It was a pleasure to work with you. We will miss you. All the best in your future career! MartinBest of luck!
by rtenhove - 2010-04-29 20:14
Marc, It was a pleasure working with you at Sun / Snorcle. I'm sure you'll be doing great things at Mitre. --RonDeclarative HTTP Link Headers
I've extended the declarative hyperlinking module to support the HTTP Link header. It works similarly to the @Link annotation I described earlier except you annotate the response entity class with @LinkHeader (or @LinkHeaders if you need more than one Link header) instead of annotating response entity fields with @Link. Here's a complete example that shows both annotations in action:
@LinkHeader(value=@Link(resource=WidgetResource.class), rel="self")
@XmlAccessorType(XmlAccessType.NONE)
@XmlElement(name="widget")
public class WidgetRepresentation {
@Link(resource=WidgetResource.class)
@XmlAttribute
private String href;
String id;
public WidgetRepresentation(String id) {
this.id = id;
}
public String getId() {
return id;
}
}
Given a resource class:
@Path("widgets/{id}")
public class WidgetResource {
@GET
@Produces("application/xml")
WidgetRepresentation getWidget(@PathParam("id") String id) {
return new WidgetRepresentation(id);
}
}
A GET request for /application/widgets/10 will result in:
HTTP/1.1 200 OK Server: GlassFish v3 Link: </application/widgets/10>;rel="self" Content-Type: application/xml Content-Length: xxx Date: Thu, 18 Mar 2010 21:04:04 GMT <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <widget href="/application/widgets/10"/>
where the bold text is created by the new linking annotations.
- Login or register to post comments
- Printer-friendly version
- mhadley's blog
- 2217 reads
Declarative Hyperlinking Enhancements
I've spent some time fleshing out the code in the experimental declarative hyperlinking module I blogged about earlier. In that earlier entry I showed how you could use the new @Link annotation with existing URI templates either explicitly like this:
@Link("widgets/{id}")
URI link;
or by referencing a resource class @Path annotation value like this:
@Link(resource=WidgetResource.class) URI link;
Expression Language Support
With the latest trunk code you can now use EL in explicit @Link templates, thanks to Ed Burns for helping to get me bootstrapped with the EL APIs. E.g.:
@Link("widgets/${instance.id}")
URI link;
The above would extract the value of the id property of the instance bean. Three beans are currently supported:
instance- The object whose class contains the
@Linkannotation currently being processed. entity- The response entity object returned by the resource class method.
resource- The resource class instance that returned the entity.
Its straightforward to add others but these seemed like a useful set to start with.
Custom Bindings
By default, a URI template parameter is replaced by the value of a same-named property in the current instance. The following two annotations are therefore equivalent:
@Link("{id}")
@Link("${instance.id}")
Custom bindings allow the source of the value of a URI template parameter to be changed, e.g.:
@Link(value="{id}", bindings={
@Binding(name="id", value="${resource.widgetId}")
})
In the above the {id} template parameter will be replaced with the value of the widgetId property of the resource class instance that returned the response. The name property of an @Binding gives the name of a URI template parameter, the value is an EL expression that defines how to get the value of the parameter.
- Login or register to post comments
- Printer-friendly version
- mhadley's blog
- 2225 reads
Comments
one scenario i've run into
by kokaku - 2010-09-21 22:22
one scenario i've run into that i'd like to see addressed - being able to return different uris depending on the request context - for example, if a method returns a list of users, the uri inserted for each user may depend on whether the intention is to associate the user w resource A or B (which would depend on the request context, maybe the referrer path)That should be possible already
by mhadley - 2010-09-22 06:50
That scenario should be possible given that you can call into any getter method on the representation or resource instances. E.g. the resource class could have a method like getContextualUserUri that returns an appropriate computed URI and you could then use @Link("${resource.contextualUserUri}") in the respresentation.
Declarative Hyperlinking in Jersey
One of the areas I'm keen to improve in the next version of JAX-RS is link creation. JAX-RS already offers UriBuilder but I think an annotation driven approach could save a lot of repetitive coding.
I've been experimenting with a couple of annotations that I think would be useful and I just checked in an experimental extension that partially implements what I have in mind. Suppose you have a resource like this:
@Path{"widgets"}
public class WidgetsResource {
...
}
and you want to include a URI to this resource in a representation. Using the new extension you can just annotate a field in your representation class like this:
@Link(resource=WidgetsResource.class) URI link;
and then Jersey will build the appropriate URI and inject it into the representation before the representation is serialized by a message body writer.
If the URI template contains parameters, their values are obtained by looking for a bean property or field by the same name in the representation. E.g. consider the following representation class:
public class WidgetRepresentation {
@Link("widgets/{widgetId}")
URI link;
String getWidgetId() {...}
}
After processing by the extension, if the getWidgetId method returned "abc123", the value of the link field would be /context/widgets/abc123 where context is the deployment context.
The optional style property of the @Link annotation can be used to select between absolute URIs, absolute path and relative path depending on requirements.
Using the Extension
In order to try out the extension you have to:
- Declare a dependency on the new
jersey-server-linkingmodule which is available in Jersey trunk under theexperimentaldirectory. - Install the response filter in your application using an
init-paramin theweb.xmllike this:<servlet> <servlet-name>Jersey Web Application</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>your application packages here</param-value> </init-param> <init-param> <param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name> <param-value>com.sun.jersey.server.linking.LinkFilter</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet>
Next Steps
The Javadoc of the @Link annotation describes a couple of things that I plan to implement next:
- Support for the
@Bindingannotation already sketched out in the code. This will allow the values of template parameters to be pulled from alternate sources including differently named properties of the representation and resource. - Support for EL expressions in link templates. This will allow a little more expressivity for templates that don't already exist as values of
@Pathannotations.
- Printer-friendly version
- mhadley's blog
- 2318 reads
Comments
Great stuff!
by jstrachan - 2010-03-11 04:29
Nice work Marc! I'm liking it. I started a rather long reply and found comments come out as one big assed paragraph, so shot an email to the jersey lists instead :) http://n2.nabble.com/thoughts-on-Link-and-Marc-s-blog-post-td4715173.htm...WADL Submitted to W3C
For those of you who've been patiently waiting for WADL to be submitted to a standards organization, I'm pleased to announce that WADL is now a W3C Member Submission.
The specification submitted to the W3C is a reformatted version of the draft update I blogged about here. If you already switched to that version then you are current. If not, now would be a good time to think about updating to the latest grammar, the changes are fairly minimal but did require a new namespace since they were not backwards compatible.
- Printer-friendly version
- mhadley's blog
- 2574 reads
HATEOAS with WADL
Craig asked me how you would describe something like the Sun Cloud APIs with WADL and I thought others might be interested in the answer. A key feature of the cloud APIs is that they make good use of hypertext as the engine of application state or HATEOAS for (relatively) short. What this means is that rather than documenting a set of URIs and URI templates and relying on the client to construct URIs to access the resource they need, the cloud APIs only publish a single "root" URI and then document where to find additional URIs in representations that clients can use to traverse the service. This is much closer to how a browser user traverses links in web pages. In a recent blog entry Craig describes the advantages of HATEOAS.
So, how to describe this kind of Web application in WADL ? The key is to:
- Use resource types to describe each kind of resource,
- Parameterize representations to identify links embedded within them,
- Define the types of resource each embedded link identifies.
To illustrate I'll use the Sun cloud APIs and the root level representation of the VDC. In WADL we describe this top level resource as follows:
<resources base="http://example.com/"> <resource path="/" type="#vdc"/> </resources>
The above declares a top level resource of type "vdc" at the URI "http://example.com/". Next we need to describe the resource type "vdc":
<resource_type id="vdc">
<method name="GET">
<response status="200">
<representation mediaType="application/vnd.com.sun.cloud.compute.Vdc+json">
<parameter name="attach" path="vms[].attach" style="plain">
<link resource_type="#button"/>
</parameter>
<parameter name="detach" path="vms[].detach" style="plain">
<link resource_type="#button"/>
</parameter>
<parameter name="backup" path="vms[].backup" style="plain">
<link resource_type="#button"/>
</parameter>
...
</representation>
</response>
</method>
</resource_type>
The above says that a representation of resources of type "vdc" can be obtained with GET and that such representations contain links to other types of resources. I've shown three links here but in reality a VDC document contains many more. Each link is contained within a parameter that describes where in the representation the link can be found. In this case each link is to the same type of resource that essentially acts like a push button, here's the description of that resource type:
<resource_type id="button"> <method name="POST"> <response status="204"> </method> </resource_type>
The above says that resources of type "button" only support POST and return an empty 204 response on success.
I've glossed over one important issue related to the use of JSON for the representation of a VDC. If the representation used XML then the value of the path attribute of the parameter element is an XPath and it has semantics for selecting a set of nodes. For JSON theres no such standard path language (that I'm aware of) so I've had to improvise. The "vms" property of the vdc JSON object is an array and the "[]" in the path attribute values is meant to signify that the path will match multiple properties of the JSON object, if anyone has a better idea then let me know.
- Login or register to post comments
- Printer-friendly version
- mhadley's blog
- 2798 reads
Comments
RESTful Semantic Web Services
by otaviofff - 2010-01-08 13:10
Hello Marc. I've just finished my masters thesis on RESTful Semantic Web Services. One of my findings is that WADL can be successfully applied on Semantic Web Services. I would love to receive some feedback from you! http://www.fullsemanticweb.com/blog/ontologies/restfulgrounding/ Thank you very much in advance. Cheers!by mhadley - 2009-05-11 07:40
A method definition element can either be a child of a resource element (a local definition) or a child of the application element (a global definition), sorry if that isn't clear from the spec. You should only include id attributes on global definitions to avoid the issue about how/whether to inherit resource-wide parameters in referenced methods.by otaviofff - 2009-05-09 14:07
Hello Marc. I've been researching on WADL lately, and it's been a great experience. However, recently I've got a doubt on the definition of the method element. The WADL specification says the following (p.9): "id: An identifier for the method, required for globally defined methods, not allowed on locally embedded methods". It doesn't make too much sense to me, because the section 2.7.2 talks about the method definition element, which is a child of a resource element. It means that this method is always a locally embedded one. The section 2.7.1 is the one talking about the method reference element, which is the global one. Could you please help me out here? Thanks! Otavioby kriskam - 2009-06-03 12:39
Hi Marc I am new to REST and WADL stuff and I started using jersey for one of my projects. (jersey-1.1.1.ea-snapshot) I came across lot of articles on wadl particulary using yahoo search api as an example. I understood how to generate client stubs using wadl and wadl2java. But I am not able to understand how an WebApplicationException gets converted to fault element in WADL? For e.g, I have a very simple resource namely Project and it throws EntityNotFoundException (a subclass of WebApplication) . what is the process involved in representing this exception as a fault element in WADL? I took the following steps: Created the Resource 'Project' Created the Exception 'EntityNotFoundException' (subclass of WAE) Used schemagen to generate corresponding xsd's Used wadl-generator to generate wadl from those xsds. However the generated wadl does not contain fault elements like the ones in yahoo search API. Could you please help me figure how to create those fault elements in wadl ? is it a manual process? Thanks in advanceJAX-RS 1.1 Draft Available
A draft of the JAX-RS 1.1 specification and API is now available. We're now working on implementing the new features in Jersey and adding corresponding tests to the TCK. It will be a while before 1.1 can be declared final since there's quite a bit of new functionality, particularly in the areas of integration with Servlet 3.0, EJB 3.1 and JSR 299 - none of which are yet final.
- Login or register to post comments
- Printer-friendly version
- mhadley's blog
- 2547 reads
BYOAPI to Zembly with WADL
Check out this tutorial on the use of WADL to add a service to Zembly. For those not already familiar with Zembly it is:
"An application development environment that not only targets the web as its native platform, but uses cutting-edge web innovations such as web services, social networking, and Web 2.0, to change the way applications are built, deployed, scaled, and delivered to where users congregate."
Essentially any service described by WADL can be easily used within a Zembly application. If you are using Jersey to build your service then support for WADL comes free.
- Login or register to post comments
- Printer-friendly version
- mhadley's blog
- 1105 reads
Comments
BYOAPI to Zembly with WADL
by ubroide - 2011-03-14 05:24
Hi Mark
Can you please indicate where is the latest distribution of wadl2java ??
The current link (http://wadl.java.net/servlets/ProjectDocumentList?folderID=7152&expandFo...) is empty
Thanks
Uri




Comments
WADL-JSON ?
by nikitaattaa - 2011-01-22 03:15
Can you please tell me how to generate proxy classes using WADL path in netbeans
Thanks
WADL-JSON ?
by jcarnegi - 2010-08-09 10:39
That's funny! Good find.