Example usage for javax.xml.soap DetailEntry setValue

List of usage examples for javax.xml.soap DetailEntry setValue

Introduction

In this page you can find the example usage for javax.xml.soap DetailEntry setValue.

Prototype

public void setValue(String value);

Source Link

Document

If this is a Text node then this method will set its value, otherwise it sets the value of the immediate (Text) child of this node.

Usage

From source file:it.cnr.icar.eric.server.interfaces.soap.RegistryBSTServlet.java

private SOAPMessage createFaultSOAPMessage(java.lang.Throwable e, SOAPHeader sh) {
    SOAPMessage msg = null;//from   w  ww .java2s.  com
    if (log.isDebugEnabled()) {
        log.debug("Creating Fault SOAP Message with Throwable:", e);
    }
    try {
        // Will this method be "legacy" ebRS 3.0 spec-compliant and
        // return a URN as the <faultcode/> value? Default expectation
        // is of a an older client. Overridden to instead be SOAP
        // 1.1-compliant and return a QName as the faultcode value when
        // we know (for sure) client supports new approach.
        boolean legacyFaultCode = true;

        // get SOAPHeaderElement list from the received message
        // TODO: if additional capabilities are needed, move code to
        // elsewhere
        if (null != sh) {
            Iterator<?> headers = sh.examineAllHeaderElements();
            while (headers.hasNext()) {
                Object obj = headers.next();

                // confirm expected Iterator content
                if (obj instanceof SOAPHeaderElement) {
                    SOAPHeaderElement header = (SOAPHeaderElement) obj;
                    Name headerName = header.getElementName();

                    // check this SOAP header for relevant capability
                    // signature
                    if (headerName.getLocalName().equals(BindingUtility.SOAP_CAPABILITY_HEADER_LocalName)
                            && headerName.getURI().equals(BindingUtility.SOAP_CAPABILITY_HEADER_Namespace)
                            && header.getValue().equals(BindingUtility.SOAP_CAPABILITY_ModernFaultCodes)) {
                        legacyFaultCode = false;
                        // only interested in one client capability
                        break;
                    }
                }
            }
        }

        msg = MessageFactory.newInstance().createMessage();
        SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
        SOAPFault fault = msg.getSOAPBody().addFault();

        // set faultCode
        String exceptionName = e.getClass().getName();
        // TODO: SAAJ 1.3 has introduced preferred QName interfaces
        Name name = env.createName(exceptionName, "ns1", BindingUtility.SOAP_FAULT_PREFIX);
        fault.setFaultCode(name);
        if (legacyFaultCode) {
            // we now have an element child, munge its text (hack alert)
            Node faultCode = fault.getElementsByTagName("faultcode").item(0);
            // Using Utility.setTextContent() implementation since Java
            // WSDP 1.5 (containing an earlier DOM API) does not
            // support Node.setTextContent().
            Utility.setTextContent(faultCode, BindingUtility.SOAP_FAULT_PREFIX + ":" + exceptionName);
        }

        // set faultString
        String errorMsg = e.getMessage();
        if (errorMsg == null) {
            errorMsg = "NULL";
        }
        fault.setFaultString(errorMsg);

        // create faultDetail with one entry
        Detail det = fault.addDetail();

        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        String str = sw.toString();

        name = env.createName("StackTrace", "rs", "urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0");
        DetailEntry de = det.addDetailEntry(name);
        de.setValue(str);
        // de.addTextNode(str);

        // TODO: Need to put baseURL for this registry here

        msg.saveChanges();
    } catch (SOAPException ex) {
        log.warn(ex, ex);
        // otherwise ignore the problem updating part of the message
    }

    return msg;
}

From source file:it.cnr.icar.eric.server.interfaces.soap.RegistrySAMLServlet.java

/**
 * This method is a copy of the respective method from RegistrySOAPServlet.
 * The SAML-based Servlet returns X.509 certificate base SOAP messages.
 * /*  w w  w .j av a 2s  .c o  m*/
 */

private SOAPMessage createFaultSOAPMessage(java.lang.Throwable e, SOAPHeader sh) {
    SOAPMessage msg = null;

    if (log.isDebugEnabled()) {
        log.debug("Creating Fault SOAP Message with Throwable:", e);
    }

    try {
        // Will this method be "legacy" ebRS 3.0 spec-compliant and
        // return a URN as the <faultcode/> value? Default expectation
        // is of a an older client. Overridden to instead be SOAP
        // 1.1-compliant and return a QName as the faultcode value when
        // we know (for sure) client supports new approach.
        boolean legacyFaultCode = true;

        // get SOAPHeaderElement list from the received message
        // TODO: if additional capabilities are needed, move code to
        // elsewhere
        if (null != sh) {
            Iterator<?> headers = sh.examineAllHeaderElements();
            while (headers.hasNext()) {
                Object obj = headers.next();

                // confirm expected Iterator content
                if (obj instanceof SOAPHeaderElement) {
                    SOAPHeaderElement header = (SOAPHeaderElement) obj;
                    Name headerName = header.getElementName();

                    // check this SOAP header for relevant capability
                    // signature
                    if (headerName.getLocalName().equals(BindingUtility.SOAP_CAPABILITY_HEADER_LocalName)
                            && headerName.getURI().equals(BindingUtility.SOAP_CAPABILITY_HEADER_Namespace)
                            && header.getValue().equals(BindingUtility.SOAP_CAPABILITY_ModernFaultCodes)) {
                        legacyFaultCode = false;
                        // only interested in one client capability
                        break;
                    }
                }
            }
        }

        msg = MessageFactory.newInstance().createMessage();
        SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
        SOAPFault fault = msg.getSOAPBody().addFault();

        // set faultCode
        String exceptionName = e.getClass().getName();

        // TODO: SAAJ 1.3 has introduced preferred QName interfaces
        Name name = env.createName(exceptionName, "ns1", BindingUtility.SOAP_FAULT_PREFIX);
        fault.setFaultCode(name);
        if (legacyFaultCode) {
            // we now have an element child, munge its text (hack alert)
            Node faultCode = fault.getElementsByTagName("faultcode").item(0);

            // Using Utility.setTextContent() implementation since Java
            // WSDP 1.5 (containing an earlier DOM API) does not
            // support Node.setTextContent().
            Utility.setTextContent(faultCode, BindingUtility.SOAP_FAULT_PREFIX + ":" + exceptionName);
        }

        // set faultString
        String errorMsg = e.getMessage();
        if (errorMsg == null) {
            errorMsg = "NULL";
        }
        fault.setFaultString(errorMsg);

        // create faultDetail with one entry
        Detail det = fault.addDetail();

        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        String str = sw.toString();

        name = env.createName("StackTrace", "rs", "urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0");

        DetailEntry de = det.addDetailEntry(name);
        de.setValue(str);
        // de.addTextNode(str);

        // TODO: Need to put baseURL for this registry here

        msg.saveChanges();

    } catch (SOAPException ex) {
        log.warn(ex, ex);
        // otherwise ignore the problem updating part of the message
    }

    return msg;
}