java - How can I get Axis 1.4 to not generate several prefixes for the same XML namespace? -


i receiving soap requests client uses axis 1.4 libraries. requests have following form:

<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"                    xmlns:xsd="http://www.w3.org/2001/xmlschema"                    xmlns:xsi="http://www.w3.org/2001/xmlschema-instance">   <soapenv:body>     <placeorderrequest xmlns="http://example.com/schema/order/request">       <order>         <ns1:requestparameter xmlns:ns1="http://example.com/schema/common/request">           <ns1:orderingsystemwithdomain>             <ns1:orderingsystem>internet</ns1:orderingsystem>             <ns1:domainsign>2</ns1:domainsign>           </ns1:orderingsystemwithdomain>         </ns1:requestparameter>         <ns2:directdeliveryaddress ns2:addresstype="0" ns2:index="1"                                     xmlns:ns2="http://example.com/schema/order/request">           <ns3:address xmlns:ns3="http://example.com/schema/common/request">             <ns4:zipcode xmlns:ns4="http://example.com/schema/common">12345</ns4:zipcode>             <ns5:city xmlns:ns5="http://example.com/schema/common">city</ns5:city>             <ns6:street xmlns:ns6="http://example.com/schema/common">street</ns6:street>             <ns7:housenum xmlns:ns7="http://example.com/schema/common">1</ns7:housenum>             <ns8:country xmlns:ns8="http://example.com/schema/common">xx</ns8:country>           </ns3:address> [...] 

as can see, several prefixes defined same namespace, e.g. namespace http://example.com/schema/common has prefixes ns4, ns5, ns6, ns7 , ns8. long requests define several hundred prefixes same namespace.

this causes problem saxon xslt processor, use transform requests. saxon limits the number of different prefixes same namespace 255 , throws exception when define more prefixes.

can axis 1.4 configured define smarter prefixes, there 1 prefix each namespace?

i have same issue. moment, i've worked around writing basichandler extension, , walking soappart myself , moving namespace reference parent node. don't like solution, seem work.

i hope comes along , tells have do.

edit

this way complicated, , said, don't @ all, here go. broke functionality few classes (this wasn't manipulation needed in project, there other implementations) hope can fix soon. uses dom4j process xml passing through soap process, you'll need dom4j make work.

public class xmlmanipulationhandler extends basichandler { private static log log = logfactory.getlog(xmlmanipulationhandler.class); private static list processinghandlers;  public static void setprocessinghandlers(list handlers) {     processinghandlers = handlers; }  protected document process(document doc) {     if (processinghandlers == null) {         processinghandlers = new arraylist();         processinghandlers.add(new emptyprocessinghandler());     }     log.trace(processinghandlers);     treewalk(doc.getrootelement());     return doc; }  protected void treewalk(element element) {     (int = 0, size = element.nodecount(); < size; i++) {         node node = element.node(i);         (int handlerindex = 0; handlerindex < processinghandlers.size(); handlerindex++) {             processinghandler handler = (processinghandler) processinghandlers.get(handlerindex);             handler.process(node);         }         if (node instanceof element) {             treewalk((element) node);         }     } }  public void invoke(messagecontext context) throws axisfault {     if (!context.getpastpivot()) {         soapmessage message = context.getmessage();         soappart soappart = message.getsoappart();         bytearrayoutputstream baos = new bytearrayoutputstream();          try {             message.writeto(baos);             baos.flush();             baos.close();              bytearrayinputstream bais = new bytearrayinputstream(baos.tobytearray());             saxreader saxreader = new saxreader();             document doc = saxreader.read(bais);             doc = process(doc);             documentsource ds = new documentsource(doc);             soappart.setcontent(ds);             message.savechanges();         } catch (exception e) {             throw new axisfault("error caught processing document in xmlmanipulationhandler", e);         }     } }  }   public interface processinghandler {     public node process(node node); }   public class namespaceremovalhandler implements processinghandler { private static log log = logfactory.getlog(namespaceremovalhandler.class); private namespace namespace; private string targetelement; private set ignoreelements;  public namespaceremovalhandler() {     ignoreelements = new hashset(); }  public node process(node node) {     if (node instanceof element) {         element element = (element) node;         if (element.isrootelement()) {             // evidently, never see root node when we're called             // soap...         } else {             if (element.getname().equals(targetelement)) {                 log.trace("found target element.  adding requested namespace");                 namespace = element.getnamespaceforuri(namespace.geturi());                 if (already == null) {                     element.add(namespace);                 }             } else if (!ignoreelements.contains(element.getname())) {                 namespace target = element.getnamespaceforuri(namespace.geturi());                 if (target != null) {                     element.remove(target);                     element.setqname(new qname(element.getname(), namespace));                 }             }             attribute type = element.attribute("type");             if (type != null) {                 log.trace("replacing type information: " + type.gettext());                 string typetext = type.gettext();                 typetext = typetext.replaceall("ns[0-9]+", namespace.getprefix());                 type.settext(typetext);             }         }     }      return node; }  public namespace getnamespace() {     return namespace; }  public void setnamespace(namespace namespace) {     this.namespace = namespace; }  /**  * @return targetelement  */ public string gettargetelement() {     return targetelement; }  /**  * @param targetelement targetelement set  */ public void settargetelement(string targetelement) {     this.targetelement = targetelement; }  /**  * @return ignoreelements  */ public set getignoreelements() {     return ignoreelements; }  /**  * @param ignoreelements ignoreelements set  */ public void setignoreelements(set ignoreelements) {     this.ignoreelements = ignoreelements; }  public void addignoreelement(string element) {     this.ignoreelements.add(element); } } 

no warranty, etc, etc.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -