ConfigureHTTPTransportHandler extends AbstractBaseHandler { @Override protected InvocationResponse doProcessing(final IMessageProcessingContext procCtx, final Logger log) throws PersistenceException { final IMessageUnitEntity primaryMU = procCtx.getPrimaryMessageUnit(); if (primaryMU == null) return InvocationResponse.CONTINUE; final MessageContext axisMsgCtx = procCtx.getParentContext(); axisMsgCtx.getOptions().setProperty(Constants.Configuration.DISABLE_SOAP_ACTION, "true"); log.trace("Get P-Mode configuration for primary MU"); ILeg leg; try { leg = PModeUtils.getLeg(primaryMU); } catch (IllegalStateException pmodeNotAvailable) { log.error("P-Mode set for primary message unit [" + primaryMU.getMessageId() + "] is not available"); leg = null; } if (leg == null) if (axisMsgCtx.isServerSide()) { log.debug("No P-Mode given for primary message unit, using default HTTP configuration"); return InvocationResponse.CONTINUE; } else { log.error("No P-Mode available for primary message unit [msgId=" + primaryMU.getMessageId() + "] to get the destination!"); setMessagesToFailed(procCtx, log); return InvocationResponse.ABORT; } final Options options = axisMsgCtx.getOptions(); final IProtocol protocolCfg = leg.getProtocol(); if (!axisMsgCtx.isServerSide()) { String destURL = null; try { try { if (primaryMU instanceof IReceipt) destURL = leg.getReceiptConfiguration().getTo(); else if (primaryMU instanceof IErrorMessage) destURL = leg.getUserMessageFlow().getErrorHandlingConfiguration().getReceiverErrorsTo(); } catch (NullPointerException npe) {} if (destURL == null) destURL = leg.getProtocol().getAddress(); } catch (final NullPointerException npe) { log.error("P-Mode does not contain destination URL for " + MessageUnitUtils.getMessageUnitName(primaryMU)); setMessagesToFailed(procCtx, log); } log.debug("Destination URL=" + destURL); axisMsgCtx.setProperty(Constants.Configuration.TRANSPORT_URL, destURL); } final boolean compress = (protocolCfg != null ? protocolCfg.useHTTPCompression() : false); if (compress) log.debug("Enable HTTP compression using gzip Content-Encoding"); if (!axisMsgCtx.isServerSide()) options.setProperty(HTTPConstants.MC_GZIP_REQUEST, Boolean.valueOf(compress)); else options.setProperty(HTTPConstants.MC_GZIP_RESPONSE, Boolean.valueOf(compress)); if (compress || (protocolCfg != null ? protocolCfg.useChunking() : false)) { log.debug("Enable chunked transfer-encoding"); options.setProperty(HTTPConstants.CHUNKED, Boolean.TRUE); } else { log.debug("Disable chunked transfer-encoding"); options.setProperty(HTTPConstants.CHUNKED, Boolean.FALSE); } if (axisMsgCtx.getAttachmentMap().getContentIDSet().isEmpty()) { log.trace("Disable SwA as message does not contain attachments"); options.setProperty(Constants.Configuration.ENABLE_SWA, Boolean.FALSE); } else options.setProperty(Constants.Configuration.ENABLE_SWA, Boolean.TRUE); log.trace("HTTP configuration done"); return InvocationResponse.CONTINUE; }    }
@Test public void testDoProcessing() throws Exception { MessageContext mc = new MessageContext(); mc.setFLOW(MessageContext.OUT_FLOW); mc.setServerSide(false); PMode pmode = TestUtils.create1WaySendPushPMode(); Leg leg = pmode.getLeg(Label.REQUEST); Protocol protocolConfig = leg.getProtocol(); protocolConfig.setHTTPCompression(true); protocolConfig.setChunking(true); leg.setProtocol(protocolConfig); HolodeckB2BCore.getPModeSet().add(pmode); UserMessage userMessage = new UserMessage(); userMessage.setPModeId(pmode.getId()); IMessageProcessingContext procCtx = MessageProcessingContext.getFromMessageContext(mc); procCtx.setUserMessage(HolodeckB2BCore.getStorageManager().storeOutGoingMessageUnit(userMessage)); try { assertEquals(Handler.InvocationResponse.CONTINUE, new ConfigureHTTPTransportHandler().invoke(mc)); } catch (Exception e) { fail(e.getMessage()); } assertEquals(protocolConfig.getAddress(), mc.getProperty(Constants.Configuration.TRANSPORT_URL)); Options options = mc.getOptions(); assertNotNull(options); assertTrue((Boolean) options.getProperty(HTTPConstants.MC_GZIP_REQUEST)); assertTrue((Boolean) options.getProperty(HTTPConstants.CHUNKED)); assertFalse((Boolean) options.getProperty(Constants.Configuration.ENABLE_SWA)); }