AddPayloads extends AbstractUserMessageHandler { @Override protected InvocationResponse doProcessing(final IUserMessageEntity um, final IMessageProcessingContext procCtx, final Logger log) throws PersistenceException { log.trace("Check that all meta-data of the User Message is available for processing"); if (!um.isLoadedCompletely()) { log.trace("Not all info loaded, load now"); HolodeckB2BCore.getQueryManager().ensureCompletelyLoaded(um); } log.trace("All meta-data of User Message available, check for payloads to include"); final Collection<IPayload> payloads = um.getPayloads(); if (Utils.isNullOrEmpty(payloads)) { log.debug("User message has no payloads"); } else { log.trace("User message contains " + payloads.size() + " payload(s)"); ArrayList<IPayload> newPayloadInfo = new ArrayList<>(payloads.size()); boolean cidGenerated = false; for (final IPayload pl : payloads) { Payload p = new Payload(pl); if (pl.getContainment() == ATTACHMENT && Utils.isNullOrEmpty(pl.getPayloadURI())) { final String cid = MessageIdUtils.createContentId(um.getMessageId()); log.trace("Generated a new Content-id [" + cid + "] for payload [" + pl.getContentLocation() + "]"); p.setPayloadURI(cid); cidGenerated = true; } newPayloadInfo.add(p); try { addContent(p, procCtx.getParentContext(), log); } catch (final Exception e) { log.error("Adding the payload content to message failed. Error details: " + e.getMessage()); return InvocationResponse.ABORT; } } if (cidGenerated) { HolodeckB2BCore.getStorageManager().setPayloadInformation(um, newPayloadInfo); log.debug("Generated MIME Content-Id(s) saved to database"); } log.debug("Payloads successfully added to User Message [msgId=" + um.getMessageId() + "]"); } return InvocationResponse.CONTINUE; }    }
@Test public void testDoProcessing() throws Exception { MessageContext mc = new MessageContext(); mc.setFLOW(MessageContext.OUT_FLOW); try { mc.setEnvelope(SOAPEnv.createEnvelope(SOAPEnv.SOAPVersion.SOAP_12)); } catch (AxisFault axisFault) { fail(axisFault.getMessage()); } UserMessage userMessage = new UserMessage(); userMessage.setMessageId("payload-adder-01"); Payload payload = new Payload(); payload.setContainment(IPayload.Containment.ATTACHMENT); String payloadURI = "some_URI_01"; payload.setPayloadURI(payloadURI); payload.setContentLocation(baseDir + "/flower.jpg"); userMessage.addPayload(payload); payload = new Payload(); payload.setContainment(IPayload.Containment.BODY); payload.setPayloadURI("some_URI_03"); payload.setContentLocation(baseDir + "/document.xml"); userMessage.addPayload(payload); IUserMessageEntity userMessageEntity = HolodeckB2BCore.getStorageManager() .storeIncomingMessageUnit(userMessage); IMessageProcessingContext procCtx = MessageProcessingContext.getFromMessageContext(mc); procCtx.setUserMessage(userMessageEntity); try { new AddPayloads().invoke(mc); } catch (Exception e) { fail(e.getMessage()); } assertNotNull(mc.getAttachmentMap()); assertEquals(1, mc.getAttachmentMap().getAllContentIDs().length); assertNotNull(mc.getEnvelope().getBody().getFirstElement()); assertEquals("document", mc.getEnvelope().getBody().getFirstElement().getLocalName()); }