Hi there,
   I'm trying to create custom detail messages to indicate the nature of
request faults, so that they can appropriately be handled on the client
side.  I've been told by Those Who Know that I shouldn't use anything beyond
Client or Server in the faultcode to be compatible with the Basic Profile,
so I need to pass details in.. well, the details.
 
   Everything is fine, except that I was also told to use a custom namespace
for the tags in the detail, to avoid collisions.  Fair enough, and here's my
utility method to create the AxisFault:
 
    static final String NS = "http://benefit-systems.com/faults/exceptions";;
    static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/";;
    private AxisFault generateAxisFault(String type, String desc, String
errorName, String errorDetail) {
        String where = "http://secure.benefit-systems.com";;
            DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
        DocumentBuilder db = null;
        try {
            db = dbf.newDocumentBuilder();
        } catch (ParserConfigurationException e) {
            e.printStackTrace(); 
        }
        Document doc = db.newDocument();
        Element error = doc.createElementNS(NS, "e:error");
        doc.appendChild(error);
        error.setAttributeNS(XMLNS_NS, "xmlns:e", NS);
        Element errorcode = doc.createElementNS(NS, "e:errorcode");
        error.appendChild(errorcode);
        errorcode.appendChild(doc.createTextNode(errorName));
        Element errordetail = doc.createElementNS(NS, "e:errordetail");
        error.appendChild(errordetail);
        errordetail.appendChild(doc.createTextNode(errorDetail));
        Element[] detail = {error};
        AxisFault fault = new AxisFault(type, desc, where, detail);
        return fault;
    }

Unfortunately, in spite of all the messing around with namespaces, what
comes out is:

<soapenv:Envelope>
  <soapenv:Body>
    <soapenv:Fault>
      <faultcode>ns1:Client</faultcode>
      <faultstring>Bad Username or Password</faultstring>
      <faultactor>http://secure.benefit-systems.com</faultactor>
      <detail>
        <e:error>
          <e:errorcode>Authentication</e:errorcode>
          <e:errordetail/>
        </e:error>
      </detail>
     </soapenv:Fault>
   </soapenv:Body>
</soapenv:Envelope>

One will notice the conspicuous lack of an xmlns field.  Searching on the
web, it seems like everybody has the same problem with Xerces in general.
Any ideas?  I suppose I could generate the wrapping error tag using non-XML
methods to force the xmlns line, but that's gross.

Reply via email to