ClientInInterceptor extends AbstractPhaseInterceptor<Message> { @Override public void handleMessage( final Message message ) { try { if ( InterceptorState.CLIENT_IN.isActive( message ) ) { URL url = new URL( ( String ) message.getExchange().getOutMessage().get( Message.ENDPOINT_ADDRESS ) ); String ip = url.getHost(); String targetId = getPeerIdByIp( ip ); if ( targetId != null && url.getPort() == peerManager.getPeer( targetId ).getPeerInfo() .getPublicSecurePort() ) { String path = url.getPath(); if ( path.startsWith( "/rest/v1/peer" ) ) { handlePeerMessage( targetId, message ); } else { final String prefix = "/rest/v1/env"; if ( path.startsWith( prefix ) ) { String s = path.substring( prefix.length() + 1 ); String environmentId = s.substring( 0, s.indexOf( "/" ) ); handleEnvironmentMessage( targetId, environmentId, message ); } } } } } catch ( Exception ex ) { throw new Fault( ex ); } } ClientInInterceptor( SecurityManager securityManager, PeerManager peerManager ); @Override void handleMessage( final Message message );  }
@Test public void testHandleMessage() throws Exception { Message message = InterceptorStateHelper.getMessage( InterceptorState.CLIENT_IN ); Message outMessage = message.getExchange().getOutMessage(); doReturn( String.format( "http: .get( Message .ENDPOINT_ADDRESS ); doReturn( PEER_ID ).when( interceptor ).getPeerIdByIp( Common.LOCAL_HOST_IP ); doReturn( peer ).when( peerManager ).getPeer( PEER_ID ); doReturn( peerInfo ).when( peer ).getPeerInfo(); doReturn( PORT ).when( peerInfo ).getPublicSecurePort(); doReturn( localPeer ).when( peerManager ).getLocalPeer(); interceptor.handleMessage( message ); verify( interceptor ).getPeerIdByIp( Common.LOCAL_HOST_IP ); verify( interceptor ).handlePeerMessage( PEER_ID, message ); doReturn( String.format( "http: .get( Message .ENDPOINT_ADDRESS ); interceptor.handleMessage( message ); verify( interceptor ).handleEnvironmentMessage( PEER_ID,ENV_ID, message ); }