Saturday, February 13. 2016
spml4jaxb - First Version
As you now I was developing a new library to cover the SPMLv2 standard in Java. Finally I decided to release the first version of the spml4jaxb project (I suppose is not complete yet but it is useful). The library is based on JAXB and all the definitions provided by the standard have been incorporated into it. (All the XSD files provided by OASIS have been parsed using the xjc command and transformed into JAXB classes.) Remember that this project was born because the previous SPMLv2 series in this blog.
The main target of the library is providing an easy way for clients to send and receive the SPMLv2 data. For that reason I decided to use a wrapper approach. The parsed classes (JAXB generated) are not used directly but wrapped. There are two different wrappers: builders (wrapper to create / write requests or responses) and accessors (wrapper to receive / access them). The library uses generics a lot too.
Comparing with the old OpenSPML, spml4jaxb provides DSML and XSD interfaces and gives an easier way of constructing the requests and responses. I like to present the difference between the two libraries with a modification DSML example.
Using OpenSPML:
Spml2Client client = new Spml2Client("http://localhost:8080/SpmlServlet/rpcrouter2"); ModifyRequest mr = new ModifyRequest(); mr.setRequestID("mr1"); mr.setExecutionMode(ExecutionMode.SYNCHRONOUS); psoId = new PSOIdentifier("ricky", null, "ddbb-spml-dsml"); mr.setPsoID(psoId); wrapper = new Modification(); DSMLModification dsmlmod = new DSMLModification("description", "me", ModificationMode.DELETE); wrapper.addOpenContentElement(dsmlmod); dsmlmod = new DSMLModification("password", "ricky123", ModificationMode.REPLACE); wrapper.addOpenContentElement(dsmlmod); dsmlmod = new DSMLModification("role", "Admin", ModificationMode.DELETE); wrapper.addOpenContentElement(dsmlmod); dsmlmod = new DSMLModification("role", "Test", ModificationMode.ADD); wrapper.addOpenContentElement(dsmlmod); mr.addModification(wrapper); ModifyResponse ms = (ModifyResponse) client.send(mr);
Using spml4jaxb:
SOAPClient client = new SOAPClient("http://localhost:8000/rpcrouter2"); ModifyResponseAccessor mra = RequestBuilder.builderForModify() .requestId("mr1") .synchronous() .psoId("ricky") .psoTargetId("ddbb-spml-dsml") .dsmlDelete("description", "me") .dsmlReplace("password", "ricky123") .dsmlDelete("role", "Admin") .dsmlAdd("role", "Test") .send(client);
I think the difference is clear, the new library constructs the request and sends it in an easier and faster way. Builders use their typical chaining of methods to add all the necessary properties in the request. Some operations have real complex properties (like a filter in a DSML search request), the library provides more builders for those properties. The accessor then also gives better methods to check the received data in the response.
In general the current status of the library is the following:
Support for all the defined capabilities in the SPMLv2 standard (except the reference capability which is not wrapped).
Several clients developed (simple SOAP, SOAP with WSSE username and plain password, SOAP with basic authentication,...).
Skeleton to make the server implementation based on a Servlet.
Example for extending the library with a custom capability.
Sample server implementation for a in-memory user repository (based on hsqldb).
Good unitary test unit with the sample server.
If you are interested in using SPMLv2 in Java (quite rare standard as you know), please give a try to my little library.
cheerio!
Comments