55
I have been working on a REST web service using Jersey for a few days now, and managed to have all CRUD operations working, with several exchange formats: XML, JSON, Google Protobuf.
However I am facing some issues related to automatically generated WADL and XSD.
Context
To define the objects exchanged in these three formats, I have followed a "contract-first" approach:
- from a XSD I wrote, I generated my model classes using JAXB;
- from an equivalent proto file I wrote, I generated the Google Protobuf classes (and internally have a way to convert these to the JAXB-generated objects, in order to have one unique model).
However, as I would like my users to be able to generate their classes too, I would like to share these schema files (.xsd and .proto) and have them well integrated with the automatically generated WADL.
For that purpose, thanks to this wiki page:
- I have exposed the two files under
/schema/schema.xsd/schema/schema.proto
I have added an application-grammar file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <grammars xmlns="http://wadl.dev.java.net/2009/02" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xi="http://www.w3.org/1999/XML/xinclude"> <include href="../schema/schema.xsd" /> </grammars>I have added a customized WADL generator:
public class RichWadlGeneratorConfig extends WadlGeneratorConfig { @Override public List<WadlGeneratorDescription> configure() { return generator(WadlGeneratorApplicationDoc.class) .prop("applicationDocsStream", "application-doc.xml") .generator(WadlG