private void validateFault(SoapMessage message, SOAPFault fault, BindingOperationInfo bop) { if (ServiceUtils.isSchemaValidationEnabled(SchemaValidationType.OUT, message)) { Schema schema = EndpointReferenceUtils.getSchema(message.getExchange().getService() .getServiceInfos().get(0), message.getExchange().getBus()); Detail d = fault.getDetail(); try { validateFaultDetail(d, schema, bop); } catch (Exception e) { throw new SoapFault(e.getMessage(), e, message.getVersion().getReceiver()); } //We validated what we can from a fault standpoint message.put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.FALSE); } }
SoapFault sf = SoapFault.createFault((Fault)exception, ((SoapMessage)msg).getVersion()); soapFault.setFaultString(sf.getReason()); SAAJUtils.setFaultCode(soapFault, sf.getFaultCode()); if (sf.hasDetails()) { soapFault.addDetail(); Node nd = soapMessage.getSOAPPart().importNode(sf.getDetail(), true); nd = nd.getFirstChild(); while (nd != null) {
public SoapFaultException(MuleEvent event, SoapFault soapFault, MessageProcessor failingMessageProcessor) { super(CoreMessages.createStaticMessage(soapFault.getMessage()), event, soapFault, failingMessageProcessor); this.faultCode = soapFault.getFaultCode(); this.subCode = soapFault.getSubCode(); this.detail = soapFault.getDetail(); }
if (!soapFault.getNamespaceURI().equals(((SoapFault)ex).getFaultCode().getNamespaceURI()) && SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE .equals(((SoapFault)ex).getFaultCode().getNamespaceURI())) { if (StringUtils.isEmpty(((SoapFault)ex).getLang())) { soapFault.setFaultString(((SoapFault)ex).getReason()); } else { soapFault.setFaultString(((SoapFault)ex).getReason(), stringToLocale(((SoapFault)ex).getLang())); SAAJUtils.setFaultCode(soapFault, ((SoapFault)ex).getFaultCode()); String role = ((SoapFault)ex).getRole(); if (role != null) { soapFault.setFaultActor(role); if (((SoapFault)ex).getSubCodes() != null && !isSoap11) { for (QName fsc : ((SoapFault)ex).getSubCodes()) { soapFault.appendFaultSubcode(fsc); if (((SoapFault)ex).hasDetails()) { Node nd = soapFault.getOwnerDocument().importNode(((SoapFault)ex).getDetail(), true); nd = nd.getFirstChild();
/** * Create a SoapFault from a WSSecurityException, following the SOAP Message Security * 1.1 specification, chapter 12 "Error Handling". * * When the Soap version is 1.1 then set the Fault/Code/Value from the fault code * specified in the WSSecurityException (if it exists). * * Otherwise set the Fault/Code/Value to env:Sender and the Fault/Code/Subcode/Value * as the fault code from the WSSecurityException. */ private SoapFault createSoapFault(SoapVersion version, WSSecurityException e) { SoapFault fault; javax.xml.namespace.QName faultCode = e.getFaultCode(); if (version.getVersion() == 1.1 && faultCode != null) { fault = new SoapFault(e.getMessage(), e, faultCode); } else { fault = new SoapFault(e.getMessage(), e, version.getSender()); if (version.getVersion() != 1.1 && faultCode != null) { fault.setSubCode(faultCode); } } return fault; }
Fault f = (Fault) message.getContent(Exception.class); SoapFault fault = SoapFault.createFault(f, message.getVersion()); Map<String, String> namespaces = fault.getNamespaces(); for (Map.Entry<String, String> e : namespaces.entrySet()) { writer.writeNamespace(e.getKey(), e.getValue()); String codeString = fault.getCodeString(getFaultCodePrefix(writer, fault.getFaultCode()), defaultPrefix); prepareStackTrace(message, fault); if (fault.getRole() != null) { writer.writeStartElement("faultactor"); writer.writeCharacters(fault.getRole()); writer.writeEndElement(); if (fault.hasDetails()) { Element detail = fault.getDetail(); writer.writeStartElement("detail");
XPathConstants.STRING); } catch (XMLStreamException e) { throw new SoapFault("Could not parse message.", e, message.getVersion().getSender()); SoapFault fault = new SoapFault(exMessage, faultCode); fault.setSubCodes(subCodes); fault.setDetail(detail); fault.setRole(role); fault.setNode(node); fault.setLang(lang); return fault;
private Object[] invoke(SoapRequest request, Exchange exchange, MessageDispatcher dispatcher) { String operation = request.getOperation(); XMLStreamReader xmlBody = getXmlBody(request); try { Map<String, Object> ctx = getInvocationContext(request, dispatcher); return client.invoke(getInvocationOperation(), new Object[] {xmlBody}, ctx, exchange); } catch (SoapFault sf) { throw new SoapFaultException(sf.getFaultCode(), sf.getSubCode(), parseExceptionDetail(sf.getDetail()).orElse(null), sf.getReason(), sf.getNode(), sf.getRole(), sf); } catch (Fault f) { if (f.getMessage().contains("COULD_NOT_READ_XML")) { throw new BadRequestException("Error consuming the operation [" + operation + "], the request body is not a valid XML"); } throw new SoapFaultException(f.getFaultCode(), parseExceptionDetail(f.getDetail()).orElse(null), f); } catch (DispatchingException e) { throw e; } catch (OperationNotFoundException e) { String location = wsdlModel.getLocation(); throw new BadRequestException("The provided [" + operation + "] does not exist in the WSDL file [" + location + "]", e); } catch (Exception e) { throw new SoapServiceException("Unexpected error while consuming the web service operation [" + operation + "]", e); } }
updateSoap12FaultCodes((SoapFault)f); fc = v.getReceiver(); SoapFault soapFault = new SoapFault(new Message(f.getMessage(), (ResourceBundle)null), f.getCause(), fc); if (v == Soap12.getInstance()) { updateSoap12FaultCodes(soapFault); soapFault.setDetail(f.getDetail()); return soapFault;
faultMessageValidator = new PlainTextTestResource(expectedValue.getMessage()); codeValidator = new QNameValidator(expectedValue.getFaultCode()); if (expectedValue.getDetail() != null) detailValidator = new XmlTestResource(expectedValue.getDetail().getOwnerDocument()); } catch (Exception ex) { throw new RuntimeException(ex); faultMessageExchange.getIn().setBody(fault.getMessage()); validMessage = faultMessageValidator.matches(faultMessageExchange); logger.warn("The SOAP Fault message is not as expected; received {}", fault.getCode()); codeExchange.getIn().setBody(fault.getFaultCode()); validCode = codeValidator.matches(codeExchange); if (!validCode) logger.warn("The SOAP Fault code is not as expected; received {}", fault.getCode()); detailExchange.getIn().setBody(fault.getDetail()); validDetail = detailValidator.matches(detailExchange); String detail = xmlUtilities.getDocumentAsString(fault.getDetail()); if (!validDetail) logger.warn("The SOAP Fault detail is not as expected; received {}", detail);
public SoapFault getValue() throws Exception { SoapFault fault = new SoapFault(message, faultCode); if (xmlDetail != null) { Document document = xmlDetail.getValue(); if (!document.getDocumentElement().getNodeName().equals("detail")) { logger.warn("The provided XML is not wrapped in a detail element, this is required and one will be added"); DocumentBuilder builder = xmlUtilities.getDocumentBuilder(); Document newDetailDocument = builder.newDocument(); Element newDetailElement = newDetailDocument.createElement("detail"); newDetailDocument.appendChild(newDetailElement); newDetailElement.appendChild(newDetailDocument.importNode(document.getDocumentElement(), true)); fault.setDetail(newDetailElement); } else fault.setDetail(document.getDocumentElement()); } return fault; }
public String toString(Fault f) { SoapFault sf = (SoapFault)f; org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("SEQ_FAULT_MSG", LOG, new Object[] {sf.getReason(), sf.getFaultCode(), sf.getSubCode()}); return msg.toString(); } }
rpToken = sts.requestSecurityTokenResponse(realm); } catch (SoapFault ex) { LOG.error("Error in retrieving a token", ex.getMessage()); if (ex.getFaultCode() != null && "RequestFailed".equals(ex.getFaultCode().getLocalPart())) { throw new ProcessingException(TYPE.BAD_REQUEST);
private static void updateSoap12FaultCodes(SoapFault f) { //per Soap 1.2 spec, the fault code MUST be one of the 5 values specified in the spec. //Soap 1.1 allows the soap fault code to be arbitrary (recommends the 4 values in the spec, but //explicitely mentions that it can be extended to include additional codes). Soap 1.2 however //requires the use of one of the 5 defined codes. Additional detail or more specific information //can be transferred via the SubCodes. QName fc = f.getFaultCode(); SoapVersion v = Soap12.getInstance(); if (fc.getNamespaceURI().equals(Soap12.SOAP_NAMESPACE) && (fc.equals(v.getReceiver()) || fc.equals(v.getSender()) || fc.equals(v.getMustUnderstand()) || fc.equals(v.getDateEncodingUnknown()) || fc.equals(v.getVersionMismatch()))) { //valid fault codes, don't change anything return; } f.setFaultCode(Soap12.getInstance().getReceiver()); if (f.getSubCodes() == null) { f.setRootSubCode(fc); } else if (!f.getSubCodes().contains(fc)) { f.getSubCodes().add(fc); } } public static SoapFault createFault(Fault f, SoapVersion v) {
protected void prepareStackTrace(SoapMessage message, SoapFault fault) throws Exception { boolean config = MessageUtils.getContextualBoolean(message, Message.FAULT_STACKTRACE_ENABLED, false); if (config && fault.getCause() != null) { StringBuilder sb = new StringBuilder(); Throwable throwable = fault.getCause(); sb.append("Caused by: ").append(throwable.getClass().getCanonicalName()) .append(": " + throwable.getMessage() + "\n").append(Message.EXCEPTION_CAUSE_SUFFIX); Element detail = fault.getDetail(); String soapNamespace = message.getVersion().getNamespace(); if (detail == null) { detail = doc.createElementNS( soapNamespace, "detail"); fault.setDetail(detail); detail.appendChild(stackTrace); } else {
(org.apache.cxf.binding.soap.SoapFault) cause; System.out.println("Got exception: " + af.getClass().getName()); System.out.println("Reason = " + af.getReason()); System.out.println("Message = " + af.getMessage()); fail("Legal access dis-allowed"); } else {
public String getReason() { return getMessage(); }
SoapFault sf = (SoapFault)cause; assertEquals(expectedMsg, sf.getReason()); assertEquals(SOAP_FAULT_CODE, sf.getFaultCode()); Throwable cause = ex.getCause(); SoapFault sf = (SoapFault)cause; assertEquals(expectedMsg, sf.getReason()); assertEquals(SOAP_FAULT_CODE, sf.getFaultCode());