com.sun.xml.ws.fault.SOAP11Fault Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of webservices-rt Show documentation
Show all versions of webservices-rt Show documentation
This module contains the Metro runtime code.
/*
* Copyright (c) 1997, 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package com.sun.xml.ws.fault;
import com.sun.xml.ws.api.SOAPVersion;
import com.sun.xml.ws.util.DOMUtil;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import javax.xml.bind.annotation.*;
import javax.xml.namespace.QName;
import javax.xml.soap.Detail;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFault;
import javax.xml.ws.WebServiceException;
import java.util.Iterator;
/**
* This class represents SOAP1.1 Fault. This class will be used to marshall/unmarshall a soap fault using JAXB.
*
*
* Example:
*
* <soap:Fault xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
* <faultcode>soap:Client</faultcode>
* <faultstring>Invalid message format</faultstring>
* <faultactor>http://example.org/someactor</faultactor>
* <detail>
* <m:msg xmlns:m='http://example.org/faults/exceptions'>
* Test message
* </m:msg>
* </detail>
* </soap:Fault>
*
* Above, m:msg, if a known fault (described in the WSDL), IOW, if m:msg is known by JAXBContext it should be unmarshalled into a
* Java object otherwise it should be deserialized as {@link javax.xml.soap.Detail}
*
*
*
* @author Vivek Pandey
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"faultcode",
"faultstring",
"faultactor",
"detail"
})
@XmlRootElement(name = "Fault", namespace = "http://schemas.xmlsoap.org/soap/envelope/")
class SOAP11Fault extends SOAPFaultBuilder {
@XmlElement(namespace = "")
private QName faultcode;
@XmlElement(namespace = "")
private String faultstring;
@XmlElement(namespace = "")
private String faultactor;
@XmlElement(namespace = "")
private DetailType detail;
SOAP11Fault() {
}
/**
* This constructor takes soap fault detail among other things. The detail could represent {@link javax.xml.soap.Detail}
* or a java object that can be marshalled/unmarshalled by JAXB.
*
* @param code
* @param reason
* @param actor
* @param detailObject
*/
SOAP11Fault(QName code, String reason, String actor, Element detailObject) {
this.faultcode = code;
this.faultstring = reason;
this.faultactor = actor;
if (detailObject != null) {
if ((detailObject.getNamespaceURI() == null ||
"".equals(detailObject.getNamespaceURI())) && "detail".equals(detailObject.getLocalName())) {
detail = new DetailType();
for(Element detailEntry : DOMUtil.getChildElements(detailObject)) {
detail.getDetails().add(detailEntry);
}
} else {
detail = new DetailType(detailObject);
}
}
}
SOAP11Fault(SOAPFault fault) {
this.faultcode = fault.getFaultCodeAsQName();
this.faultstring = fault.getFaultString();
this.faultactor = fault.getFaultActor();
if (fault.getDetail() != null) {
detail = new DetailType();
Iterator iter = fault.getDetail().getDetailEntries();
while(iter.hasNext()){
Element fd = (Element)iter.next();
detail.getDetails().add(fd);
}
}
}
QName getFaultcode() {
return faultcode;
}
void setFaultcode(QName faultcode) {
this.faultcode = faultcode;
}
@Override
String getFaultString() {
return faultstring;
}
void setFaultstring(String faultstring) {
this.faultstring = faultstring;
}
String getFaultactor() {
return faultactor;
}
void setFaultactor(String faultactor) {
this.faultactor = faultactor;
}
/**
* returns the object that represents detail.
*/
@Override
DetailType getDetail() {
return detail;
}
void setDetail(DetailType detail) {
this.detail = detail;
}
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);
}
}
}