HttpHeaderRequestOutInterceptor extends AbstractPhaseInterceptor<Message> { @Override public void handleMessage(Message message) { LOG.trace("Begin HttpHeaderRequestOutInterceptor"); Map<String, List> headers = (Map<String, List>) message.get(Message.PROTOCOL_HEADERS); if(headers == null) { headers = new HashMap<>(); } final Map<String, String> customHttpHeaders = getCustomHttpHeaders(message); if(MapUtils.isNotEmpty(customHttpHeaders)) { for(Entry<String,String> entry : customHttpHeaders.entrySet()) { headers.put(entry.getKey(), Collections.singletonList(entry.getValue())); LOG.debug("Adding custom CONNECT HTTP header: {}, {}" , entry.getKey(), entry.getValue()); } } message.put(Message.PROTOCOL_HEADERS, headers); } HttpHeaderRequestOutInterceptor(); @Override void handleMessage(Message message);  }
@Test public void testHandleMessage() { Message message = new MessageImpl(); final HashMap<String, String> customHttpHeaders = new HashMap<>(); String headerName = "headerName"; String headerValue = "headerValue"; customHttpHeaders.put(headerName, headerValue); Map<String, List> protocolHeaders = new HashMap<>(); List<String> connectionList = new ArrayList<>(); String connectionHeader = "connection"; String keepAliveValue = "keep-alive"; connectionList.add(keepAliveValue); protocolHeaders.put(connectionHeader, connectionList); message.put(Message.PROTOCOL_HEADERS, protocolHeaders); HttpHeaderRequestOutInterceptor httpInterceptor = new HttpHeaderRequestOutInterceptor() { @Override protected Map<String,String> getCustomHttpHeaders(Message message) { return customHttpHeaders; } }; httpInterceptor.handleMessage(message); Map<String, List> protocolHeadersResult = (Map<String, List>) message.get(Message.PROTOCOL_HEADERS); assertEquals(protocolHeadersResult.size(), 2); assert(protocolHeadersResult.containsKey(headerName)); assertEquals(protocolHeadersResult.get(headerName).get(0), headerValue); }