Archive for August, 2011

New Registry Version 4.1.6

There has been a registry update highlights below:

 

* json responses for web service if accept header = application/json. The exact format of the json response is currently subject to change.

* multiple parameters for the same type are now accepted for e.g. capabilities=features;capabilities=types; returning sources with either features or types

* select active or inactive or both sources using the active=true, active=false or active=any, default is active only

* lists and links to rng files at http://www.dasregistry.org/validation1.6/ http://www.dasregistry.org/validation/

 

Code:

The registry web service code is now self contained and is it’s own project hosted here: http://code.google.com/p/das-registry-web-service/source/browse/ it uses the Spring REST mvc framework, JAXB2 and the Jackson JSON library. Also maven.

 

The new registry rest service uses the JDAS project which is here: http://code.google.com/p/jdas/ . This project has object models generated from the relaxng schema files and thus has an easy to use model that follows the structure of the documents. These objects also have JAXB2 annotations that enables the immediate use of more standard Java libraries like spring REST and the Jackson library.

 

To make a json request you can for example make a request to http://www.dasregistry.org/das/sources after setting the “accept” header in the request to “application/json”. A simple REST client can be downloaded for free from here:

http://rest-client.googlecode.com/

 

 

Configuration for REST spring mvc with Jackson json mapper omitting null properties

Putting this configuration into my spring res-mvc-config.xml changed the json responses so that null properties are not written. To make this changes have an effect you have to get rid of any mvc:annotation-driven element as this stops the overriding having an effect. no errors will be thrown, so it’s not easy to see what is going on or not going on 😉

<<?xml version=”1.0″ encoding=”UTF-8″?>
<beans xmlns=”http://www.springframework.org/schema/beans&#8221;
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
xmlns:context=”http://www.springframework.org/schema/context&#8221;
xmlns:jdbc=”http://www.springframework.org/schema/jdbc&#8221;
xmlns:mvc=”http://www.springframework.org/schema/mvc&#8221;
xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd”&gt;

<context:component-scan base-package=”uk.ac.sanger.das.dasregistry.springrest.sources”></context:component-scan>

<context:component-scan base-package=”uk.ac.sanger.das.dasregistry.springrest.coordinates”></context:component-scan>
<!– <mvc:annotation-driven/> –>

<bean
>
<property name=”messageConverters”>
<list>
<bean> </bean>
<bean>
<property name=”objectMapper” ref=”jacksonObjectMapper” />
</bean>
</list>
</property>
</bean>

<!– jackson configuration : http://stackoverflow.com/questions/3661769 –>
<bean id=”jacksonObjectMapper” />
<bean id=”jacksonSerializationConfig”
factory-bean=”jacksonObjectMapper” factory-method=”getSerializationConfig” />
<bean
>
<property name=”targetMethod” value=”setSerializationInclusion” />
<property name=”targetObject” ref=”jacksonSerializationConfig” />
<property name=”arguments”>
<list>
<value type=”org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion”>NON_NULL</value>
</list>
</property>
</bean>

</beans>

Mapping urls to a jsp

I have a directory with some schema files in that I wanted to list for people to see. The old tomcat would list them if you went to the directory e.g. http://www.dasregistry.org/validation1.6/ there were a few forums where various answers to how to do this came up top in google, but they weren’t very simple. The simplest being to create a servlet to redirect to the jsp from your desired urls, simple but not very quick. I knew there had to be a quicker way as jsps are compiled into servlets anyway!

I found an article here http://www.xyzws.com/JSPfaq/how-to-config-a-jsp-file-in-webxml/2 which is what I wanted and it’s pretty easy.

<servlet>
<servlet-name>myjsp</servlet-name>
<jsp-file>/myjsp.jsp</jsp-file>
<init-param>
<param-name>hello</param-name>
<param-value>test</param-value>
</init-param>
</servlet>
 
<servlet-mapping>
<servlet-name>myjsp</servlet-name>
<url-pattern>/myjsp</url-pattern>
</servlet-mapping>

so for my directory listing url I used these mappings to allow access through the directory with and without the last slash:

<servlet>

<servlet-name>relaxng1.6</servlet-name>

<jsp-file>/validation1.6/relaxng.jsp</jsp-file>

</servlet>

 

<servlet-mapping>

<servlet-name>relaxng1.6</servlet-name>

<url-pattern>/validation1.6</url-pattern>

</servlet-mapping>

<servlet-mapping>

<servlet-name>relaxng1.6</servlet-name>

<url-pattern>/validation1.6/</url-pattern>

</servlet-mapping>

Generating Java classes from relaxng

We convert our relaxngs to xsd using trang and then use xjc to create java objects.

locate trang, you will likely have this already if you have spring or eclipse

run trang like this:

java -jar /Users/jw12/trang-20091111/trang.jar sources.rng sources.xsd

find xjc on your system, if you use java you are likely to have xjc already: locate xjc

the one I’m using came with netbeans /Applications/NetBeans/glassfish-3.0.1/glassfish/bin/xjc

use xjc on the xsd file just generated specifying the package with -p:

sh /Applications/NetBeans/glassfish-3.0.1/glassfish/bin/xjc sources.xsd -p org.biodas.jdas.schema.sources

Note that because relaxng is much more descriptive than xsd conflicts and approximations may occur. We removed interleave elements from the rng schemas for generating our java classes so that we didn’t have to test for different types when using the generated java classes. this is because interleave means the classes don’t know if the list of child elements is going to contain a specific type of object as the objects can occur in any order – thus generating a for example getMaintanerOrCoodinate() method. We want seperat getMaintainer() and getCoordinate() methods and removing interleave does that. In the DAS specification it doesn’t specify whether the child elements should be returned in order, however the official W3C xml core data model characterizes element children as:

An ordered list of child information items, in document order. This list contains element….

WE also believe the vast majority of xml writers will produce the elements in order…