Any workaround for ignoring unexpected elements in Apache Axis 1.4?

后端 未结 3 1333
北恋
北恋 2021-02-19 02:23

The problem was asked before \"Apache AXIS Ignore/Skip additional element while parsing\" in 2012 for Apache Axis 2. Is there no workaround yet for Axis 1.4?

Pro

3条回答
  •  南方客
    南方客 (楼主)
    2021-02-19 02:26

    We always go through this hell due to bad vendors writing these services.

    So, unfortunately, there's no way out using parameters for WSDL2JAVA, BUT there is a workaround, you'll to re-generate stubs at least once:

    1. Replace xs:sequence with xs:all. This allows elements to be returned in any order, and helps fix a lot of cases, as well as generated stub code which makes it easier for step
    2. Sorry, but you for each response bean, you go into its class from the generated code (such as ResponseGetCustomerInfo.java), and instead of this:
    while(!reader.isStartElement() && !reader.isEndElement())
       reader.next();
    
    if(reader.isStartElement())
    // A start element we are not expecting indicates a trailing invalid
    // property
    throw new org.apache.axis2.databinding.ADBException("Unexpected subelement " + reader.getLocalName());
    

    Have this:

    while(!reader.isStartElement() && !reader.isEndElement())
       reader.next();
    
    // if(reader.isStartElement())
    // A start element we are not expecting indicates a trailing invalid
    // property
    
    // The below is commented, to prevent unexpected result parameters from causing an exception
    // (As well as the condition above is removed)
    //  throw new org.apache.axis2.databinding.ADBException("Unexpected subelement " + reader.getLocalName());
    

    It's tested and works at least better than no solution.

提交回复
热议问题