Namespace customization in easyWSDL…
Publié par mbeldame dans Non classé, tags: easyWSDLWhen using the easyWSDL toolbox, and specially the Java2easyWSDL tool provided, the namespaces prefixes are automatically generated (ns1, ns2, …). The second problem is that some namespaces, not declared in the root element are repeated in all the other elements.
The generated wsdl was totally correct, but not human readable. It does not cause any problem when the wsdl is only read by a tool (to generate stub), but becomes problematic when people want to read it directly…
The solution proposed by jaxb2, is to extend the class com.sun.xml.bind.marshaller.NamespacePrefixMapper in a custom class.
In this class, the following methods can be overwriten:
public String getPreferredPrefix(String namespaceUri, String suggestion,boolean requirePrefix) -> to return the prefered prefix for a particular namespace :
if (namespaceUri.equals(“http://schemas.xmlsoap.org/wsdl/soap12/”))
return “soap12″;
public String[] getPreDeclaredNamespaceUris() -> to specify some couples of prefix/namespace to force jaxb to declared them in the root element of the generated XML:
return new String[] {“custNS”,”http://foo.bar/”};
I can now set an instance of this class as a Property of the marshaller used:
NamespacePrefixMapper mapper = new CustomPrefixMapper();
marshaller.setProperty(“com.sun.xml.bind.namespacePrefixMapper”, mapper);
Each time the marshaller will need to get a prefix for a namespace, it will ask your CustomPrefixMapper. If this one returns a prefix, it will be used, in the other case, a generated prefix (nsX) will be used.
The end of the process was to integrate it in easyWSDL, and to provide the WSDLwriter two new methods taking avantage of this mechanism:
/**
* Use normalized prefixes for namespace declaration. Add
* some custom prefixes if needed.
*
* @param customPrefixes
* array containing custom prefixes and namespaces to use
* with the format : (prefix1,nsUri1,prefix2,nsUri2,…)
*/
public void useCustomNamespacesPrefixes(String[] customPrefixes)throws WSDLException ;
/**
* Use normalized prefixes for namespace declaration.
*/
public void useNormalizedNamespacesPrefixes() throws WSDLException;
Mathias
Bulletins (RSS)
[...] mbeldame on fév.13, 2009, under Non classé The main goal of the modifications in easyWsdl previously described was to improve the WSDL generated by Java2easyWSDL, and its ant task. So, the Main class of [...]