/** * Returns the fault string or reason. For SOAP 1.1, this returns the fault string. For SOAP 1.2, this returns the * fault reason for the default locale. * * <p>Note that this message returns the same as {@link #getMessage()}. */ public String getFaultStringOrReason() { return soapFault != null ? soapFault.getFaultStringOrReason() : null; }
/** Returns the fault code. */ public QName getFaultCode() { return soapFault != null ? soapFault.getFaultCode() : null; }
/** * Compares fault actor or role. See {@link SoapFault#getFaultActorOrRole()}. * @param expectedActorOrRole * @return */ public MessageValidator assertFaultActorOrRole(String expectedActorOrRole) { String faultActorOrRole = getSoapFault().getFaultActorOrRole(); if (!expectedActorOrRole.equals(faultActorOrRole)) { throw new WsTestException("Expected fault actor or role \""+expectedActorOrRole+"\", get \""+faultActorOrRole+"\"", message); } return this; }
/** * Builder method from Spring WS SOAP fault object. * @param fault * @return */ public static SoapFault from(org.springframework.ws.soap.SoapFault fault) { QNameEditor qNameEditor = new QNameEditor(); qNameEditor.setValue(fault.getFaultCode()); SoapFault soapFault = new SoapFault() .faultCode(qNameEditor.getAsText()) .faultActor(fault.getFaultActorOrRole()) .faultString(fault.getFaultStringOrReason()); if (fault.getFaultDetail() != null) { Iterator<SoapFaultDetailElement> details = fault.getFaultDetail().getDetailEntries(); while (details.hasNext()) { SoapFaultDetailElement soapFaultDetailElement = details.next(); soapFault.addFaultDetail(extractFaultDetail(soapFaultDetailElement)); } } return soapFault; }
@Override public void match(WebServiceMessage request, WebServiceMessage response) throws IOException, AssertionError { assertTrue("Response is not a SOAP message", response instanceof SoapMessage); SoapMessage soapResponse = (SoapMessage) response; SoapBody responseBody = soapResponse.getSoapBody(); assertTrue("Response has no SOAP Body", responseBody != null); assertTrue("Response has no SOAP Fault", responseBody.hasFault()); SoapFault soapFault = responseBody.getFault(); QName expectedFaultCode = getExpectedFaultCode(soapResponse.getVersion()); assertEquals("Invalid SOAP Fault code", expectedFaultCode, soapFault.getFaultCode()); if (expectedFaultStringOrReason != null) { assertEquals("Invalid SOAP Fault string/reason", expectedFaultStringOrReason, soapFault.getFaultStringOrReason()); } }
protected void customizeFault(Object endpoint, Exception ex, SoapFault fault) { if (ex instanceof BusinessItcbException) { BusinessItcbException bie = (BusinessItcbException) ex; SoapFaultDetail detail = fault.addFaultDetail(); detail.addFaultDetailElement(BusinessItcbException.EXCEPTION_CLASS).addText(ex.getClass().getName()); detail.addFaultDetailElement(BusinessItcbException.COMMON_MESSAGE).addText(bie.getMessage()); } }
private void createMustUnderstandFault(SoapMessage soapResponse, List<QName> notUnderstoodHeaderNames, String[] actorsOrRoles) { if (logger.isWarnEnabled()) { logger.warn("Could not handle mustUnderstand headers: " + StringUtils.collectionToCommaDelimitedString(notUnderstoodHeaderNames) + ". Returning fault"); } SoapBody responseBody = soapResponse.getSoapBody(); SoapFault fault = responseBody.addMustUnderstandFault(mustUnderstandFaultString, mustUnderstandFaultStringLocale); if (!ObjectUtils.isEmpty(actorsOrRoles)) { fault.setFaultActorOrRole(actorsOrRoles[0]); } SoapHeader header = soapResponse.getSoapHeader(); if (header instanceof Soap12Header) { Soap12Header soap12Header = (Soap12Header) header; for (QName headerName : notUnderstoodHeaderNames) { soap12Header.addNotUnderstoodHeaderElement(headerName); } } }
soapFault.setFaultActorOrRole(replyMessage.getFaultActor()); SoapFaultDetail faultDetail = soapFault.addFaultDetail(); for (int i = 0; i < soapFaultDetails.size(); i++) { transformer.transform(new StringSource(soapFaultDetails.get(i)), faultDetail.getResult());
private void manageOtherSpecificSoapFaultClientException(SoapFaultClientException sfce) { //ValidationError if(sfce.getSoapFault().getFaultDetail() != null) { try { Iterator<SoapFaultDetailElement> iteratorDetailEntries = sfce.getSoapFault().getFaultDetail().getDetailEntries(); while(iteratorDetailEntries.hasNext()) { SoapFaultDetailElement soapFaultDetailElement = iteratorDetailEntries.next(); if(soapFaultDetailElement.getName().getNamespaceURI().equals(SPRING_WS_URI) && soapFaultDetailElement.getName().getLocalPart().equals(SPRING_WS_VALIDATION_ERROR)) { if(soapFaultDetailElement.getResult() instanceof DOMResult) { String detailedMessage = ((DOMResult)soapFaultDetailElement.getResult()).getNode().getTextContent(); throw new ClientItcbException(ClientItcbExceptionMappingErrors.COMMON_CLIENT_VALIDATION_ERROR, messageSource.getMessage("common-client.exception.validation_error", new Object[] {detailedMessage}, LocaleContextHolder.getLocale())); } } } } catch(ClientItcbException cie) { throw cie; } } }
if (ex.getSoapFault() != null && ex.getSoapFault().getSource() != null) { final TransformerFactory factory = TransformerFactory.newInstance(); factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); transformer.transform(ex.getSoapFault().getSource(), result); StringBuffer sb = writer.getBuffer(); exceptionString = sb.toString();
@Override public void match(WebServiceMessage request, WebServiceMessage response) throws IOException, AssertionError { assertTrue("Response is not a SOAP message", response instanceof SoapMessage); SoapMessage soapResponse = (SoapMessage) response; SoapBody responseBody = soapResponse.getSoapBody(); assertTrue("Response has no SOAP Body", responseBody != null); assertTrue("Response has no SOAP Fault", responseBody.hasFault()); SoapFault soapFault = responseBody.getFault(); QName expectedFaultCode = getExpectedFaultCode(soapResponse.getVersion()); assertEquals("Invalid SOAP Fault code", expectedFaultCode, soapFault.getFaultCode()); if (expectedFaultStringOrReason != null) { assertEquals("Invalid SOAP Fault string/reason", expectedFaultStringOrReason, soapFault.getFaultStringOrReason()); } }
/** * Adds error code element detail into SOAP fault. * * @param messageContext current message context * @param endpoint the executed endpoint, or <code>null</code> if none chosen at the time of the exception * @param ex the exception that got thrown during endpoint execution * @param fault the SOAP fault to be customized. */ protected void customizeFault(MessageContext messageContext, Object endpoint, Exception ex, SoapFault fault) { if (ex instanceof IntegrationException) { SoapFaultDetail detail = fault.addFaultDetail(); detail.addFaultDetailElement(ERR_CODE).addText(((IntegrationException) ex).getError().getErrorCode()); } } }
private void createMustUnderstandFault(SoapMessage soapResponse, List<QName> notUnderstoodHeaderNames, String[] actorsOrRoles) { if (logger.isWarnEnabled()) { logger.warn("Could not handle mustUnderstand headers: " + StringUtils.collectionToCommaDelimitedString(notUnderstoodHeaderNames) + ". Returning fault"); } SoapBody responseBody = soapResponse.getSoapBody(); SoapFault fault = responseBody.addMustUnderstandFault(mustUnderstandFaultString, mustUnderstandFaultStringLocale); if (!ObjectUtils.isEmpty(actorsOrRoles)) { fault.setFaultActorOrRole(actorsOrRoles[0]); } SoapHeader header = soapResponse.getSoapHeader(); if (header instanceof Soap12Header) { Soap12Header soap12Header = (Soap12Header) header; for (QName headerName : notUnderstoodHeaderNames) { soap12Header.addNotUnderstoodHeaderElement(headerName); } } }
private void manageOtherSpecificSoapFaultClientException(SoapFaultClientException sfce) { //ValidationError if(sfce.getSoapFault().getFaultDetail() != null) { try { while(sfce.getSoapFault().getFaultDetail().getDetailEntries().hasNext()) { SoapFaultDetailElement saajSoapFaultDetailElement = sfce.getSoapFault().getFaultDetail().getDetailEntries().next(); if(saajSoapFaultDetailElement.getName().getNamespaceURI().equals(SPRING_WS_URI) && saajSoapFaultDetailElement.getName().getLocalPart().equals(SPRING_WS_VALIDATION_ERROR)) { if(saajSoapFaultDetailElement.getResult() instanceof DOMResult) { String detailedMessage = ((DOMResult)saajSoapFaultDetailElement.getResult()).getNode().getTextContent(); throw new ClientItcbException(ClientItcbExceptionMappingErrors.COMMON_CLIENT_VALIDATION_ERROR, messageSource.getMessage("common-client.exception.validation_error", new Object[] {detailedMessage}, LocaleContextHolder.getLocale())); } } } } catch(ClientItcbException cie) { throw cie; } } }
transformer.transform(((org.springframework.ws.soap.SoapMessage)webServiceResponse).getSoapBody().getFault().getSource(), faultPayload);
@Override public void match(WebServiceMessage request, WebServiceMessage response) throws IOException, AssertionError { assertTrue("Response is not a SOAP message", response instanceof SoapMessage); SoapMessage soapResponse = (SoapMessage) response; SoapBody responseBody = soapResponse.getSoapBody(); assertTrue("Response has no SOAP Body", responseBody != null); assertTrue("Response has no SOAP Fault", responseBody.hasFault()); SoapFault soapFault = responseBody.getFault(); QName expectedFaultCode = getExpectedFaultCode(soapResponse.getVersion()); assertEquals("Invalid SOAP Fault code", expectedFaultCode, soapFault.getFaultCode()); if (expectedFaultStringOrReason != null) { assertEquals("Invalid SOAP Fault string/reason", expectedFaultStringOrReason, soapFault.getFaultStringOrReason()); } }
/** * Returns the fault string or reason. For SOAP 1.1, this returns the fault string. For SOAP 1.2, this returns the * fault reason for the default locale. * * <p>Note that this message returns the same as {@link #getMessage()}. */ public String getFaultStringOrReason() { return soapFault != null ? soapFault.getFaultStringOrReason() : null; }
SoapFault fault = body.addClientOrSenderFault(getFaultStringOrReason(), getFaultStringOrReasonLocale()); if (getAddValidationErrorDetail()) { SoapFaultDetail detail = fault.addFaultDetail(); for (SAXParseException error : errors) { SoapFaultDetailElement detailElement = detail.addFaultDetailElement(getDetailElementName());
/** Returns the fault code. */ public QName getFaultCode() { return soapFault != null ? soapFault.getFaultCode() : null; }
private void createMustUnderstandFault(SoapMessage soapResponse, List<QName> notUnderstoodHeaderNames, String[] actorsOrRoles) { if (logger.isWarnEnabled()) { logger.warn("Could not handle mustUnderstand headers: " + StringUtils.collectionToCommaDelimitedString(notUnderstoodHeaderNames) + ". Returning fault"); } SoapBody responseBody = soapResponse.getSoapBody(); SoapFault fault = responseBody.addMustUnderstandFault(mustUnderstandFaultString, mustUnderstandFaultStringLocale); if (!ObjectUtils.isEmpty(actorsOrRoles)) { fault.setFaultActorOrRole(actorsOrRoles[0]); } SoapHeader header = soapResponse.getSoapHeader(); if (header instanceof Soap12Header) { Soap12Header soap12Header = (Soap12Header) header; for (QName headerName : notUnderstoodHeaderNames) { soap12Header.addNotUnderstoodHeaderElement(headerName); } } }