### Question:
DeliveryAgent { public void submit(MessageContext msgContext, EndpointReference epr) throws AxisFault { try { if (log.isDebugEnabled()) { log.debug("Submitting request for MessageID: " + msgContext.getMessageID()); } URL url = new URL(epr.getAddress()); String scheme = url.getProtocol() != null ? url.getProtocol() : "http"; String hostname = url.getHost(); int port = url.getPort(); if (port == -1) { if ("http".equals(scheme)) { port = 80; } else if ("https".equals(scheme)) { port = 443; } } HttpHost target = new HttpHost(hostname, port, scheme); boolean secure = "https".equalsIgnoreCase(target.getSchemeName()); HttpHost proxy = proxyConfig.selectProxy(target); msgContext.setProperty(PassThroughConstants.PROXY_PROFILE_TARGET_HOST, target.getHostName()); HttpRoute route; if (proxy != null) { route = new HttpRoute(target, null, proxy, secure); } else { route = new HttpRoute(target, null, secure); } Queue<MessageContext> queue = null; lock.lock(); try { queue = waitingMessages.get(route); if (queue == null) { queue = new ConcurrentLinkedQueue<MessageContext>(); waitingMessages.put(route, queue); } if (queue.size() == maxWaitingMessages) { MessageContext msgCtx = queue.poll(); msgCtx.setProperty(PassThroughConstants.INTERNAL_EXCEPTION_ORIGIN, PassThroughConstants.INTERNAL_ORIGIN_ERROR_HANDLER); targetErrorHandler.handleError(msgCtx, ErrorCodes.CONNECTION_TIMEOUT, "Error connecting to the back end", null, ProtocolState.REQUEST_READY); } queue.add(msgContext); } finally { lock.unlock(); } NHttpClientConnection conn = targetConnections.getConnection(route); if (conn != null) { if (log.isDebugEnabled()) { log.debug("Connection found from pool for MessageID: " + msgContext.getMessageID() + ", conn: " + conn.toString()); } conn.resetInput(); conn.resetOutput(); MessageContext messageContext = queue.poll(); if (messageContext != null) { tryNextMessage(messageContext, route, conn); } } } catch (MalformedURLException e) { handleException("Malformed URL in the target EPR", e); } } DeliveryAgent(TargetConfiguration targetConfiguration,
                         TargetConnections targetConnections,
                         ProxyConfig proxyConfig); void submit(MessageContext msgContext, EndpointReference epr); void errorConnecting(HttpRoute route, int errorCode, String message, Exception exceptionToRaise); void errorConnecting(HttpRoute route, int errorCode, String message); void connected(HttpRoute route, NHttpClientConnection conn);  }### Answer:
@Test public void test() throws Exception { MessageContext messageContext = new MessageContext(); ServiceContext svcCtx = new ServiceContext(); OperationContext opCtx = new OperationContext(new InOutAxisOperation(), svcCtx); messageContext.setServiceContext(svcCtx); messageContext.setOperationContext(opCtx); TargetConfiguration targetConfiguration = PowerMockito.mock(TargetConfiguration.class); TargetConnections conns = PowerMockito.mock(TargetConnections.class); ProxyConfig config = PowerMockito.mock(ProxyConfig.class); EndpointReference epr = new EndpointReference("http: DeliveryAgent agent = new DeliveryAgent(targetConfiguration, conns, config); agent.submit(messageContext, epr); Assert.assertEquals("127.0.0.1", messageContext.getProperty("PROXY_PROFILE_TARGET_HOST")); }