/** * HAVE message notification handler. * * @param message the message * @ssdd */ @Override public void haveMessageNotificationHandler(Core2CoreMessage message) { log.debug("haveMessageNotificationHandler: received messagefrom " + message.getFromCore()); // =[" + message.getMessage()+ "] XmlObject xmlObj; try { EDXLDistributionDocument edxlDoc = EDXLDistributionDocument.Factory.parse(message.getMessage()); if (edxlDoc.getEDXLDistribution().sizeOfExplicitAddressArray() > 0) { // Find core name for each explicit address. for (ValueSchemeType type : edxlDoc.getEDXLDistribution().getExplicitAddressArray()) { if (type.getExplicitAddressScheme() .equals(CommunicationsService.UICDSExplicitAddressScheme)) { for (String address : type.getExplicitAddressValueArray()) { xmlObj = XmlObject.Factory.parse(edxlDoc.toString()); // log.debug("broadcastMessageNotificationHandler: sending notification [" // + xmlObj.toString() + "] to " + address); sendMessageNotification(xmlObj, address); } } } } } catch (Throwable e) { log.error( "resourceMessageNotificationHandler: Error parsing message - not a valid XML string"); throw new IllegalArgumentException("Message is not a valid XML string"); } }
private ProductPublicationStatus publishWorkProduct( EDXLDistribution edxl, DigestType digest, WorkProductDocument currentWorkProduct) { log.debug("Creating work product for HAVE message"); ValidationUtil.validate(edxl, true); ValidationUtil.validate(digest, true); // Create a work product WorkProduct workProduct = new WorkProduct(); workProduct.setProductType(HAVE_PRODUCT_TYPE); // If updating set the work product identification if (currentWorkProduct != null && currentWorkProduct.getWorkProduct() != null) { IdentificationType id = WorkProductHelper.getIdentificationElement(currentWorkProduct.getWorkProduct()); if (id != null) { try { Integer version = Integer.parseInt(id.getVersion().getStringValue()); workProduct.setProductVersion(version); workProduct.setChecksum(id.getChecksum().getStringValue()); workProduct.setProductID(id.getIdentifier().getStringValue()); workProduct.setProductType(id.getType().getStringValue()); workProduct.setActive(id.getState() == StateType.ACTIVE); } catch (NumberFormatException e) { log.error("Error parsing version number to update HAVE message: " + e.getMessage()); } } else { log.error("Cannot find WorkProductIdentification in matching HAVE message"); } } // workProduct.setProductID(wpIDBuffer.toString()); EDXLDistributionDocument edxlDoc = EDXLDistributionDocument.Factory.newInstance(); edxlDoc.addNewEDXLDistribution().set(edxl); workProduct.setProduct(edxlDoc.xmlText().getBytes()); DigestDocument digestDoc = DigestDocument.Factory.newInstance(); digestDoc.setDigest((DigestType) digest.copy()); workProduct.setDigest(digestDoc); if (edxl.sizeOfContentObjectArray() > 0 && edxl.getContentObjectArray(0).getIncidentID() != null) { workProduct .getAssociatedInterestGroupIDs() .add(edxl.getContentObjectArray(0).getIncidentID()); } // System.out.println(WorkProductHelper.toWorkProductXmlDocument(workProduct)); // publish the work product ProductPublicationStatus status = workProductService.publishProduct(workProduct); return status; }
private void sendEdxlDeMessage(EDXLDistribution edxl) throws IllegalArgumentException, EmptyCoreNameListException, SendMessageErrorException, LocalCoreNotOnlineException { HashSet<String> cores = BroadcastUtil.getCoreList(edxl); // Send the message to each core that has a user in an explictAddress // element if (cores.size() == 0) { return; } else { SendMessageErrorException errorException = new SendMessageErrorException(); for (String core : cores) { try { log.info("sendMessage to: " + core); EDXLDistributionDocument doc = EDXLDistributionDocument.Factory.newInstance(); doc.setEDXLDistribution(edxl); communicationsService.sendMessage( doc.xmlText(), CommunicationsService.CORE2CORE_MESSAGE_TYPE.RESOURCE_MESSAGE, core); log.debug("called communicationsService.sendMessage"); } catch (RemoteCoreUnknownException e1) { errorException .getErrors() .put(core, SendMessageErrorException.SEND_MESSAGE_ERROR_TYPE.CORE_UNKNOWN); } catch (RemoteCoreUnavailableException e2) { errorException .getErrors() .put(core, SendMessageErrorException.SEND_MESSAGE_ERROR_TYPE.CORE_UNAVAILABLE); } catch (LocalCoreNotOnlineException e) { // TODO: this short circuit for the local core should be in the // CommunicationService log.info("Sending to local core"); Core2CoreMessage message = new Core2CoreMessage(); message.setFromCore(core); message.setToCore(core); message.setMessageType( CommunicationsService.CORE2CORE_MESSAGE_TYPE.RESOURCE_MESSAGE.toString()); // Core2CoreMessageDocument doc = // Core2CoreMessageDocument.Factory.newInstance(); // doc.addNewCore2CoreMessage().set(edxl); // message.setMessage(doc.toString()); EDXLDistributionDocument doc = EDXLDistributionDocument.Factory.newInstance(); doc.setEDXLDistribution(edxl); message.setMessage(doc.toString()); haveMessageNotificationHandler(message); // communicationsService.core2CoreMessageNotificationHandler(message); } catch (NoShareAgreementException e) { errorException .getErrors() .put(core, SendMessageErrorException.SEND_MESSAGE_ERROR_TYPE.NO_SHARE_AGREEMENT); } catch (NoShareRuleInAgreementException e) { errorException .getErrors() .put( core, SendMessageErrorException.SEND_MESSAGE_ERROR_TYPE.NO_SHARE_RULE_IN_AGREEMENT); } } if (errorException.getErrors().size() > 0) { throw errorException; } } }