Java Code Examples for javax.xml.soap.SOAPFault#addDetail()

The following examples show how to use javax.xml.soap.SOAPFault#addDetail() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SOAP11Fault.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected Throwable getProtocolException() {
    try {
        SOAPFault fault = SOAPVersion.SOAP_11.getSOAPFactory().createFault(faultstring, faultcode);
        fault.setFaultActor(faultactor);
        if(detail != null){
            Detail d = fault.addDetail();
            for(Element det : detail.getDetails()){
                Node n = fault.getOwnerDocument().importNode(det, true);
                d.appendChild(n);
            }
        }
        return new ServerSOAPFaultException(fault);
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
}
 
Example 2
Source File: SOAP11Fault.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
protected Throwable getProtocolException() {
    try {
        SOAPFault fault = SOAPVersion.SOAP_11.getSOAPFactory().createFault(faultstring, faultcode);
        fault.setFaultActor(faultactor);
        if(detail != null){
            Detail d = fault.addDetail();
            for(Element det : detail.getDetails()){
                Node n = fault.getOwnerDocument().importNode(det, true);
                d.appendChild(n);
            }
        }
        return new ServerSOAPFaultException(fault);
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
}
 
Example 3
Source File: SOAP11Fault.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
protected Throwable getProtocolException() {
    try {
        SOAPFault fault = SOAPVersion.SOAP_11.getSOAPFactory().createFault(faultstring, faultcode);
        fault.setFaultActor(faultactor);
        if(detail != null){
            Detail d = fault.addDetail();
            for(Element det : detail.getDetails()){
                Node n = fault.getOwnerDocument().importNode(det, true);
                d.appendChild(n);
            }
        }
        return new ServerSOAPFaultException(fault);
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
}
 
Example 4
Source File: SOAP11Fault.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
protected Throwable getProtocolException() {
    try {
        SOAPFault fault = SOAPVersion.SOAP_11.getSOAPFactory().createFault(faultstring, faultcode);
        fault.setFaultActor(faultactor);
        if(detail != null){
            Detail d = fault.addDetail();
            for(Element det : detail.getDetails()){
                Node n = fault.getOwnerDocument().importNode(det, true);
                d.appendChild(n);
            }
        }
        return new ServerSOAPFaultException(fault);
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
}
 
Example 5
Source File: SOAP11Fault.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
protected Throwable getProtocolException() {
    try {
        SOAPFault fault = SOAPVersion.SOAP_11.getSOAPFactory().createFault(faultstring, faultcode);
        fault.setFaultActor(faultactor);
        if(detail != null){
            Detail d = fault.addDetail();
            for(Element det : detail.getDetails()){
                Node n = fault.getOwnerDocument().importNode(det, true);
                d.appendChild(n);
            }
        }
        return new ServerSOAPFaultException(fault);
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
}
 
Example 6
Source File: SOAP11Fault.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
protected Throwable getProtocolException() {
    try {
        SOAPFault fault = SOAPVersion.SOAP_11.getSOAPFactory().createFault(faultstring, faultcode);
        fault.setFaultActor(faultactor);
        if(detail != null){
            Detail d = fault.addDetail();
            for(Element det : detail.getDetails()){
                Node n = fault.getOwnerDocument().importNode(det, true);
                d.appendChild(n);
            }
        }
        return new ServerSOAPFaultException(fault);
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
}
 
Example 7
Source File: SOAP11Fault.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
protected Throwable getProtocolException() {
    try {
        SOAPFault fault = SOAPVersion.SOAP_11.getSOAPFactory().createFault(faultstring, faultcode);
        fault.setFaultActor(faultactor);
        if(detail != null){
            Detail d = fault.addDetail();
            for(Element det : detail.getDetails()){
                Node n = fault.getOwnerDocument().importNode(det, true);
                d.appendChild(n);
            }
        }
        return new ServerSOAPFaultException(fault);
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
}
 
Example 8
Source File: SOAP11Fault.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
protected Throwable getProtocolException() {
    try {
        SOAPFault fault = SOAPVersion.SOAP_11.getSOAPFactory().createFault(faultstring, faultcode);
        fault.setFaultActor(faultactor);
        if(detail != null){
            Detail d = fault.addDetail();
            for(Element det : detail.getDetails()){
                Node n = fault.getOwnerDocument().importNode(det, true);
                d.appendChild(n);
            }
        }
        return new ServerSOAPFaultException(fault);
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
}
 
Example 9
Source File: TestSOAPHandler.java    From cxf with Apache License 2.0 6 votes vote down vote up
private SOAPFaultException createSOAPFaultExceptionWithDetail(String faultString)
    throws SOAPException {

    SOAPFault fault = SOAPFactory.newInstance().createFault();

    QName faultName = new QName(SOAPConstants.URI_NS_SOAP_ENVELOPE,
                    "Server");
    SAAJUtils.setFaultCode(fault, faultName);
    fault.setFaultActor("http://gizmos.com/orders");
    fault.setFaultString(faultString);

    Detail detail = fault.addDetail();

    QName entryName = new QName("http://gizmos.com/orders/",
                    "order", "PO");
    DetailEntry entry = detail.addDetailEntry(entryName);
    entry.addTextNode("Quantity element does not have a value");

    QName entryName2 = new QName("http://gizmos.com/orders/",
                    "order", "PO");
    DetailEntry entry2 = detail.addDetailEntry(entryName2);
    entry2.addTextNode("Incomplete address: no zip code");

    return new SOAPFaultException(fault);
}
 
Example 10
Source File: JPlagServerAccessHandler.java    From jplag with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Manually builds up a JPlagException SOAP message and replaces the
 * original one with it
 */
public void replaceByJPlagException(SOAPMessageContext smsg, String desc, String rep) {
	try {
		SOAPMessage msg = smsg.getMessage();
		SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();

		/*
		 * Remove old header andy body
		 */

		SOAPHeader oldheader = envelope.getHeader();
		if (oldheader != null)
			oldheader.detachNode();
		SOAPBody oldbody = envelope.getBody();
		if (oldbody != null)
			oldbody.detachNode();

		SOAPBody sb = envelope.addBody();
		SOAPFault sf = sb.addFault(envelope.createName("Server", "env", SOAPConstants.URI_NS_SOAP_ENVELOPE),
				"jplagWebService.server.JPlagException");
		Detail detail = sf.addDetail();
		DetailEntry de = detail.addDetailEntry(envelope.createName("JPlagException", "ns0", JPLAG_WEBSERVICE_BASE_URL + "types"));

		SOAPElement e = de.addChildElement("exceptionType");
		e.addTextNode("accessException");

		e = de.addChildElement("description");
		e.addTextNode(desc);

		e = de.addChildElement("repair");
		e.addTextNode(rep);
	} catch (SOAPException x) {
		x.printStackTrace();
	}
}
 
Example 11
Source File: AbstractSoapEncoder.java    From arctic-sea with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a SOAPFault element from SOS exception
 *
 * @param soapFault
 *            SOAPFault element
 * @param owsExceptionReport
 *            SOS exception
 *
 * @return SOAP action URI.
 *
 * @throws SOAPException
 *             if an error occurs.
 *
 * @deprecated javax.xml.soap.* is no longer supported from 8.0 because it
 *             was removed from Java
 */
@Deprecated
protected String createSOAPFaultFromExceptionResponse(SOAPFault soapFault, OwsExceptionReport owsExceptionReport)
        throws SOAPException {
    // FIXME: check and fix support for ExceptionReport with multiple
    // exceptions!
    if (!owsExceptionReport.getExceptions()
            .isEmpty()) {
        CodedException firstException = owsExceptionReport.getExceptions()
                .iterator()
                .next();
        if (soapFault.getNamespaceURI()
                .equalsIgnoreCase(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE)) {
            QName qname = new QName(soapFault.getNamespaceURI(), "Client", soapFault.getPrefix());
            soapFault.setFaultCode(qname);
        } else {
            soapFault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
            if (firstException.getCode() != null) {
                soapFault.appendFaultSubcode(new QName(OWSConstants.NS_OWS, firstException.getCode()
                        .toString(), OWSConstants.NS_OWS_PREFIX));
            } else {
                soapFault.appendFaultSubcode(OWSConstants.QN_NO_APPLICABLE_CODE);
            }
        }
        soapFault.addFaultReasonText(SoapHelper.getSoapFaultReasonText(firstException.getCode()), Locale.ENGLISH);
        Detail detail = soapFault.addDetail();
        for (CodedException exception : owsExceptionReport.getExceptions()) {
            createSOAPFaultDetail(detail, exception);
        }
        return getExceptionActionURI(firstException.getCode());
    } else {
        SoapFault fault = new SoapFault();
        fault.setFaultCode(SOAPConstants.SOAP_RECEIVER_FAULT);
        fault.setFaultSubcode(OWSConstants.QN_NO_APPLICABLE_CODE);
        fault.setFaultReason(DEFAULT_FAULT_REASON);
        fault.setLocale(Locale.ENGLISH);
        fault.setDetailText(MISSING_EXCEPTION_DETAIL_TEXT);
        createSOAPFault(soapFault, fault);
        return SosSoapConstants.RESP_ACTION_SOS;
    }
}
 
Example 12
Source File: HWSoapMessageDocProvider.java    From cxf with Apache License 2.0 4 votes vote down vote up
public SOAPMessage invoke(SOAPMessage request) {
    QName qn = (QName)ctx.getMessageContext().get(MessageContext.WSDL_OPERATION);
    if (qn == null) {
        throw new RuntimeException("No Operation Name");
    }

    SOAPMessage response = null;
    SOAPBody body = null;
    try {
        body = SAAJUtils.getBody(request);
    } catch (SOAPException e) {
        return null;
    }
    Node n = body.getFirstChild();

    while (n.getNodeType() != Node.ELEMENT_NODE) {
        n = n.getNextSibling();
    }
    if (n.getLocalName().equals(sayHi.getLocalPart())) {
        response = sayHiResponse;
    } else if (n.getLocalName().equals(greetMe.getLocalPart())) {
        Element el = DOMUtils.getFirstElement(n);
        String v = DOMUtils.getContent(el);
        if (v.contains("Return sayHi")) {
            response = sayHiResponse;
        } else if (v.contains("exceed maxLength")) {
            response = greetMeResponseExceedMaxLengthRestriction;
        } else if (v.contains("throwFault")) {
            try {
                SOAPFactory f = SOAPFactory.newInstance();
                SOAPFault soapFault = f.createFault();

                soapFault.setFaultString("Test Fault String ****");

                Detail detail = soapFault.addDetail();
                detail = soapFault.getDetail();

                QName qName = new QName("http://www.Hello.org/greeter", "TestFault", "ns");
                DetailEntry de = detail.addDetailEntry(qName);

                qName = new QName("http://www.Hello.org/greeter", "ErrorCode", "ns");
                SOAPElement errorElement = de.addChildElement(qName);
                errorElement.setTextContent("errorcode");
                throw new SOAPFaultException(soapFault);
            } catch (SOAPException ex) {
                //ignore
            }

        } else {
            response = greetMeResponse;
        }
    }
    return response;
}
 
Example 13
Source File: HWDOMSourcePayloadProvider.java    From cxf with Apache License 2.0 4 votes vote down vote up
public DOMSource invoke(DOMSource request) {
    QName qn = (QName)ctx.getMessageContext().get(MessageContext.WSDL_OPERATION);
    if (qn == null) {
        throw new RuntimeException("No Operation Name");
    }

    DOMSource response = new DOMSource();

    Node n = request.getNode();
    if (n instanceof Document) {
        n = ((Document)n).getDocumentElement();
    }
    if (n.getLocalName().equals(sayHi.getLocalPart())) {
        response.setNode(sayHiResponse);
    } else if (n.getLocalName().equals(greetMe.getLocalPart())) {
        Element el = DOMUtils.getFirstElement(n);
        String s = DOMUtils.getContent(el);
        if ("throwFault".equals(s.trim())) {
            try {
                SOAPFactory f = SOAPFactory.newInstance();
                SOAPFault soapFault = f.createFault();

                soapFault.setFaultString("Test Fault String ****");

                Detail detail = soapFault.addDetail();
                detail = soapFault.getDetail();

                QName qName = new QName("http://www.Hello.org/greeter", "TestFault", "ns");
                DetailEntry de = detail.addDetailEntry(qName);

                qName = new QName("http://www.Hello.org/greeter", "ErrorCode", "ns");
                SOAPElement errorElement = de.addChildElement(qName);
                errorElement.setTextContent("errorcode");

                throw new SOAPFaultException(soapFault);
            } catch (SOAPException e) {
                e.printStackTrace();
            }
        }

        response.setNode(greetMeResponse);
    }
    return response;
}