Example usage for javax.xml.soap DetailEntry addChildElement

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

Introduction

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

Prototype

public SOAPElement addChildElement(Name name) throws SOAPException;

Source Link

Document

Creates a new SOAPElement object initialized with the given Name object and adds the new element to this SOAPElement object.

Usage

From source file:de.unibi.techfak.bibiserv.BiBiTools.java

/**
 * Returns a SOAPFaultException with specified
 *
 * @param faultcode/*ww w.  j a v a 2 s.co m*/
 * @param faultstring
 * @param hobitstatuscode
 * @param hobitstatusdescription
 * @return
 */
public static SOAPFaultException createSOAPFaultException(String faultcode, String faultstring,
        String hobitstatuscode, String hobitstatusdescription) {
    SOAPFault fault = null;
    try {
        SOAPFactory sfi = SOAPFactory.newInstance();
        fault = sfi.createFault();

        fault.setFaultCode(new QName("http://schemas.xmlsoap.org/soap/envelope/", faultcode, "soap"));
        fault.setFaultString(faultstring);
        if (hobitstatuscode != null && hobitstatusdescription != null) {
            Detail detail = fault.addDetail();
            DetailEntry detailentry = detail.addDetailEntry(new QName(
                    "http://hobit.sourceforge.net/xsds/hobitStatuscode.xsd", "hobitStatuscode", "status"));

            SOAPElement statuscode = detailentry.addChildElement(
                    new QName("http://hobit.sourceforge.net/xsds/hobitStatuscode.xsd", "statuscode", "status"));
            statuscode.addTextNode(hobitstatuscode);

            SOAPElement description = detailentry.addChildElement(new QName(
                    "http://hobit.sourceforge.net/xsds/hobitStatuscode.xsd", "description", "status"));
            description.addTextNode(hobitstatusdescription);
        }

    } catch (SOAPException e) {
        log.fatal("SOAPException occured : " + e.getMessage());
    }

    return new SOAPFaultException(fault);

}

From source file:org.apache.cxf.ws.security.sts.provider.SecurityTokenServiceProvider.java

public Source invoke(Source request) {
    Source response = null;//from   ww w. j  ava 2 s .  co  m
    try {
        RequestSecurityTokenType rst = convertToJAXBObject(request);
        Object operationImpl = null;
        List<?> objectList = rst.getAny();
        for (int i = 0; i < objectList.size(); i++) {
            Object obj = objectList.get(i);
            if (obj instanceof JAXBElement) {
                QName qname = ((JAXBElement<?>) obj).getName();
                if (qname.equals(new QName(WSTRUST_13_NAMESPACE, WSTRUST_REQUESTTYPE_ELEMENTNAME))) {
                    operationImpl = operationMap.get(((JAXBElement<?>) obj).getValue().toString());
                    break;
                }

            }
        }

        if (operationImpl == null) {
            throw new Exception("Implementation for this operation not found.");
        }
        Method[] methods = operationImpl.getClass().getMethods();
        for (int x = 0; x < methods.length; x++) {
            Class<?>[] paramClass = methods[x].getParameterTypes();
            if (paramClass.length == 1 && paramClass[0].equals(rst.getClass())) {
                RequestSecurityTokenResponseCollectionType tokenResponse = (RequestSecurityTokenResponseCollectionType) methods[x]
                        .invoke(operationImpl, rst);
                if (tokenResponse == null) {
                    throw new Exception("Error in implementation class.");
                }

                response = new JAXBSource(jaxbContext,
                        new ObjectFactory().createRequestSecurityTokenResponseCollection(tokenResponse));
                return response;
            }
        }

    } catch (Exception e) {
        LOG.error(e);
        try {
            SOAPFault fault = soapFactory.createFault();
            if (e.getMessage() == null) {
                fault.setFaultString(e.getCause().getMessage());
            } else {
                fault.setFaultString(e.getMessage());
            }
            Detail detail = fault.addDetail();
            detail = fault.getDetail();
            QName qName = new QName(WSTRUST_13_NAMESPACE, "Fault", "ns");
            DetailEntry de = detail.addDetailEntry(qName);
            qName = new QName(WSTRUST_13_NAMESPACE, "ErrorCode", "ns");
            SOAPElement errorElement = de.addChildElement(qName);
            StackTraceElement[] ste = e.getStackTrace();
            errorElement.setTextContent(ste[0].toString());
            throw new SOAPFaultException(fault);
        } catch (SOAPException e1) {
            LOG.error(e1);
        }

    }

    return response;
}