Пример #1
0
  public XmlElement generateSoapFault(
      XmlNamespace faultCodeValueNs,
      String faultCodeValueName,
      String reasonTextEnglish,
      Throwable ex)
      throws XsulException {
    XmlElement faultEl = builder.newFragment(SOAP11_NS, "Fault");
    if (!NS_URI_SOAP11.equals(faultCodeValueNs.getNamespaceName())) {
      faultEl.declareNamespace("n", faultCodeValueNs.getNamespaceName());
    }

    XmlElement faultCodeEl = faultEl.addElement("faultcode");
    faultCodeEl.addChild(
        new QNameElText(faultCodeEl, faultCodeValueNs.getNamespaceName(), faultCodeValueName));
    if (reasonTextEnglish == null) reasonTextEnglish = "{null}";
    faultEl.addElement("faultstring").addChild(reasonTextEnglish);

    XmlElement detail = faultEl.addElement("detail");
    if (ex != null) {
      final XmlNamespace axisNs = faultEl.newNamespace("n", "http://xml.apache.org/axis/");

      String msg = ex.getMessage();
      if (msg != null) {
        XmlElement exName = detail.addElement(axisNs, "exceptionName");
        exName.declareNamespace(axisNs);
        exName.addChild(msg);
      }
      XmlElement stackTrace = detail.addElement(axisNs, "stackTrace");
      stackTrace.declareNamespace(axisNs);
      StringWriter sw = new StringWriter();
      ex.printStackTrace(new PrintWriter(sw));
      stackTrace.addChild(sw.toString());
    }

    return faultEl;
    // XmlDocument envelope = wrapBodyContent(faultEl);

    //        // resolve prefix to use in fault code (it MUST be done after SOAP:Envelope is
    // constructed!
    //        XmlNamespace ns = faultCodeEl.lookupNamespaceByName(faultCodeNs);
    //        if(ns == null || ns.getPrefix() == null) {
    //            // declare prefix if does nto exist
    //            final XmlNamespace faultNs = builder.newNamespace("ns", faultCodeNs);
    //            ns = faultCodeEl.declareNamespace(faultNs);
    //        }
    //        String faultcode = ns.getPrefix() + ':' + faultCodeName;
    //        faultCodeEl.addChild(faultcode);

    // return envelope;
  }