UdpEndpointContextMatcher extends KeySetEndpointContextMatcher { @Override public boolean isResponseRelatedToRequest(EndpointContext requestContext, EndpointContext responseContext) { if (checkAddress) { InetSocketAddress peerAddress1 = requestContext.getPeerAddress(); InetSocketAddress peerAddress2 = responseContext.getPeerAddress(); if (!peerAddress1.equals(peerAddress2) && !NetworkInterfacesUtil.isMultiAddress(peerAddress1.getAddress())) { LOGGER.info("request {}:{} doesn't match {}:{}!", peerAddress1.getAddress().getHostAddress(), peerAddress1.getPort(), peerAddress2.getAddress().getHostAddress(), peerAddress2.getPort()); return false; } } return super.isResponseRelatedToRequest(requestContext, responseContext); } UdpEndpointContextMatcher();  UdpEndpointContextMatcher(boolean checkAddress); @Override boolean isResponseRelatedToRequest(EndpointContext requestContext, EndpointContext responseContext);  }
@Test public void testResponse() { assertThat(matcher.isResponseRelatedToRequest(messageContext, messageContext), is(true)); assertThat(matcher.isResponseRelatedToRequest(messageContext, secureMessageContext), is(false)); assertThat(matcher.isResponseRelatedToRequest(secureMessageContext, messageContext), is(false)); assertThat(matcher.isResponseRelatedToRequest(addressContext, messageContext), is(true)); assertThat(matcher.isResponseRelatedToRequest(messageContext, addressContext), is(false)); assertThat(matcher.isResponseRelatedToRequest(messageContext, changedAddressContext), is(false)); assertThat(matcher.isResponseRelatedToRequest(changedAddressContext, messageContext), is(false)); assertThat(matcher.isResponseRelatedToRequest(multicastContext, messageContext), is(true)); assertThat(matcher.isResponseRelatedToRequest(multicastContext, changedAddressContext), is(true)); }