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 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; } } }
/** * Extracts fault detail string from soap fault detail instance. Transforms detail source * into string and takes care. * * @param detail * @return */ private static String extractFaultDetail(SoapFaultDetailElement detail) { StringResult detailResult = new StringResult(); try { TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.transform(detail.getSource(), detailResult); } catch (TransformerException e) { throw new CitrusRuntimeException(e); } return detailResult.toString(); }
/** * 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 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; } } }
for (SAXParseException error : errors) { SoapFaultDetailElement detailElement = detail.addFaultDetailElement(getDetailElementName()); detailElement.addText(error.getMessage());
private void makeBusinessItcbException(SoapFaultClientException sfce) { try { while(sfce.getSoapFault().getFaultDetail().getDetailEntries().hasNext()) { SoapFaultDetailElement saajSoapFaultDetailElement = sfce.getSoapFault().getFaultDetail().getDetailEntries().next(); if(saajSoapFaultDetailElement.getName().getLocalPart().equals(BusinessItcbException.EXCEPTION_CLASS.getLocalPart())) { if(saajSoapFaultDetailElement.getResult() instanceof DOMResult) { String exceptionClassName = ((DOMResult)saajSoapFaultDetailElement.getResult()).getNode().getTextContent(); Class<?> exceptionClass = Class.forName(exceptionClassName); Constructor<?>[] constructors= exceptionClass.getConstructors(); for (Constructor<?> constructor : constructors) { if(constructor.getParameterTypes().length == 2) { Class<?> classErrorMapping = constructor.getParameterTypes()[0]; BusinessItcbException bie = (BusinessItcbException)constructor.newInstance( classErrorMapping.getMethod("valueOf", String.class).invoke(classErrorMapping, sfce.getFaultCode().getLocalPart()) , sfce.getLocalizedMessage()); throw bie; } } } } } } catch(BusinessItcbException bie) { throw bie; } // No mapping found catch(Throwable t) { t.printStackTrace(); throw new ClientItcbException(ClientItcbExceptionMappingErrors.COMMON_CLIENT_BUSINESS_TRANSFORMATION_ERROR, messageSource.getMessage("common-client.exception.resolver.transformation_error", new Object[] {t.getMessage()}, LocaleContextHolder.getLocale())); } }
for (SAXParseException error : errors) { SoapFaultDetailElement detailElement = detail.addFaultDetailElement(getDetailElementName()); detailElement.addText(error.getMessage());
while(sfce.getSoapFault().getFaultDetail().getDetailEntries().hasNext()) { SoapFaultDetailElement soapFaultDetailElement = sfce.getSoapFault().getFaultDetail().getDetailEntries().next(); if(soapFaultDetailElement.getName().getLocalPart().equals(BusinessItcbException.EXCEPTION_CLASS.getLocalPart())) { if(soapFaultDetailElement.getResult() instanceof DOMResult) { String exceptionClassName = ((DOMResult)soapFaultDetailElement.getResult()).getNode().getTextContent(); Class<?> exceptionClass = Class.forName(exceptionClassName); Constructor<?>[] constructors= exceptionClass.getConstructors();
for (SAXParseException error : errors) { SoapFaultDetailElement detailElement = detail.addFaultDetailElement(getDetailElementName()); detailElement.addText(error.getMessage());
for (SAXParseException error : errors) { SoapFaultDetailElement detailElement = detail.addFaultDetailElement(getDetailElementName()); detailElement.addText(error.getMessage());
String msg = messageSource.getMessage(objectError, getFaultLocale()); SoapFaultDetailElement detailElement = detail.addFaultDetailElement(getDetailElementName()); detailElement.addText(msg);
String msg = messageSource.getMessage(objectError, getFaultLocale()); SoapFaultDetailElement detailElement = detail.addFaultDetailElement(getDetailElementName()); detailElement.addText(msg);
String msg = messageSource.getMessage(objectError, getFaultLocale()); SoapFaultDetailElement detailElement = detail.addFaultDetailElement(getDetailElementName()); detailElement.addText(msg);
String msg = messageSource.getMessage(objectError, getFaultLocale()); SoapFaultDetailElement detailElement = detail.addFaultDetailElement(getDetailElementName()); detailElement.addText(msg);
/** * Template method that is called when the request SOAP headers contains validation errors. * Default implementation logs all errors, and returns <code>false</code>, i.e. do not process the request. * * @param messageContext the message context * @param errors the validation errors * @return <code>true</code> to continue processing the request, <code>false</code> (the default) otherwise * @throws TransformerException if error occurs during the transformation process */ protected boolean handleHeaderValidationErrors(MessageContext messageContext, ValidationException[] errors) throws TransformerException { for (ValidationException error : errors) { logger.warn("XML validation error on request: " + error.getMessage()); } if (messageContext.getResponse() instanceof SoapMessage) { SoapMessage response = (SoapMessage) messageContext.getResponse(); SoapBody body = response.getSoapBody(); SoapFault fault = body.addClientOrSenderFault(faultHeaderStringOrReason, getFaultStringOrReasonLocale()); if (getAddValidationErrorDetail()) { SoapFaultDetail detail = fault.addFaultDetail(); for (ValidationException error : errors) { SoapFaultDetailElement detailElement = detail.addFaultDetailElement(getDetailElementName()); detailElement.addText(error.getMessage()); } } } return false; }