CompressionHandler extends AbstractUserMessageHandler { @Override protected InvocationResponse doProcessing(final IUserMessageEntity um, final IMessageProcessingContext procCtx, final Logger log) throws AxisFault { if (Utils.isNullOrEmpty(um.getPayloads())) return InvocationResponse.CONTINUE; log.trace("Check P-Mode configuration if AS4 compression must be used"); final IUserMessageFlow flow = PModeUtils.getLeg(um).getUserMessageFlow(); final IPayloadProfile plProfile = (flow != null ? flow.getPayloadProfile() : null); if ((plProfile instanceof IAS4PayloadProfile) && CompressionFeature.COMPRESSED_CONTENT_TYPE.equalsIgnoreCase( ((IAS4PayloadProfile) plProfile).getCompressionType())) { log.debug("AS4 Compression feature is used"); for (final IPayload p : um.getPayloads()) if (p.getContainment() == IPayload.Containment.ATTACHMENT) enableCompression(p, procCtx.getParentContext()); log.trace("Enabled compression for all attached payloads"); } else log.debug("AS4 Compression feature is not used"); return InvocationResponse.CONTINUE; }    }
@Test public void testDoProcessing() throws Exception { PMode pmode = TestUtils.create1WaySendPushPMode(); Leg leg = pmode.getLeg(Label.REQUEST); UserMessageFlow umFlow = new UserMessageFlow(); PayloadProfile plProfile = new PayloadProfile(); plProfile.setCompressionType(CompressionFeature.COMPRESSED_CONTENT_TYPE); umFlow.setPayloadProfile(plProfile); leg.setUserMessageFlow(umFlow); HolodeckB2BCoreInterface.getPModeSet().add(pmode); UserMessage userMessage = new UserMessage(); userMessage.setPModeId(pmode.getId()); Payload payload = new Payload(); payload.setContainment(IPayload.Containment.ATTACHMENT); String payloadPath = "file: payload.setPayloadURI(payloadPath); userMessage.addPayload(payload); MessageContext mc = new MessageContext(); mc.setFLOW(MessageContext.OUT_FLOW); Attachments attachments = new Attachments(); DataHandler attDataHandler = new DataHandler(new URL(payload.getPayloadURI())); attachments.addDataHandler(payloadPath, attDataHandler); mc.setAttachmentMap(attachments); IUserMessageEntity userMessageEntity = HolodeckB2BCore.getStorageManager().storeOutGoingMessageUnit(userMessage); IMessageProcessingContext procCtx = MessageProcessingContext.getFromMessageContext(mc); procCtx.setUserMessage(userMessageEntity); try { Handler.InvocationResponse invokeResp = new CompressionHandler().invoke(mc); assertEquals(Handler.InvocationResponse.CONTINUE, invokeResp); } catch (Exception e) { fail(e.getMessage()); } for (final IPayload p : userMessageEntity.getPayloads()) { if (p.getContainment() == IPayload.Containment.ATTACHMENT) { Collection<IProperty> properties = p.getProperties(); assertNotNull(properties); Iterator<IProperty> it = properties.iterator(); IProperty property = it.next(); assertEquals(CompressionFeature.FEATURE_PROPERTY_NAME, property.getName()); assertEquals(CompressionFeature.COMPRESSED_CONTENT_TYPE, property.getValue()); property = it.next(); assertEquals(CompressionFeature.MIME_TYPE_PROPERTY_NAME, property.getName()); assertEquals(attDataHandler.getContentType(), property.getValue()); assertTrue(mc.getAttachment(p.getPayloadURI()) instanceof CompressionDataHandler); assertEquals(CompressionFeature.COMPRESSED_CONTENT_TYPE, mc.getAttachment(p.getPayloadURI()).getContentType()); } } }