ErrorSignalElement { protected static OMElement createErrorElement(final OMElement signalmessage, final IEbmsError error) { final OMFactory f = signalmessage.getOMFactory(); final OMElement errorElement = f.createOMElement(Q_ELEMENT_NAME, signalmessage); errorElement.addAttribute(ERROR_CODE_ATTR, error.getErrorCode(), null); errorElement.addAttribute(SEVERITY_ATTR, error.getSeverity().toString(), null); final String origin = error.getOrigin(); if (!Utils.isNullOrEmpty(origin)) errorElement.addAttribute(ORIGIN_ATTR, origin, null); final String category = error.getCategory(); if (!Utils.isNullOrEmpty(category)) errorElement.addAttribute(CATEGORY_ATTR, category, null); final String refToMsg = error.getRefToMessageInError(); if (!Utils.isNullOrEmpty(refToMsg)) errorElement.addAttribute(REF_TO_ATTR, refToMsg, null); final String errMsg = error.getMessage(); if (!Utils.isNullOrEmpty(errMsg)) errorElement.addAttribute(SHORT_DESCR_ATTR, errMsg, null); final String errDetailText = error.getErrorDetail(); if (!Utils.isNullOrEmpty(errDetailText)) { final OMElement errorDetail = f.createOMElement(Q_ERROR_DETAIL, errorElement); errorDetail.setText(errDetailText); } final IDescription errDescription = error.getDescription(); if (errDescription != null && errDescription.getText() != null) DescriptionElement.createElement(errorElement, errDescription); return errorElement; }  static OMElement createElement(final OMElement messaging, final IErrorMessage errorMU); static ErrorMessage readElement(final OMElement sigElement); static Iterator<OMElement> getElements(final SOAPHeaderBlock messaging); static final QName Q_ELEMENT_NAME; }
@Test public void testCreateErrorElement() throws Exception { ErrorMessage errorMessage = new ErrorMessage(); ArrayList<IEbmsError> errors = new ArrayList<>(); EbmsError ebmsError = new EbmsError(); ebmsError.setSeverity(IEbmsError.Severity.failure); ebmsError.setErrorCode("some_error_code"); errors.add(ebmsError); errorMessage.setErrors(errors); OMElement esElement = ErrorSignalElement.createElement(headerBlock, errorMessage); EbmsError newEbmsError = new EbmsError(); newEbmsError.setSeverity(IEbmsError.Severity.failure); newEbmsError.setErrorCode("some_new_error_code"); newEbmsError.setCategory("some_category"); newEbmsError.setOrigin("some_error_origin"); newEbmsError.setMessage("some_message"); newEbmsError.setRefToMessageInError("ref_to_some_message"); newEbmsError.setErrorDetail("some_error_detail"); Description description = new Description("some_text", "en-CA"); newEbmsError.setDescription(description); OMElement eElement = ErrorSignalElement.createErrorElement(esElement, newEbmsError); System.out.println("eElement: " + eElement); assertEquals(ERROR_ELEMENT_NAME, eElement.getQName()); assertEquals(IEbmsError.Severity.failure.toString(), eElement.getAttributeValue(SEVERITY_ATTR_NAME)); assertEquals("some_new_error_code", eElement.getAttributeValue(ERROR_CODE_ATTR_NAME)); assertEquals("some_category", eElement.getAttributeValue(CATEGORY_ATTR_NAME)); assertEquals("some_error_origin", eElement.getAttributeValue(ORIGIN_ATTR_NAME)); assertEquals("some_message", eElement.getAttributeValue(SHORT_DESCR_ATTR_NAME)); assertEquals("ref_to_some_message", eElement.getAttributeValue(REF_TO_ATTR_NAME)); OMElement errDetailElement = eElement.getFirstElement(); assertEquals(Q_ERROR_DETAIL, errDetailElement.getQName()); assertEquals("some_error_detail", errDetailElement.getText()); OMElement dElement = DescriptionElement.getElement(eElement); assertEquals(DESCRIPTION_ELEMENT_NAME, dElement.getQName()); assertEquals("some_text", dElement.getText()); assertEquals("en-CA", dElement.getAttributeValue(LANG_ATTR_NAME)); }