use of org.w3.x2003.x05.soapEnvelope.Reasontext in project camel by apache.
the class Soap12DataFormatAdapter method createExceptionFromFault.
/**
* Creates an exception and eventually an embedded bean that contains the
* fault detail. The exception class is determined by using the
* elementNameStrategy. The qName of the fault detail should match the
* WebFault annotation of the Exception class. If no fault detail is set
* a {@link javax.xml.ws.soap.SOAPFaultException} is created.
*
* @param fault Soap fault
* @return created Exception
*/
private Exception createExceptionFromFault(Fault fault) {
StringBuilder sb = new StringBuilder();
for (Reasontext text : fault.getReason().getText()) {
sb.append(text.getValue());
}
String message = sb.toString();
Detail faultDetail = fault.getDetail();
if (faultDetail == null || faultDetail.getAny().size() == 0) {
try {
return new SOAPFaultException(SOAPFactory.newInstance().createFault(message, fault.getCode().getValue()));
} catch (SOAPException e) {
throw new RuntimeCamelException(e);
}
}
JAXBElement<?> detailEl = (JAXBElement<?>) faultDetail.getAny().get(0);
Class<? extends Exception> exceptionClass = getDataFormat().getElementNameStrategy().findExceptionForFaultName(detailEl.getName());
Constructor<? extends Exception> messageConstructor;
Constructor<? extends Exception> constructor;
try {
messageConstructor = exceptionClass.getConstructor(String.class);
Object detail = JAXBIntrospector.getValue(detailEl);
try {
constructor = exceptionClass.getConstructor(String.class, detail.getClass());
return constructor.newInstance(message, detail);
} catch (NoSuchMethodException e) {
return messageConstructor.newInstance(message);
}
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
}
use of org.w3.x2003.x05.soapEnvelope.Reasontext in project arctic-sea by 52North.
the class Soap12Encoder method createSOAP12FaultFromExceptionResponse.
// see
// http://www.angelikalanger.com/GenericsFAQ/FAQSections/ProgrammingIdioms.html#FAQ300
// for more details
private XmlObject createSOAP12FaultFromExceptionResponse(final OwsExceptionReport owsExceptionReport) throws EncodingException {
final FaultDocument faultDoc = FaultDocument.Factory.newInstance();
final Fault fault = faultDoc.addNewFault();
final Faultcode code = fault.addNewCode();
code.setValue(SOAPConstants.SOAP_SENDER_FAULT);
// 19.2.3 SOAP 1.2 Fault Binding
if (!owsExceptionReport.getExceptions().isEmpty()) {
final CodedException firstException = owsExceptionReport.getExceptions().get(0);
final Subcode subcode = code.addNewSubcode();
QName qName;
if (firstException.getCode() != null) {
qName = OwsHelper.getQNameForLocalName(firstException.getCode().toString());
} else {
qName = OwsHelper.getQNameForLocalName(OwsExceptionCode.NoApplicableCode.name());
}
subcode.setValue(qName);
final Reasontext addNewText = fault.addNewReason().addNewText();
addNewText.setLang(Locale.ENGLISH.getLanguage());
addNewText.setStringValue(SoapHelper.getSoapFaultReasonText(firstException.getCode()));
fault.addNewDetail().set(encodeObjectToXml(OWSConstants.NS_OWS, firstException, EncodingContext.of(XmlBeansEncodingFlags.ENCODE_OWS_EXCEPTION_ONLY)));
}
return faultDoc;
}
use of org.w3.x2003.x05.soapEnvelope.Reasontext in project camel by apache.
the class Soap12DataFormatAdapter method createFaultFromException.
/**
* Creates a SOAP fault from the exception and populates the message as well
* as the detail. The detail object is read from the method getFaultInfo of
* the throwable if present
*
* @param exception the cause exception
* @return SOAP fault from given Throwable
*/
@SuppressWarnings("unchecked")
private JAXBElement<Fault> createFaultFromException(final Throwable exception) {
WebFault webFault = exception.getClass().getAnnotation(WebFault.class);
if (webFault == null || webFault.targetNamespace() == null) {
throw new RuntimeException("The exception " + exception.getClass().getName() + " needs to have an WebFault annotation with name and targetNamespace", exception);
}
QName name = new QName(webFault.targetNamespace(), webFault.name());
Object faultObject;
try {
Method method = exception.getClass().getMethod("getFaultInfo");
faultObject = method.invoke(exception);
} catch (Exception e) {
throw new RuntimeCamelException("Exception while trying to get fault details", e);
}
Fault fault = new Fault();
Faultcode code = new Faultcode();
code.setValue(FAULT_CODE_SERVER);
fault.setCode(code);
Reasontext text = new Reasontext();
text.setValue(exception.getMessage());
text.setLang("en");
fault.setReason(new Faultreason().withText(text));
Detail detailEl = new ObjectFactory().createDetail();
@SuppressWarnings("rawtypes") JAXBElement<?> faultDetailContent = new JAXBElement(name, faultObject.getClass(), faultObject);
detailEl.getAny().add(faultDetailContent);
fault.setDetail(detailEl);
return new ObjectFactory().createFault(fault);
}
use of org.w3.x2003.x05.soapEnvelope.Reasontext in project arctic-sea by 52North.
the class Soap12Encoder method createSOAP12Fault.
private XmlObject createSOAP12Fault(final SoapFault soapFault) {
final FaultDocument faultDoc = FaultDocument.Factory.newInstance();
final Fault fault = faultDoc.addNewFault();
fault.addNewCode().setValue(soapFault.getFaultCode());
final Reasontext addNewText = fault.addNewReason().addNewText();
addNewText.setLang(soapFault.getLocale().getDisplayLanguage());
addNewText.setStringValue(soapFault.getFaultReason());
if (soapFault.getDetailText() != null) {
final XmlString xmlString = XmlString.Factory.newInstance();
xmlString.setStringValue(soapFault.getDetailText());
fault.addNewDetail().set(xmlString);
}
return faultDoc;
}
Aggregations